-
Notifications
You must be signed in to change notification settings - Fork 188
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 #76 from Remitly/refactor-provider-options
Refactor provider options
- Loading branch information
Showing
8 changed files
with
124 additions
and
66 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 |
---|---|---|
|
@@ -1541,7 +1541,9 @@ func TestOAuthStart(t *testing.T) { | |
opts := testOpts("abced", "testtest") | ||
opts.RedirectURL = "https://example.com/oauth2/callback" | ||
opts.Validate() | ||
proxy, _ := NewAuthenticator(opts, func(p *Authenticator) error { | ||
u, _ := url.Parse("http://example.com") | ||
provider := providers.NewTestProvider(u) | ||
proxy, _ := NewAuthenticator(opts, setTestProvider(provider), func(p *Authenticator) error { | ||
p.Validator = func(string) bool { return true } | ||
return nil | ||
}, setMockCSRFStore(&sessions.MockCSRFStore{})) | ||
|
@@ -1632,3 +1634,45 @@ func TestHostHeader(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestGoogleProviderApiSettings(t *testing.T) { | ||
opts := testOpts("abced", "testtest") | ||
opts.Provider = "google" | ||
opts.Validate() | ||
proxy, _ := NewAuthenticator(opts, AssignProvider(opts), func(p *Authenticator) error { | ||
p.Validator = func(string) bool { return true } | ||
return nil | ||
}) | ||
p := proxy.provider.Data() | ||
testutil.Equal(t, "https://accounts.google.com/o/oauth2/auth?access_type=offline", | ||
p.SignInURL.String()) | ||
testutil.Equal(t, "https://www.googleapis.com/oauth2/v3/token", | ||
p.RedeemURL.String()) | ||
testutil.Equal(t, "", p.ProfileURL.String()) | ||
testutil.Equal(t, "profile email", p.Scope) | ||
} | ||
|
||
func TestGoogleGroupInvalidFile(t *testing.T) { | ||
opts := testOpts("abced", "testtest") | ||
opts.Provider = "google" | ||
opts.GoogleAdminEmail = "[email protected]" | ||
opts.GoogleServiceAccountJSON = "file_doesnt_exist.json" | ||
opts.Validate() | ||
_, err := NewAuthenticator(opts, AssignProvider(opts), func(p *Authenticator) error { | ||
p.Validator = func(string) bool { return true } | ||
return nil | ||
}) | ||
testutil.NotEqual(t, nil, err) | ||
testutil.Equal(t, "invalid Google credentials file: file_doesnt_exist.json", err.Error()) | ||
} | ||
|
||
func TestUnimplementedProvider(t *testing.T) { | ||
opts := testOpts("abced", "testtest") | ||
opts.Validate() | ||
_, err := NewAuthenticator(opts, AssignProvider(opts), func(p *Authenticator) error { | ||
p.Validator = func(string) bool { return true } | ||
return nil | ||
}) | ||
testutil.NotEqual(t, nil, err) | ||
testutil.Equal(t, "unimplemented provider: \"\"", err.Error()) | ||
} |
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 |
---|---|---|
|
@@ -53,21 +53,6 @@ func TestNewOptions(t *testing.T) { | |
testutil.Equal(t, expected, err.Error()) | ||
} | ||
|
||
func TestGoogleGroupInvalidFile(t *testing.T) { | ||
defer func() { | ||
r := recover() | ||
panicMsg := "could not read google credentials file" | ||
if r != panicMsg { | ||
t.Errorf("expected panic with message %s but got %s", panicMsg, r) | ||
} | ||
}() | ||
o := testOptions() | ||
o.GoogleAdminEmail = "[email protected]" | ||
o.GoogleServiceAccountJSON = "file_doesnt_exist.json" | ||
o.Validate() | ||
|
||
} | ||
|
||
func TestInitializedOptions(t *testing.T) { | ||
o := testOptions() | ||
testutil.Equal(t, nil, o.Validate()) | ||
|
@@ -84,18 +69,6 @@ func TestRedirectURL(t *testing.T) { | |
testutil.Equal(t, expected, o.redirectURL) | ||
} | ||
|
||
func TestDefaultProviderApiSettings(t *testing.T) { | ||
o := testOptions() | ||
testutil.Equal(t, nil, o.Validate()) | ||
p := o.provider.Data() | ||
testutil.Equal(t, "https://accounts.google.com/o/oauth2/auth?access_type=offline", | ||
p.SignInURL.String()) | ||
testutil.Equal(t, "https://www.googleapis.com/oauth2/v3/token", | ||
p.RedeemURL.String()) | ||
testutil.Equal(t, "", p.ProfileURL.String()) | ||
testutil.Equal(t, "profile email", p.Scope) | ||
} | ||
|
||
func TestCookieRefreshMustBeLessThanCookieExpire(t *testing.T) { | ||
o := testOptions() | ||
testutil.Equal(t, nil, o.Validate()) | ||
|
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