forked from mesosphere/traefik-forward-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`makeSessionCookie` turns its err value into a nil, losing its info. Also make fatal problems use Error and non-fatal problems use Warn. cherry-pick 3e4e6f9
- Loading branch information
Showing
4 changed files
with
38 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,8 @@ func TestAuthValidateCookie(t *testing.T) { | |
// Should catch expired | ||
config.Lifetime = time.Second * time.Duration(-1) | ||
a = NewAuthenticator(config) | ||
c = a.MakeIDCookie(r, "[email protected]", "") | ||
c, err = a.MakeIDCookie(r, "[email protected]", "") | ||
assert.Nil(err) | ||
_, err = a.ValidateCookie(r, c) | ||
if assert.Error(err) { | ||
assert.Equal("securecookie: expired timestamp", err.Error()) | ||
|
@@ -61,7 +62,8 @@ func TestAuthValidateCookie(t *testing.T) { | |
// Should accept valid cookie | ||
config.Lifetime = time.Second * time.Duration(10) | ||
a = NewAuthenticator(config) | ||
c = a.MakeIDCookie(r, "[email protected]", "") | ||
c, err = a.MakeIDCookie(r, "[email protected]", "") | ||
assert.Nil(err) | ||
id, err := a.ValidateCookie(r, c) | ||
assert.Nil(err, "valid request should not return an error") | ||
assert.Equal("[email protected]", id.Email, "valid request should return user email") | ||
|
@@ -124,10 +126,11 @@ func TestAuthMakeCookie(t *testing.T) { | |
r, _ := http.NewRequest("GET", "http://app.example.com", nil) | ||
r.Header.Add("X-Forwarded-Host", "app.example.com") | ||
|
||
c := a.MakeIDCookie(r, "[email protected]", "") | ||
c, err := a.MakeIDCookie(r, "[email protected]", "") | ||
assert.Nil(err) | ||
assert.Equal("_forward_auth", c.Name) | ||
assert.Greater(len(c.Value), 18, "encoded securecookie should be longer") | ||
_, err := a.ValidateCookie(r, c) | ||
_, err = a.ValidateCookie(r, c) | ||
assert.Nil(err, "should generate valid cookie") | ||
assert.Equal("/", c.Path) | ||
assert.Equal("app.example.com", c.Domain) | ||
|
@@ -138,7 +141,8 @@ func TestAuthMakeCookie(t *testing.T) { | |
|
||
config.CookieName = "testname" | ||
config.InsecureCookie = true | ||
c = a.MakeIDCookie(r, "[email protected]", "") | ||
c, err = a.MakeIDCookie(r, "[email protected]", "") | ||
assert.Nil(err) | ||
assert.Equal("testname", c.Name) | ||
assert.False(c.Secure) | ||
} | ||
|
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 |
---|---|---|
|
@@ -105,7 +105,8 @@ func TestServerAuthHandlerInvalid(t *testing.T) { | |
req = newDefaultHTTPRequest("/foo") | ||
// NOTE(jkoelker) `notAuthenticated` will redirect if it thinks the request is from a browser | ||
req.Header.Set("Accept", "application/json") | ||
c := a.MakeIDCookie(req, "[email protected]", "") | ||
c, err := a.MakeIDCookie(req, "[email protected]", "") | ||
assert.Nil(err) | ||
config = newTestConfig(testAuthKey2, testEncKey2) // new auth & encryption key! | ||
|
||
config.AuthHost = "" | ||
|
@@ -115,7 +116,8 @@ func TestServerAuthHandlerInvalid(t *testing.T) { | |
// Should validate email | ||
req = newDefaultHTTPRequest("/foo") | ||
a = authentication.NewAuthenticator(config) | ||
c = a.MakeIDCookie(req, "[email protected]", "") | ||
c, err = a.MakeIDCookie(req, "[email protected]", "") | ||
assert.Nil(err) | ||
config.Domains = []string{"test.com"} | ||
|
||
res, _ = doHttpRequest(req, c, config) | ||
|
@@ -132,7 +134,8 @@ func TestServerAuthHandlerExpired(t *testing.T) { | |
|
||
// Should redirect expired cookie | ||
req := newDefaultHTTPRequest("/foo") | ||
c := a.MakeIDCookie(req, "[email protected]", "") | ||
c, err := a.MakeIDCookie(req, "[email protected]", "") | ||
assert.Nil(err) | ||
res, _ := doHttpRequest(req, c, config) | ||
assert.Equal(307, res.StatusCode, "request with expired cookie should be redirected") | ||
|
||
|
@@ -151,7 +154,8 @@ func TestServerAuthHandlerValid(t *testing.T) { | |
|
||
// Should allow valid request email | ||
req := newDefaultHTTPRequest("/foo") | ||
c := a.MakeIDCookie(req, "[email protected]", "") | ||
c, err := a.MakeIDCookie(req, "[email protected]", "") | ||
assert.Nil(err) | ||
|
||
config.Domains = []string{} | ||
|
||
|