1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-04-15 11:56:49 +02:00

Cleanup method name refactors missed in comments

This commit is contained in:
Nick Meves 2020-11-29 14:12:48 -08:00
parent f6ae15e8c3
commit 26ed080bed
No known key found for this signature in database
GPG Key ID: 93BA8A3CEDCDD1CF
9 changed files with 33 additions and 32 deletions

View File

@ -43,6 +43,7 @@
## Changes since v6.1.1 ## Changes since v6.1.1
- [#938](https://github.com/oauth2-proxy/oauth2-proxy/pull/938) Cleanup missed provider renaming refactor methods (@NickMeves)
- [#925](https://github.com/oauth2-proxy/oauth2-proxy/pull/925) Fix basic auth legacy header conversion (@JoelSpeed) - [#925](https://github.com/oauth2-proxy/oauth2-proxy/pull/925) Fix basic auth legacy header conversion (@JoelSpeed)
- [#916](https://github.com/oauth2-proxy/oauth2-proxy/pull/916) Add AlphaOptions struct to prepare for alpha config loading (@JoelSpeed) - [#916](https://github.com/oauth2-proxy/oauth2-proxy/pull/916) Add AlphaOptions struct to prepare for alpha config loading (@JoelSpeed)
- [#923](https://github.com/oauth2-proxy/oauth2-proxy/pull/923) Support TLS 1.3 (@aajisaka) - [#923](https://github.com/oauth2-proxy/oauth2-proxy/pull/923) Support TLS 1.3 (@aajisaka)

View File

@ -279,7 +279,7 @@ func (p *AzureProvider) GetLoginURL(redirectURI, state string) string {
return a.String() return a.String()
} }
// ValidateSessionState validates the AccessToken // ValidateSession validates the AccessToken
func (p *AzureProvider) ValidateSessionState(ctx context.Context, s *sessions.SessionState) bool { func (p *AzureProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
return validateToken(ctx, p, s.AccessToken, makeAzureHeader(s.AccessToken)) return validateToken(ctx, p, s.AccessToken, makeAzureHeader(s.AccessToken))
} }

View File

@ -82,7 +82,7 @@ func (p *DigitalOceanProvider) GetEmailAddress(ctx context.Context, s *sessions.
return email, nil return email, nil
} }
// ValidateSessionState validates the AccessToken // ValidateSession validates the AccessToken
func (p *DigitalOceanProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool { func (p *DigitalOceanProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
return validateToken(ctx, p, s.AccessToken, makeOIDCHeader(s.AccessToken)) return validateToken(ctx, p, s.AccessToken, makeOIDCHeader(s.AccessToken))
} }

View File

@ -102,7 +102,7 @@ func (p *GitHubProvider) SetUsers(users []string) {
p.Users = users p.Users = users
} }
// EnrichSessionState updates the User & Email after the initial Redeem // EnrichSession updates the User & Email after the initial Redeem
func (p *GitHubProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error { func (p *GitHubProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
err := p.getEmail(ctx, s) err := p.getEmail(ctx, s)
if err != nil { if err != nil {
@ -111,7 +111,7 @@ func (p *GitHubProvider) EnrichSession(ctx context.Context, s *sessions.SessionS
return p.getUser(ctx, s) return p.getUser(ctx, s)
} }
// ValidateSessionState validates the AccessToken // ValidateSession validates the AccessToken
func (p *GitHubProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool { func (p *GitHubProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
return validateToken(ctx, p, s.AccessToken, makeGitHubHeader(s.AccessToken)) return validateToken(ctx, p, s.AccessToken, makeGitHubHeader(s.AccessToken))
} }

View File

@ -187,7 +187,7 @@ func (p *GitLabProvider) createSessionState(ctx context.Context, token *oauth2.T
}, nil }, nil
} }
// ValidateSessionState checks that the session's IDToken is still valid // ValidateSession checks that the session's IDToken is still valid
func (p *GitLabProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool { func (p *GitLabProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
_, err := p.Verifier.Verify(ctx, s.IDToken) _, err := p.Verifier.Verify(ctx, s.IDToken)
return err == nil return err == nil

View File

@ -177,10 +177,10 @@ func (p *GoogleProvider) Redeem(ctx context.Context, redirectURL, code string) (
}, nil }, nil
} }
// EnrichSessionState checks the listed Google Groups configured and adds any // EnrichSession checks the listed Google Groups configured and adds any
// that the user is a member of to session.Groups. // that the user is a member of to session.Groups.
func (p *GoogleProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error { func (p *GoogleProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error {
// TODO (@NickMeves) - Move to pure EnrichSessionState logic and stop // TODO (@NickMeves) - Move to pure EnrichSession logic and stop
// reusing legacy `groupValidator`. // reusing legacy `groupValidator`.
// //
// This is called here to get the validator to do the `session.Groups` // This is called here to get the validator to do the `session.Groups`

View File

@ -20,30 +20,30 @@ func updateURL(url *url.URL, hostname string) {
url.Host = hostname url.Host = hostname
} }
type ValidateSessionStateTestProvider struct { type ValidateSessionTestProvider struct {
*ProviderData *ProviderData
} }
var _ Provider = (*ValidateSessionStateTestProvider)(nil) var _ Provider = (*ValidateSessionTestProvider)(nil)
func (tp *ValidateSessionStateTestProvider) GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error) { func (tp *ValidateSessionTestProvider) GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error) {
return "", errors.New("not implemented") return "", errors.New("not implemented")
} }
// Note that we're testing the internal validateToken() used to implement // Note that we're testing the internal validateToken() used to implement
// several Provider's ValidateSessionState() implementations // several Provider's ValidateSession() implementations
func (tp *ValidateSessionStateTestProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool { func (tp *ValidateSessionTestProvider) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
return false return false
} }
type ValidateSessionStateTest struct { type ValidateSessionStateTest struct {
backend *httptest.Server backend *httptest.Server
responseCode int responseCode int
provider *ValidateSessionStateTestProvider provider *ValidateSessionTestProvider
header http.Header header http.Header
} }
func NewValidateSessionStateTest() *ValidateSessionStateTest { func NewValidateSessionTest() *ValidateSessionStateTest {
var vtTest ValidateSessionStateTest var vtTest ValidateSessionStateTest
vtTest.backend = httptest.NewServer( vtTest.backend = httptest.NewServer(
@ -73,7 +73,7 @@ func NewValidateSessionStateTest() *ValidateSessionStateTest {
})) }))
backendURL, _ := url.Parse(vtTest.backend.URL) backendURL, _ := url.Parse(vtTest.backend.URL)
vtTest.provider = &ValidateSessionStateTestProvider{ vtTest.provider = &ValidateSessionTestProvider{
ProviderData: &ProviderData{ ProviderData: &ProviderData{
ValidateURL: &url.URL{ ValidateURL: &url.URL{
Scheme: "http", Scheme: "http",
@ -90,14 +90,14 @@ func (vtTest *ValidateSessionStateTest) Close() {
vtTest.backend.Close() vtTest.backend.Close()
} }
func TestValidateSessionStateValidToken(t *testing.T) { func TestValidateSessionValidToken(t *testing.T) {
vtTest := NewValidateSessionStateTest() vtTest := NewValidateSessionTest()
defer vtTest.Close() defer vtTest.Close()
assert.Equal(t, true, validateToken(context.Background(), vtTest.provider, "foobar", nil)) assert.Equal(t, true, validateToken(context.Background(), vtTest.provider, "foobar", nil))
} }
func TestValidateSessionStateValidTokenWithHeaders(t *testing.T) { func TestValidateSessionValidTokenWithHeaders(t *testing.T) {
vtTest := NewValidateSessionStateTest() vtTest := NewValidateSessionTest()
defer vtTest.Close() defer vtTest.Close()
vtTest.header = make(http.Header) vtTest.header = make(http.Header)
vtTest.header.Set("Authorization", "Bearer foobar") vtTest.header.Set("Authorization", "Bearer foobar")
@ -105,28 +105,28 @@ func TestValidateSessionStateValidTokenWithHeaders(t *testing.T) {
validateToken(context.Background(), vtTest.provider, "foobar", vtTest.header)) validateToken(context.Background(), vtTest.provider, "foobar", vtTest.header))
} }
func TestValidateSessionStateEmptyToken(t *testing.T) { func TestValidateSessionEmptyToken(t *testing.T) {
vtTest := NewValidateSessionStateTest() vtTest := NewValidateSessionTest()
defer vtTest.Close() defer vtTest.Close()
assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "", nil)) assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "", nil))
} }
func TestValidateSessionStateEmptyValidateURL(t *testing.T) { func TestValidateSessionEmptyValidateURL(t *testing.T) {
vtTest := NewValidateSessionStateTest() vtTest := NewValidateSessionTest()
defer vtTest.Close() defer vtTest.Close()
vtTest.provider.Data().ValidateURL = nil vtTest.provider.Data().ValidateURL = nil
assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "foobar", nil)) assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "foobar", nil))
} }
func TestValidateSessionStateRequestNetworkFailure(t *testing.T) { func TestValidateSessionRequestNetworkFailure(t *testing.T) {
vtTest := NewValidateSessionStateTest() vtTest := NewValidateSessionTest()
// Close immediately to simulate a network failure // Close immediately to simulate a network failure
vtTest.Close() vtTest.Close()
assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "foobar", nil)) assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "foobar", nil))
} }
func TestValidateSessionStateExpiredToken(t *testing.T) { func TestValidateSessionExpiredToken(t *testing.T) {
vtTest := NewValidateSessionStateTest() vtTest := NewValidateSessionTest()
defer vtTest.Close() defer vtTest.Close()
vtTest.responseCode = 401 vtTest.responseCode = 401
assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "foobar", nil)) assert.Equal(t, false, validateToken(context.Background(), vtTest.provider, "foobar", nil))

