Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1924 from heidiberry/main
Browse files Browse the repository at this point in the history
Add SAML group link support for custom roles
  • Loading branch information
svanharmelen authored May 2, 2024
2 parents 40591c1 + a53d348 commit 2c4b565
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 2 deletions.
5 changes: 3 additions & 2 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ type LDAPGroupLink struct {
//
// GitLab API docs: https://docs.gitlab.com/ee/api/groups.html#saml-group-links
type SAMLGroupLink struct {
Name string `json:"name"`
AccessLevel AccessLevelValue `json:"access_level"`
Name string `json:"name"`
AccessLevel AccessLevelValue `json:"access_level"`
MemberRoleID int `json:"member_role_id,omitempty"`
}

// ListGroupsOptions represents the available ListGroups() options.
Expand Down
95 changes: 95 additions & 0 deletions groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,38 @@ func TestListGroupSAMLLinks(t *testing.T) {
}
}

func TestListGroupSAMLLinksCustomRole(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/saml_group_links",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `[
{
"access_level":30,
"name":"gitlab_group_example_developer",
"member_role_id":123
}
]`)
})

links, _, err := client.Groups.ListGroupSAMLLinks(1)
if err != nil {
t.Errorf("Groups.ListGroupSAMLLinks returned error: %v", err)
}

want := []*SAMLGroupLink{
{
AccessLevel: DeveloperPermissions,
Name: "gitlab_group_example_developer",
MemberRoleID: 123,
},
}
if !reflect.DeepEqual(want, links) {
t.Errorf("Groups.ListGroupSAMLLinks returned %+v, want %+v", links, want)
}
}

func TestGetGroupSAMLLink(t *testing.T) {
mux, client := setup(t)

Expand Down Expand Up @@ -459,6 +491,35 @@ func TestGetGroupSAMLLink(t *testing.T) {
}
}

func TestGetGroupSAMLLinkCustomRole(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/saml_group_links/gitlab_group_example_developer",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `
{
"access_level":30,
"name":"gitlab_group_example_developer",
"member_role_id":123
}`)
})

links, _, err := client.Groups.GetGroupSAMLLink(1, "gitlab_group_example_developer")
if err != nil {
t.Errorf("Groups.GetGroupSAMLLinks returned error: %v", err)
}

want := &SAMLGroupLink{
AccessLevel: DeveloperPermissions,
Name: "gitlab_group_example_developer",
MemberRoleID: 123,
}
if !reflect.DeepEqual(want, links) {
t.Errorf("Groups.GetGroupSAMLLink returned %+v, want %+v", links, want)
}
}

func TestAddGroupSAMLLink(t *testing.T) {
mux, client := setup(t)

Expand Down Expand Up @@ -491,6 +552,40 @@ func TestAddGroupSAMLLink(t *testing.T) {
}
}

func TestAddGroupSAMLLinkCustomRole(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/saml_group_links",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `
{
"access_level":30,
"name":"gitlab_group_example_developer",
"member_role_id":123
}`)
})

opt := &AddGroupSAMLLinkOptions{
SAMLGroupName: Ptr("gitlab_group_example_developer"),
AccessLevel: Ptr(DeveloperPermissions),
}

link, _, err := client.Groups.AddGroupSAMLLink(1, opt)
if err != nil {
t.Errorf("Groups.AddGroupSAMLLink returned error: %v", err)
}

want := &SAMLGroupLink{
AccessLevel: DeveloperPermissions,
Name: "gitlab_group_example_developer",
MemberRoleID: 123,
}
if !reflect.DeepEqual(want, link) {
t.Errorf("Groups.AddGroupSAMLLink returned %+v, want %+v", link, want)
}
}

func TestRestoreGroup(t *testing.T) {
mux, client := setup(t)
mux.HandleFunc("/api/v4/groups/1/restore",
Expand Down

0 comments on commit 2c4b565

Please sign in to comment.