-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #711 from smallstep/oidc-admin-group
Check for admins in both emails and groups.
- Loading branch information
Showing
3 changed files
with
69 additions
and
39 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
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 |
---|---|---|
|
@@ -698,3 +698,39 @@ func Test_sanitizeEmail(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func Test_openIDPayload_IsAdmin(t *testing.T) { | ||
type fields struct { | ||
Email string | ||
Groups []string | ||
} | ||
type args struct { | ||
admins []string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want bool | ||
}{ | ||
{"ok email", fields{"[email protected]", nil}, args{[]string{"[email protected]"}}, true}, | ||
{"ok email multiple", fields{"[email protected]", []string{"admin", "eng"}}, args{[]string{"[email protected]", "[email protected]"}}, true}, | ||
{"ok email sanitized", fields{"[email protected]", nil}, args{[]string{"[email protected]"}}, true}, | ||
{"ok group", fields{"", []string{"admin"}}, args{[]string{"admin"}}, true}, | ||
{"ok group multiple", fields{"[email protected]", []string{"engineering", "admin"}}, args{[]string{"admin"}}, true}, | ||
{"fail missing", fields{"[email protected]", []string{"admin"}}, args{[]string{"[email protected]"}}, false}, | ||
{"fail email letter case", fields{"[email protected]", []string{}}, args{[]string{"[email protected]"}}, false}, | ||
{"fail group letter case", fields{"", []string{"Admin"}}, args{[]string{"admin"}}, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
o := &openIDPayload{ | ||
Email: tt.fields.Email, | ||
Groups: tt.fields.Groups, | ||
} | ||
if got := o.IsAdmin(tt.args.admins); got != tt.want { | ||
t.Errorf("openIDPayload.IsAdmin() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |