Skip to content

Commit

Permalink
fix: correct SAMLGroupLink MemberID mapping (#170)
Browse files Browse the repository at this point in the history
Signed-off-by: Cyrill Näf <[email protected]>
  • Loading branch information
BigGold1310 authored Feb 10, 2025
1 parent c237415 commit 796bc29
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/clients/groups/samlgrouplink.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ func NewSamlGroupLinkClient(cfg clients.Config) SamlGroupLinkClient {
return git.Groups
}

// GenerateAddSamlGroupLinkOptions is used to produce Options for SamlGroupSync creation
// GenerateAddSamlGroupLinkOptions is used to produce Options for SamlGroupLink creation
func GenerateAddSamlGroupLinkOptions(p *v1alpha1.SamlGroupLinkParameters) *gitlab.AddGroupSAMLLinkOptions {
samlGroupName := &gitlab.AddGroupSAMLLinkOptions{
SAMLGroupName: p.Name,
AccessLevel: (*gitlab.AccessLevelValue)(&p.AccessLevel),
MemberRoleID: p.MemberRoleID,
}

return samlGroupName
Expand Down
33 changes: 32 additions & 1 deletion pkg/controller/groups/samlgrouplinks/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
"github.com/xanzy/go-gitlab"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/crossplane-contrib/provider-gitlab/apis/groups/v1alpha1"
Expand All @@ -50,6 +51,7 @@ type SamlGroupLinkModifier func(*v1alpha1.SamlGroupLink)
func withConditions(c ...xpv1.Condition) SamlGroupLinkModifier {
return func(cr *v1alpha1.SamlGroupLink) { cr.Status.ConditionedStatus.Conditions = c }
}

func withGroupID() SamlGroupLinkModifier {
return func(r *v1alpha1.SamlGroupLink) { r.Spec.ForProvider.GroupID = &groupID }
}
Expand All @@ -70,6 +72,10 @@ func withExternalName(n string) SamlGroupLinkModifier {
return func(r *v1alpha1.SamlGroupLink) { meta.SetExternalName(r, n) }
}

func withMemberRoleID(i int) SamlGroupLinkModifier {
return func(r *v1alpha1.SamlGroupLink) { r.Spec.ForProvider.MemberRoleID = ptr.To(i) }
}

func samlGroupLink(m ...SamlGroupLinkModifier) *v1alpha1.SamlGroupLink {
cr := &v1alpha1.SamlGroupLink{}
for _, f := range m {
Expand Down Expand Up @@ -274,7 +280,6 @@ func TestObserve(t *testing.T) {
}
})
}

}

func TestDelete(t *testing.T) {
Expand Down Expand Up @@ -466,6 +471,32 @@ func TestCreate(t *testing.T) {
result: managed.ExternalCreation{},
},
},
"SuccessfulCreationWithMemberRoleID": {
args: args{
samlGroupLink: &fake.MockClient{
MockAddGroupSAMLLink: func(pid interface{}, opt *gitlab.AddGroupSAMLLinkOptions, options ...gitlab.RequestOptionFunc) (*gitlab.SAMLGroupLink, *gitlab.Response, error) {
return &gitlab.SAMLGroupLink{Name: name}, &gitlab.Response{}, nil
},
},
cr: samlGroupLink(
withGroupID(),
withSpec(v1alpha1.SamlGroupLinkParameters{GroupID: &groupID, Name: &name}),
withAccessLevel(10),
withMemberRoleID(10),
),
},
want: want{
cr: samlGroupLink(
withGroupID(),
withExternalName(name),
withSpec(v1alpha1.SamlGroupLinkParameters{GroupID: &groupID, Name: &name}),
withAccessLevel(10),
withMemberRoleID(10),
),
err: nil,
result: managed.ExternalCreation{},
},
},
}

for name, tc := range cases {
Expand Down

0 comments on commit 796bc29

Please sign in to comment.