-
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.
Merge pull request #1544 from kenperkins/saml-groups
Adding support for allowed groups in SAML Connector
- Loading branch information
Showing
3 changed files
with
150 additions
and
27 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 |
---|---|---|
|
@@ -49,9 +49,10 @@ type responseTest struct { | |
entityIssuer string | ||
|
||
// Attribute customization. | ||
usernameAttr string | ||
emailAttr string | ||
groupsAttr string | ||
usernameAttr string | ||
emailAttr string | ||
groupsAttr string | ||
allowedGroups []string | ||
|
||
// Expected outcome of the test. | ||
wantErr bool | ||
|
@@ -98,6 +99,96 @@ func TestGroups(t *testing.T) { | |
test.run(t) | ||
} | ||
|
||
func TestGroupsWhitelist(t *testing.T) { | ||
test := responseTest{ | ||
caFile: "testdata/ca.crt", | ||
respFile: "testdata/good-resp.xml", | ||
now: "2017-04-04T04:34:59.330Z", | ||
usernameAttr: "Name", | ||
emailAttr: "email", | ||
groupsAttr: "groups", | ||
allowedGroups: []string{"Admins"}, | ||
inResponseTo: "6zmm5mguyebwvajyf2sdwwcw6m", | ||
redirectURI: "http://127.0.0.1:5556/dex/callback", | ||
wantIdent: connector.Identity{ | ||
UserID: "[email protected]", | ||
Username: "Eric", | ||
Email: "[email protected]", | ||
EmailVerified: true, | ||
Groups: []string{"Admins", "Everyone"}, | ||
}, | ||
} | ||
test.run(t) | ||
} | ||
|
||
func TestGroupsWhitelistEmpty(t *testing.T) { | ||
test := responseTest{ | ||
caFile: "testdata/ca.crt", | ||
respFile: "testdata/good-resp.xml", | ||
now: "2017-04-04T04:34:59.330Z", | ||
usernameAttr: "Name", | ||
emailAttr: "email", | ||
groupsAttr: "groups", | ||
allowedGroups: []string{}, | ||
inResponseTo: "6zmm5mguyebwvajyf2sdwwcw6m", | ||
redirectURI: "http://127.0.0.1:5556/dex/callback", | ||
wantIdent: connector.Identity{ | ||
UserID: "[email protected]", | ||
Username: "Eric", | ||
Email: "[email protected]", | ||
EmailVerified: true, | ||
Groups: []string{"Admins", "Everyone"}, | ||
}, | ||
} | ||
test.run(t) | ||
} | ||
|
||
func TestGroupsWhitelistDisallowed(t *testing.T) { | ||
test := responseTest{ | ||
wantErr: true, | ||
caFile: "testdata/ca.crt", | ||
respFile: "testdata/good-resp.xml", | ||
now: "2017-04-04T04:34:59.330Z", | ||
usernameAttr: "Name", | ||
emailAttr: "email", | ||
groupsAttr: "groups", | ||
allowedGroups: []string{"Nope"}, | ||
inResponseTo: "6zmm5mguyebwvajyf2sdwwcw6m", | ||
redirectURI: "http://127.0.0.1:5556/dex/callback", | ||
wantIdent: connector.Identity{ | ||
UserID: "[email protected]", | ||
Username: "Eric", | ||
Email: "[email protected]", | ||
EmailVerified: true, | ||
Groups: []string{"Admins", "Everyone"}, | ||
}, | ||
} | ||
test.run(t) | ||
} | ||
|
||
func TestGroupsWhitelistDisallowedNoGroupsOnIdent(t *testing.T) { | ||
test := responseTest{ | ||
wantErr: true, | ||
caFile: "testdata/ca.crt", | ||
respFile: "testdata/good-resp.xml", | ||
now: "2017-04-04T04:34:59.330Z", | ||
usernameAttr: "Name", | ||
emailAttr: "email", | ||
groupsAttr: "groups", | ||
allowedGroups: []string{"Nope"}, | ||
inResponseTo: "6zmm5mguyebwvajyf2sdwwcw6m", | ||
redirectURI: "http://127.0.0.1:5556/dex/callback", | ||
wantIdent: connector.Identity{ | ||
UserID: "[email protected]", | ||
Username: "Eric", | ||
Email: "[email protected]", | ||
EmailVerified: true, | ||
Groups: []string{}, | ||
}, | ||
} | ||
test.run(t) | ||
} | ||
|
||
// TestOkta tests against an actual response from Okta. | ||
func TestOkta(t *testing.T) { | ||
test := responseTest{ | ||
|
@@ -290,12 +381,13 @@ func loadCert(ca string) (*x509.Certificate, error) { | |
|
||
func (r responseTest) run(t *testing.T) { | ||
c := Config{ | ||
CA: r.caFile, | ||
UsernameAttr: r.usernameAttr, | ||
EmailAttr: r.emailAttr, | ||
GroupsAttr: r.groupsAttr, | ||
RedirectURI: r.redirectURI, | ||
EntityIssuer: r.entityIssuer, | ||
CA: r.caFile, | ||
UsernameAttr: r.usernameAttr, | ||
EmailAttr: r.emailAttr, | ||
GroupsAttr: r.groupsAttr, | ||
RedirectURI: r.redirectURI, | ||
EntityIssuer: r.entityIssuer, | ||
AllowedGroups: r.allowedGroups, | ||
// Never logging in, don't need this. | ||
SSOURL: "http://foo.bar/", | ||
} | ||
|