From f819200325f00fd12bed62962f095daf3be399be Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Tue, 23 Mar 2021 18:15:10 +0000 Subject: [PATCH] Remove unneeded cookie fields from OAuth2 Proxy --- oauthproxy.go | 8 ++++---- oauthproxy_test.go | 10 +++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/oauthproxy.go b/oauthproxy.go index 5892ce80..eb9ac759 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -66,8 +66,8 @@ type allowedRoute struct { // OAuthProxy is the main authentication proxy type OAuthProxy struct { - CookieOptions *options.Cookie - Validator func(string) bool + CookieSecure bool + Validator func(string) bool SignInPath string @@ -191,8 +191,8 @@ func NewOAuthProxy(opts *options.Options, validator func(string) bool) (*OAuthPr }) p := &OAuthProxy{ - CookieOptions: &opts.Cookie, - Validator: validator, + CookieSecure: opts.Cookie.Secure, + Validator: validator, SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix), diff --git a/oauthproxy_test.go b/oauthproxy_test.go index 0d5b5955..54990a0b 100644 --- a/oauthproxy_test.go +++ b/oauthproxy_test.go @@ -434,7 +434,7 @@ func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int, cookie // getEndpointWithCookie makes a requests againt the oauthproxy with passed requestPath // and cookie and returns body and status code. func (patTest *PassAccessTokenTest) getEndpointWithCookie(cookie string, endpoint string) (httpCode int, accessToken string) { - cookieName := patTest.proxy.CookieOptions.Name + cookieName := patTest.opts.Cookie.Name var value string keyPrefix := cookieName + "=" @@ -750,9 +750,6 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts, modifiers ...OptionsModifi } pcTest.proxy.provider.(*TestProvider).SetAllowedGroups(pcTest.opts.Providers[0].AllowedGroups) - // Now, zero-out proxy.CookieRefresh for the cases that don't involve - // access_token validation. - pcTest.proxy.CookieOptions.Refresh = time.Duration(0) pcTest.rw = httptest.NewRecorder() pcTest.req, _ = http.NewRequest("GET", "/", strings.NewReader("")) pcTest.validateUser = true @@ -874,7 +871,6 @@ func TestProcessCookieFailIfRefreshSetAndCookieExpired(t *testing.T) { err = pcTest.SaveSession(startSession) assert.NoError(t, err) - pcTest.proxy.CookieOptions.Refresh = time.Hour session, err := pcTest.LoadCookiedSession() assert.NotEqual(t, nil, err) if session != nil { @@ -1624,7 +1620,7 @@ func TestClearSplitCookie(t *testing.T) { t.Fatal(err) } - p := OAuthProxy{CookieOptions: &opts.Cookie, sessionStore: store} + p := OAuthProxy{sessionStore: store} var rw = httptest.NewRecorder() req := httptest.NewRequest("get", "/", nil) @@ -1657,7 +1653,7 @@ func TestClearSingleCookie(t *testing.T) { t.Fatal(err) } - p := OAuthProxy{CookieOptions: &opts.Cookie, sessionStore: store} + p := OAuthProxy{sessionStore: store} var rw = httptest.NewRecorder() req := httptest.NewRequest("get", "/", nil)