-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regex group filter for gitlab conector
- Loading branch information
1 parent
113751e
commit 0550519
Showing
2 changed files
with
86 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,12 +276,6 @@ func TestGroupsWithPermission(t *testing.T) { | |
expectNil(t, err) | ||
|
||
expectEquals(t, identity.Groups, []string{ | ||
"ops", | ||
"dev", | ||
"ops-test", | ||
"ops/project", | ||
"dev/project1", | ||
"dev/project2", | ||
"ops:owner", | ||
"dev:developer", | ||
"ops/project:owner", | ||
|
@@ -290,6 +284,56 @@ func TestGroupsWithPermission(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestGroupsWithGroupFilter(t *testing.T) { | ||
s := newTestServer(map[string]interface{}{ | ||
"/oauth/userinfo": userInfo{ | ||
Groups: []string{"team-1", "team-2", "project-1", "project-2"}, | ||
}, | ||
}) | ||
defer s.Close() | ||
|
||
c := gitlabConnector{baseURL: s.URL, groups: []string{"team-1", "project-1"}, groupsFilter: "^project.+$"} | ||
groups, err := c.getGroups(context.Background(), newClient(), true, "joebloggs") | ||
|
||
expectNil(t, err) | ||
expectEquals(t, groups, []string{ | ||
"project-1", | ||
}) | ||
} | ||
|
||
func TestGroupsWithGroupFilterWithPermission(t *testing.T) { | ||
s := newTestServer(map[string]interface{}{ | ||
"/api/v4/user": gitlabUser{Email: "[email protected]", ID: 12345678, Name: "Joe Bloggs", Username: "joebloggs"}, | ||
"/oauth/token": map[string]interface{}{ | ||
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9", | ||
"expires_in": "30", | ||
}, | ||
"/oauth/userinfo": userInfo{ | ||
Groups: []string{"ops", "dev", "ops-test", "ops/project", "dev/project1", "dev/project2"}, | ||
OwnerPermission: []string{"ops"}, | ||
DeveloperPermission: []string{"dev"}, | ||
MaintainerPermission: []string{"dev/project1"}, | ||
}, | ||
}) | ||
defer s.Close() | ||
|
||
hostURL, err := url.Parse(s.URL) | ||
expectNil(t, err) | ||
|
||
req, err := http.NewRequest("GET", hostURL.String(), nil) | ||
expectNil(t, err) | ||
|
||
c := gitlabConnector{baseURL: s.URL, httpClient: newClient(), getGroupsPermission: true, groupsFilter: ".+project.+"} | ||
identity, err := c.HandleCallback(connector.Scopes{Groups: true}, req) | ||
expectNil(t, err) | ||
|
||
expectEquals(t, identity.Groups, []string{ | ||
"ops/project:owner", | ||
"dev/project1:maintainer", | ||
"dev/project2:developer", | ||
}) | ||
} | ||
|
||
func newTestServer(responses map[string]interface{}) *httptest.Server { | ||
return httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
response := responses[r.RequestURI] | ||
|