mirror of
https://github.com/netbirdio/dex.git
synced 2026-05-22 18:43:53 -07:00
Address issues raised in review:
Improve naming Signed-off-by: Oded Ben-Ozer <obenozer@wayfair.com>
This commit is contained in:
@@ -88,16 +88,16 @@ type Config struct {
|
||||
GroupsKey string `json:"groups"` // defaults to "groups"
|
||||
} `json:"claimMapping"`
|
||||
|
||||
// ClaimModifications holds all claim modifications options
|
||||
ClaimModifications struct {
|
||||
NewGroupsFromClaims []NewGroupsFromClaims `json:"newGroupsFromClaims"`
|
||||
// ClaimMutations holds all claim mutations options
|
||||
ClaimMutations struct {
|
||||
NewGroupFromClaims []NewGroupFromClaims `json:"newGroupFromClaims"`
|
||||
} `json:"claimModifications"`
|
||||
}
|
||||
|
||||
// NewGroupFromClaims creates a new group from a list of claims and appends it to the list of existing groups.
|
||||
type NewGroupsFromClaims struct {
|
||||
type NewGroupFromClaims struct {
|
||||
// List of claim to join together
|
||||
ClaimList []string `json:"claimList"`
|
||||
Claims []string `json:"claims"`
|
||||
|
||||
// String to separate the claims
|
||||
Delimiter string `json:"delimiter"`
|
||||
@@ -210,7 +210,7 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
|
||||
preferredUsernameKey: c.ClaimMapping.PreferredUsernameKey,
|
||||
emailKey: c.ClaimMapping.EmailKey,
|
||||
groupsKey: c.ClaimMapping.GroupsKey,
|
||||
newGroupsFromClaims: c.ClaimModifications.NewGroupsFromClaims,
|
||||
newGroupFromClaims: c.ClaimMutations.NewGroupFromClaims,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ type oidcConnector struct {
|
||||
preferredUsernameKey string
|
||||
emailKey string
|
||||
groupsKey string
|
||||
newGroupsFromClaims []NewGroupsFromClaims
|
||||
newGroupFromClaims []NewGroupFromClaims
|
||||
}
|
||||
|
||||
func (c *oidcConnector) Close() error {
|
||||
@@ -450,11 +450,11 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
|
||||
}
|
||||
}
|
||||
|
||||
for _, config := range c.newGroupsFromClaims {
|
||||
for _, config := range c.newGroupFromClaims {
|
||||
newGroupSegments := []string{
|
||||
config.Prefix,
|
||||
}
|
||||
for _, claimName := range config.ClaimList {
|
||||
for _, claimName := range config.Claims {
|
||||
claimValue, ok := claims[claimName].(string)
|
||||
if !ok { // Non string claim value are ignored, concatenating them doesn't really make any sense
|
||||
continue
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestHandleCallback(t *testing.T) {
|
||||
expectPreferredUsername string
|
||||
expectedEmailField string
|
||||
token map[string]interface{}
|
||||
newGroupsFromClaims []NewGroupsFromClaims
|
||||
newGroupFromClaims []NewGroupFromClaims
|
||||
}{
|
||||
{
|
||||
name: "simpleCase",
|
||||
@@ -297,9 +297,9 @@ func TestHandleCallback(t *testing.T) {
|
||||
expectUserName: "namevalue",
|
||||
expectGroups: []string{"group1", "gh::acme::pipeline-one", "clr_delim-acme-foobar", "keep_delim-acme-foo-bar", "bk-emailvalue"},
|
||||
expectedEmailField: "emailvalue",
|
||||
newGroupsFromClaims: []NewGroupsFromClaims{
|
||||
newGroupFromClaims: []NewGroupFromClaims{
|
||||
{ // The basic functionality, should create "gh::acme::pipeline-one".
|
||||
ClaimList: []string{
|
||||
Claims: []string{
|
||||
"organization",
|
||||
"pipeline",
|
||||
},
|
||||
@@ -307,7 +307,7 @@ func TestHandleCallback(t *testing.T) {
|
||||
Prefix: "gh",
|
||||
},
|
||||
{ // Non existing claims, should not generate any any new group claim.
|
||||
ClaimList: []string{
|
||||
Claims: []string{
|
||||
"non-existing1",
|
||||
"non-existing2",
|
||||
},
|
||||
@@ -317,7 +317,7 @@ func TestHandleCallback(t *testing.T) {
|
||||
{ // In this case the delimiter character("-") should be removed removed from "claim-with-delimiter" claim to ensure the resulting
|
||||
// claim structure is in full control of the Dex operator and not the person creating a new pipeline.
|
||||
// Should create "clr_delim-acme-foobar" and not "tfe-acme-foo-bar".
|
||||
ClaimList: []string{
|
||||
Claims: []string{
|
||||
"organization",
|
||||
"claim-with-delimiter",
|
||||
},
|
||||
@@ -327,7 +327,7 @@ func TestHandleCallback(t *testing.T) {
|
||||
},
|
||||
{ // In this case the delimiter character("-") should be NOT removed from "claim-with-delimiter" claim.
|
||||
// Should create "keep_delim-acme-foo-bar".
|
||||
ClaimList: []string{
|
||||
Claims: []string{
|
||||
"organization",
|
||||
"claim-with-delimiter",
|
||||
},
|
||||
@@ -336,7 +336,7 @@ func TestHandleCallback(t *testing.T) {
|
||||
Prefix: "keep_delim",
|
||||
},
|
||||
{ // Ignore non string claims (like arrays), this should result in "bk-emailvalue".
|
||||
ClaimList: []string{
|
||||
Claims: []string{
|
||||
"non-string-claim",
|
||||
"non-string-claim2",
|
||||
"email",
|
||||
@@ -397,7 +397,7 @@ func TestHandleCallback(t *testing.T) {
|
||||
config.ClaimMapping.PreferredUsernameKey = tc.preferredUsernameKey
|
||||
config.ClaimMapping.EmailKey = tc.emailKey
|
||||
config.ClaimMapping.GroupsKey = tc.groupsKey
|
||||
config.ClaimModifications.NewGroupsFromClaims = tc.newGroupsFromClaims
|
||||
config.ClaimMutations.NewGroupFromClaims = tc.newGroupFromClaims
|
||||
|
||||
conn, err := newConnector(config)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user