-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for
sub
claim, not username
, when validating
Not all IdPs provide a `username` or `email` claim in the UserInfo response.
- Loading branch information
Showing
8 changed files
with
83 additions
and
19 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 |
---|---|---|
|
@@ -46,7 +46,12 @@ func setUp(configFile string) { | |
|
||
func TestVerifyUserPositiveUserInWhiteList(t *testing.T) { | ||
setUp("/config/testing/handler_whitelist.yml") | ||
user := &structs.User{Username: "[email protected]", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "[email protected]", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
ok, err := verifyUser(*user) | ||
assert.True(t, ok) | ||
assert.Nil(t, err) | ||
|
@@ -55,7 +60,12 @@ func TestVerifyUserPositiveUserInWhiteList(t *testing.T) { | |
func TestVerifyUserPositiveAllowAllUsers(t *testing.T) { | ||
setUp("/config/testing/handler_allowallusers.yml") | ||
|
||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
|
||
ok, err := verifyUser(*user) | ||
assert.True(t, ok) | ||
|
@@ -64,7 +74,12 @@ func TestVerifyUserPositiveAllowAllUsers(t *testing.T) { | |
|
||
func TestVerifyUserPositiveByEmail(t *testing.T) { | ||
setUp("/config/testing/handler_email.yml") | ||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
ok, err := verifyUser(*user) | ||
assert.True(t, ok) | ||
assert.Nil(t, err) | ||
|
@@ -74,7 +89,12 @@ func TestVerifyUserPositiveByTeam(t *testing.T) { | |
setUp("/config/testing/handler_teams.yml") | ||
|
||
// cfg.Cfg.TeamWhiteList = append(cfg.Cfg.TeamWhiteList, "org1/team2", "org1/team1") | ||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
user.TeamMemberships = append(user.TeamMemberships, "org1/team3") | ||
user.TeamMemberships = append(user.TeamMemberships, "org1/team1") | ||
ok, err := verifyUser(*user) | ||
|
@@ -84,7 +104,12 @@ func TestVerifyUserPositiveByTeam(t *testing.T) { | |
|
||
func TestVerifyUserNegativeByTeam(t *testing.T) { | ||
setUp("/config/testing/handler_teams.yml") | ||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
// cfg.Cfg.TeamWhiteList = append(cfg.Cfg.TeamWhiteList, "org1/team1") | ||
|
||
ok, err := verifyUser(*user) | ||
|
@@ -95,7 +120,12 @@ func TestVerifyUserNegativeByTeam(t *testing.T) { | |
func TestVerifyUserPositiveNoDomainsConfigured(t *testing.T) { | ||
setUp("/config/testing/handler_nodomains.yml") | ||
|
||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
cfg.Cfg.Domains = make([]string, 0) | ||
ok, err := verifyUser(*user) | ||
|
||
|
@@ -105,7 +135,12 @@ func TestVerifyUserPositiveNoDomainsConfigured(t *testing.T) { | |
|
||
func TestVerifyUserNegative(t *testing.T) { | ||
setUp("/config/testing/test_config.yml") | ||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
ok, err := verifyUser(*user) | ||
|
||
assert.False(t, ok) | ||
|
@@ -116,6 +151,7 @@ func TestVerifyUserNegative(t *testing.T) { | |
// it should live there but circular imports are resolved if it lives here | ||
var ( | ||
u1 = structs.User{ | ||
Sub: "test", | ||
Username: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
|
@@ -141,6 +177,7 @@ func init() { | |
// log.SetLevel(log.DebugLevel) | ||
|
||
lc = jwtmanager.VouchClaims{ | ||
u1.Sub, | ||
u1.Username, | ||
jwtmanager.Sites, | ||
customClaims.Claims, | ||
|
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 |
---|---|---|
|
@@ -28,7 +28,12 @@ import ( | |
|
||
func BenchmarkValidateRequestHandler(b *testing.B) { | ||
setUp("/config/testing/handler_email.yml") | ||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
tokens := structs.PTokens{} | ||
customClaims := structs.CustomClaims{} | ||
|
||
|
@@ -66,7 +71,12 @@ func TestValidateRequestHandlerPerf(t *testing.T) { | |
} | ||
|
||
setUp("/config/testing/handler_email.yml") | ||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
tokens := structs.PTokens{} | ||
customClaims := structs.CustomClaims{} | ||
|
||
|
@@ -153,7 +163,12 @@ func TestValidateRequestHandlerWithGroupClaims(t *testing.T) { | |
|
||
tokens := structs.PTokens{} | ||
|
||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
userTokenString := jwtmanager.CreateUserTokenString(*user, customClaims, tokens) | ||
|
||
req, err := http.NewRequest("GET", "/validate", nil) | ||
|
@@ -205,7 +220,12 @@ func TestJWTCacheHandler(t *testing.T) { | |
setUp("/config/testing/handler_logout_url.yml") | ||
handler := jwtmanager.JWTCacheHandler(http.HandlerFunc(ValidateRequestHandler)) | ||
|
||
user := &structs.User{Username: "testuser", Email: "[email protected]", Name: "Test Name"} | ||
user := &structs.User{ | ||
Sub: "testsub", | ||
Username: "testuser", | ||
Email: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
tokens := structs.PTokens{} | ||
customClaims := structs.CustomClaims{} | ||
|
||
|
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
|
||
var ( | ||
u1 = structs.User{ | ||
Sub: "testsub", | ||
Username: "[email protected]", | ||
Name: "Test Name", | ||
} | ||
|
@@ -49,6 +50,7 @@ func init() { | |
Configure() | ||
|
||
lc = VouchClaims{ | ||
u1.Sub, | ||
u1.Username, | ||
Sites, | ||
customClaims.Claims, | ||
|
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