git.iko.soy/typeable/oauth2-proxy
on master help sign in
Validate user during cookie refresh
commit84190ab19aa9fe414e2440d7582eb8748337c1cd authorMike Bland <michael.bland@gsa.gov> dateSat 9 May 2015, 16:48 (11 years ago) parent610341a
2 files changed+20−2
oauthproxy.go+1−1 oauthproxy_test.go+19−1
oauthproxy.go+1−1
@@ -302,7 +302,7 @@ func (p *OauthProxy) ProcessCookie(rw http.ResponseWriter, req *http.Request) (e
302302 } else if p.CookieRefresh != time.Duration(0) {
303303 refresh_threshold := time.Now().Add(p.CookieRefresh)
304304 if refresh_threshold.Unix() > timestamp.Unix() {
305− ok = p.ValidateToken(access_token)
305+ ok = p.Validator(email) && p.ValidateToken(access_token)
306306 if ok {
307307 p.SetCookie(rw, req, value)
308308 }
oauthproxy_test.go+19−1
@@ -397,6 +397,7 @@ type ProcessCookieTest struct {
397397 req *http.Request
398398 backend *httptest.Server
399399 response_code int
400+ validate_user bool
400401}
401402
402403func NewProcessCookieTest() *ProcessCookieTest {
@@ -414,7 +415,7 @@ func NewProcessCookieTest() *ProcessCookieTest {
414415 pc_test.opts.Validate()
415416
416417 pc_test.proxy = NewOauthProxy(pc_test.opts, func(email string) bool {
417− return true
418+ return pc_test.validate_user
418419 })
419420
420421 // Now, zero-out proxy.CookieRefresh for the cases that don't involve
@@ -422,6 +423,7 @@ func NewProcessCookieTest() *ProcessCookieTest {
422423 pc_test.proxy.CookieRefresh = time.Duration(0)
423424 pc_test.rw = httptest.NewRecorder()
424425 pc_test.req, _ = http.NewRequest("GET", "/", strings.NewReader(""))
426+ pc_test.validate_user = true
425427 return &pc_test
426428}
427429
@@ -529,3 +531,19 @@ func TestProcessCookieFailIfRefreshSetAndTokenNoLongerValid(t *testing.T) {
529531 assert.Equal(t, false, ok)
530532 assert.Equal(t, []string(nil), pc_test.rw.HeaderMap["Set-Cookie"])
531533}
534+
535+func TestProcessCookieFailIfRefreshSetAndUserNoLongerValid(t *testing.T) {
536+ pc_test := NewProcessCookieTest()
537+ pc_test.InstantiateBackend()
538+ defer pc_test.Close()
539+ pc_test.validate_user = false
540+
541+ cookie := pc_test.MakeCookie("michael.bland@gsa.gov", "my_access_token")
542+ cookie.Expires = time.Now().Add(time.Duration(23) * time.Hour)
543+ pc_test.req.AddCookie(cookie)
544+
545+ pc_test.proxy.CookieRefresh = time.Duration(24) * time.Hour
546+ _, _, _, ok := pc_test.ProcessCookie()
547+ assert.Equal(t, false, ok)
548+ assert.Equal(t, []string(nil), pc_test.rw.HeaderMap["Set-Cookie"])
549+}