|
|
|
|
@ -20,9 +20,10 @@ import ( |
|
|
|
|
|
|
|
|
|
func TestOAuth_Authenticate(t *testing.T) { |
|
|
|
|
type testCase struct { |
|
|
|
|
desc string |
|
|
|
|
req *authn.Request |
|
|
|
|
oauthCfg *social.OAuthInfo |
|
|
|
|
desc string |
|
|
|
|
req *authn.Request |
|
|
|
|
oauthCfg *social.OAuthInfo |
|
|
|
|
allowInsecureTakeover bool |
|
|
|
|
|
|
|
|
|
addStateCookie bool |
|
|
|
|
stateCookieValue string |
|
|
|
|
@ -127,6 +128,45 @@ func TestOAuth_Authenticate(t *testing.T) { |
|
|
|
|
Role: "Admin", |
|
|
|
|
Groups: []string{"grp1", "grp2"}, |
|
|
|
|
}, |
|
|
|
|
expectedIdentity: &authn.Identity{ |
|
|
|
|
Email: "some@email.com", |
|
|
|
|
AuthModule: "oauth_azuread", |
|
|
|
|
AuthID: "123", |
|
|
|
|
Name: "name", |
|
|
|
|
Groups: []string{"grp1", "grp2"}, |
|
|
|
|
OAuthToken: &oauth2.Token{}, |
|
|
|
|
OrgRoles: map[int64]org.RoleType{1: org.RoleAdmin}, |
|
|
|
|
ClientParams: authn.ClientParams{ |
|
|
|
|
SyncUser: true, |
|
|
|
|
SyncTeams: true, |
|
|
|
|
AllowSignUp: true, |
|
|
|
|
FetchSyncedUser: true, |
|
|
|
|
SyncOrgRoles: true, |
|
|
|
|
LookUpParams: login.UserLookupParams{}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
desc: "should return identity for valid request - and lookup user by email", |
|
|
|
|
req: &authn.Request{HTTPRequest: &http.Request{ |
|
|
|
|
Header: map[string][]string{}, |
|
|
|
|
URL: mustParseURL("http://grafana.com/?state=some-state"), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
oauthCfg: &social.OAuthInfo{UsePKCE: true}, |
|
|
|
|
allowInsecureTakeover: true, |
|
|
|
|
addStateCookie: true, |
|
|
|
|
stateCookieValue: "some-state", |
|
|
|
|
addPKCECookie: true, |
|
|
|
|
pkceCookieValue: "some-pkce-value", |
|
|
|
|
isEmailAllowed: true, |
|
|
|
|
userInfo: &social.BasicUserInfo{ |
|
|
|
|
Id: "123", |
|
|
|
|
Name: "name", |
|
|
|
|
Email: "some@email.com", |
|
|
|
|
Role: "Admin", |
|
|
|
|
Groups: []string{"grp1", "grp2"}, |
|
|
|
|
}, |
|
|
|
|
expectedIdentity: &authn.Identity{ |
|
|
|
|
Email: "some@email.com", |
|
|
|
|
AuthModule: "oauth_azuread", |
|
|
|
|
@ -151,6 +191,10 @@ func TestOAuth_Authenticate(t *testing.T) { |
|
|
|
|
t.Run(tt.desc, func(t *testing.T) { |
|
|
|
|
cfg := setting.NewCfg() |
|
|
|
|
|
|
|
|
|
if tt.allowInsecureTakeover { |
|
|
|
|
cfg.OAuthAllowInsecureEmailLookup = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if tt.addStateCookie { |
|
|
|
|
v := tt.stateCookieValue |
|
|
|
|
if v != "" { |
|
|
|
|
|