View File

@ -86,12 +86,12 @@ func (p *ProviderData) GetLoginURL(redirectURI, state string) string {
} }
// GetEmailAddress returns the Account email address // GetEmailAddress returns the Account email address
// DEPRECATED: Migrate to EnrichSessionState // DEPRECATED: Migrate to EnrichSession
func (p *ProviderData) GetEmailAddress(_ context.Context, _ *sessions.SessionState) (string, error) { func (p *ProviderData) GetEmailAddress(_ context.Context, _ *sessions.SessionState) (string, error) {
return "", ErrNotImplemented return "", ErrNotImplemented
} }
// EnrichSessionState is called after Redeem to allow providers to enrich session fields // EnrichSession is called after Redeem to allow providers to enrich session fields
// such as User, Email, Groups with provider specific API calls. // such as User, Email, Groups with provider specific API calls.
func (p *ProviderData) EnrichSession(_ context.Context, _ *sessions.SessionState) error { func (p *ProviderData) EnrichSession(_ context.Context, _ *sessions.SessionState) error {
return nil return nil
@ -113,7 +113,7 @@ func (p *ProviderData) Authorize(_ context.Context, s *sessions.SessionState) (b
return false, nil return false, nil
} }
// ValidateSessionState validates the AccessToken // ValidateSession validates the AccessToken
func (p *ProviderData) ValidateSession(ctx context.Context, s *sessions.SessionState) bool { func (p *ProviderData) ValidateSession(ctx context.Context, s *sessions.SessionState) bool {
return validateToken(ctx, p, s.AccessToken, nil) return validateToken(ctx, p, s.AccessToken, nil)
} }

View File

@ -9,7 +9,7 @@ import (
// Provider represents an upstream identity provider implementation // Provider represents an upstream identity provider implementation
type Provider interface { type Provider interface {
Data() *ProviderData Data() *ProviderData
// DEPRECATED: Migrate to EnrichSessionState // DEPRECATED: Migrate to EnrichSession
GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error) GetEmailAddress(ctx context.Context, s *sessions.SessionState) (string, error)
Redeem(ctx context.Context, redirectURI, code string) (*sessions.SessionState, error) Redeem(ctx context.Context, redirectURI, code string) (*sessions.SessionState, error)
EnrichSession(ctx context.Context, s *sessions.SessionState) error EnrichSession(ctx context.Context, s *sessions.SessionState) error