This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
47 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
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 |
---|---|---|
|
@@ -348,13 +348,12 @@ func NewProcessCookieTest(opts ProcessCookieTestOpts) *ProcessCookieTest { | |
|
||
pc_test.opts = NewOptions() | ||
pc_test.opts.Upstreams = append(pc_test.opts.Upstreams, "unused") | ||
pc_test.opts.CookieSecret = "foobar" | ||
pc_test.opts.ClientID = "bazquux" | ||
pc_test.opts.ClientSecret = "xyzzyplugh" | ||
pc_test.opts.CookieSecret = "0123456789abcdef" | ||
// First, set the CookieRefresh option so proxy.AesCipher is created, | ||
// needed to encrypt the access_token. | ||
pc_test.opts.CookieRefresh = time.Duration(24) * time.Hour | ||
pc_test.opts.CookieRefresh = time.Hour | ||
pc_test.opts.Validate() | ||
|
||
pc_test.proxy = NewOauthProxy(pc_test.opts, func(email string) bool { | ||
|
@@ -379,14 +378,13 @@ func NewProcessCookieTestWithDefaults() *ProcessCookieTest { | |
}) | ||
} | ||
|
||
func (p *ProcessCookieTest) MakeCookie(value, access_token string) *http.Cookie { | ||
cookie_value, _ := buildCookieValue( | ||
value, p.proxy.AesCipher, access_token) | ||
return p.proxy.MakeCookie(p.req, cookie_value, p.opts.CookieExpire) | ||
func (p *ProcessCookieTest) MakeCookie(value, access_token string, ref time.Time) *http.Cookie { | ||
cookie_value, _ := buildCookieValue(value, p.proxy.AesCipher, access_token) | ||
return p.proxy.MakeCookie(p.req, cookie_value, p.opts.CookieExpire, ref) | ||
} | ||
|
||
func (p *ProcessCookieTest) AddCookie(value, access_token string) { | ||
p.req.AddCookie(p.MakeCookie(value, access_token)) | ||
p.req.AddCookie(p.MakeCookie(value, access_token, time.Now())) | ||
} | ||
|
||
func (p *ProcessCookieTest) ProcessCookie() (email, user, access_token string, ok bool) { | ||
|
@@ -416,15 +414,16 @@ func TestProcessCookieFailIfParsingCookieValueFails(t *testing.T) { | |
pc_test.proxy.AesCipher, "my_access_token") | ||
pc_test.req.AddCookie(pc_test.proxy.MakeCookie( | ||
pc_test.req, value+"some bogus bytes", | ||
pc_test.opts.CookieExpire)) | ||
pc_test.opts.CookieExpire, time.Now())) | ||
_, _, _, ok := pc_test.ProcessCookie() | ||
assert.Equal(t, false, ok) | ||
} | ||
|
||
func TestProcessCookieRefreshNotSet(t *testing.T) { | ||
pc_test := NewProcessCookieTestWithDefaults() | ||
pc_test.proxy.CookieExpire = time.Duration(23) * time.Hour | ||
cookie := pc_test.MakeCookie("[email protected]", "") | ||
reference := time.Now().Add(time.Duration(-2) * time.Hour) | ||
cookie := pc_test.MakeCookie("[email protected]", "", reference) | ||
pc_test.req.AddCookie(cookie) | ||
|
||
_, _, _, ok := pc_test.ProcessCookie() | ||
|
@@ -435,22 +434,24 @@ func TestProcessCookieRefreshNotSet(t *testing.T) { | |
func TestProcessCookieRefresh(t *testing.T) { | ||
pc_test := NewProcessCookieTestWithDefaults() | ||
pc_test.proxy.CookieExpire = time.Duration(23) * time.Hour | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token") | ||
reference := time.Now().Add(time.Duration(-2) * time.Hour) | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token", reference) | ||
pc_test.req.AddCookie(cookie) | ||
|
||
pc_test.proxy.CookieRefresh = time.Duration(24) * time.Hour | ||
pc_test.proxy.CookieRefresh = time.Hour | ||
_, _, _, ok := pc_test.ProcessCookie() | ||
assert.Equal(t, true, ok) | ||
assert.NotEqual(t, []string(nil), pc_test.rw.HeaderMap["Set-Cookie"]) | ||
} | ||
|
||
func TestProcessCookieRefreshThresholdNotCrossed(t *testing.T) { | ||
pc_test := NewProcessCookieTestWithDefaults() | ||
pc_test.proxy.CookieExpire = time.Duration(25) * time.Hour | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token") | ||
pc_test.proxy.CookieExpire = time.Duration(23) * time.Hour | ||
reference := time.Now().Add(time.Duration(-30) * time.Minute) | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token", reference) | ||
pc_test.req.AddCookie(cookie) | ||
|
||
pc_test.proxy.CookieRefresh = time.Duration(24) * time.Hour | ||
pc_test.proxy.CookieRefresh = time.Hour | ||
_, _, _, ok := pc_test.ProcessCookie() | ||
assert.Equal(t, true, ok) | ||
assert.Equal(t, []string(nil), pc_test.rw.HeaderMap["Set-Cookie"]) | ||
|
@@ -461,10 +462,11 @@ func TestProcessCookieFailIfRefreshSetAndTokenNoLongerValid(t *testing.T) { | |
provider_validate_cookie_response: false, | ||
}) | ||
pc_test.proxy.CookieExpire = time.Duration(23) * time.Hour | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token") | ||
reference := time.Now().Add(time.Duration(-24) * time.Hour) | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token", reference) | ||
pc_test.req.AddCookie(cookie) | ||
|
||
pc_test.proxy.CookieRefresh = time.Duration(24) * time.Hour | ||
pc_test.proxy.CookieRefresh = time.Hour | ||
_, _, _, ok := pc_test.ProcessCookie() | ||
assert.Equal(t, false, ok) | ||
assert.Equal(t, []string(nil), pc_test.rw.HeaderMap["Set-Cookie"]) | ||
|
@@ -475,10 +477,11 @@ func TestProcessCookieFailIfRefreshSetAndUserNoLongerValid(t *testing.T) { | |
pc_test.validate_user = false | ||
|
||
pc_test.proxy.CookieExpire = time.Duration(23) * time.Hour | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token") | ||
reference := time.Now().Add(time.Duration(-2) * time.Hour) | ||
cookie := pc_test.MakeCookie("[email protected]", "my_access_token", reference) | ||
pc_test.req.AddCookie(cookie) | ||
|
||
pc_test.proxy.CookieRefresh = time.Duration(24) * time.Hour | ||
pc_test.proxy.CookieRefresh = time.Hour | ||
_, _, _, ok := pc_test.ProcessCookie() | ||
assert.Equal(t, false, ok) | ||
assert.Equal(t, []string(nil), pc_test.rw.HeaderMap["Set-Cookie"]) | ||
|