forked from mystiq/dex
Bug fix: take into account 'teamNameField' settings while fetching all user groups
This commit is contained in:
parent
e876353128
commit
ce3cd53a11
2 changed files with 36 additions and 9 deletions
|
@ -445,7 +445,7 @@ func (c *githubConnector) userOrgTeams(ctx context.Context, client *http.Client)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range teams {
|
for _, t := range teams {
|
||||||
groups[t.Org.Login] = append(groups[t.Org.Login], t.Name)
|
groups[t.Org.Login] = append(groups[t.Org.Login], c.teamGroupClaim(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiURL == "" {
|
if apiURL == "" {
|
||||||
|
@ -680,14 +680,9 @@ func (c *githubConnector) teamsForOrg(ctx context.Context, client *http.Client,
|
||||||
return nil, fmt.Errorf("github: get teams: %v", err)
|
return nil, fmt.Errorf("github: get teams: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, team := range teams {
|
for _, t := range teams {
|
||||||
if team.Org.Login == orgName {
|
if t.Org.Login == orgName {
|
||||||
switch c.teamNameField {
|
groups = append(groups, c.teamGroupClaim(t))
|
||||||
case "name", "":
|
|
||||||
groups = append(groups, team.Name)
|
|
||||||
case "slug":
|
|
||||||
groups = append(groups, team.Slug)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,3 +693,13 @@ func (c *githubConnector) teamsForOrg(ctx context.Context, client *http.Client,
|
||||||
|
|
||||||
return groups, nil
|
return groups, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// teamGroupClaim returns team slag if 'teamNameField; option is set to 'slug' otherwise returns team name.
|
||||||
|
func (c *githubConnector) teamGroupClaim(t team) string {
|
||||||
|
switch c.teamNameField {
|
||||||
|
case "slug":
|
||||||
|
return t.Slug
|
||||||
|
default:
|
||||||
|
return t.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,28 @@ func TestUserGroupsWithoutOrgs(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUserGroupsWithTeamNameFieldConfig(t *testing.T) {
|
||||||
|
s := newTestServer(map[string]testResponse{
|
||||||
|
"/user/orgs": {
|
||||||
|
data: []org{{Login: "org-1"}},
|
||||||
|
},
|
||||||
|
"/user/teams": {
|
||||||
|
data: []team{
|
||||||
|
{Name: "Team 1", Slug: "team-1", Org: org{Login: "org-1"}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
defer s.Close()
|
||||||
|
|
||||||
|
c := githubConnector{apiURL: s.URL, teamNameField: "slug"}
|
||||||
|
groups, err := c.userGroups(context.Background(), newClient())
|
||||||
|
|
||||||
|
expectNil(t, err)
|
||||||
|
expectEquals(t, groups, []string{
|
||||||
|
"org-1:team-1",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestUsernameIncludedInFederatedIdentity(t *testing.T) {
|
func TestUsernameIncludedInFederatedIdentity(t *testing.T) {
|
||||||
|
|
||||||
s := newTestServer(map[string]testResponse{
|
s := newTestServer(map[string]testResponse{
|
||||||
|
|
Loading…
Reference in a new issue