summaryrefslogtreecommitdiff
path: root/internal/handlers/handler_firstfactor_test.go
diff options
context:
space:
mode:
authorClement Michaud <clement.michaud34@gmail.com>2020-01-17 23:48:48 +0100
committerClément Michaud <clement.michaud34@gmail.com>2020-01-18 00:12:36 +0100
commit841de2b75dacf12ffa0d0b8907d069e004657f30 (patch)
tree3c040a11befeeba9ae2cb997a26abff3d1a7276b /internal/handlers/handler_firstfactor_test.go
parent6792fd5bc3dc7830e247b417099a158c047df6f2 (diff)
Disable inactivity timeout when user checked remember me.
Instead of checking the value of the cookie expiration we rely on the boolean stored in the user session to check whether inactivity timeout should be disabled.
Diffstat (limited to 'internal/handlers/handler_firstfactor_test.go')
-rw-r--r--internal/handlers/handler_firstfactor_test.go49
1 files changed, 44 insertions, 5 deletions
diff --git a/internal/handlers/handler_firstfactor_test.go b/internal/handlers/handler_firstfactor_test.go
index 487381998..6129592a3 100644
--- a/internal/handlers/handler_firstfactor_test.go
+++ b/internal/handlers/handler_firstfactor_test.go
@@ -151,7 +151,7 @@ func (s *FirstFactorSuite) TestShouldFailIfAuthenticationMarkFail() {
s.mock.Assert200KO(s.T(), "Authentication failed. Check your credentials.")
}
-func (s *FirstFactorSuite) TestShouldAuthenticateUser() {
+func (s *FirstFactorSuite) TestShouldAuthenticateUserWithRememberMeChecked() {
s.mock.UserProviderMock.
EXPECT().
CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")).
@@ -171,10 +171,10 @@ func (s *FirstFactorSuite) TestShouldAuthenticateUser() {
Return(nil)
s.mock.Ctx.Request.SetBodyString(`{
- "username": "test",
- "password": "hello",
- "keepMeLoggedIn": true
- }`)
+ "username": "test",
+ "password": "hello",
+ "keepMeLoggedIn": true
+ }`)
FirstFactorPost(s.mock.Ctx)
// Respond with 200.
@@ -184,10 +184,49 @@ func (s *FirstFactorSuite) TestShouldAuthenticateUser() {
// And store authentication in session.
session := s.mock.Ctx.GetSession()
assert.Equal(s.T(), "test", session.Username)
+ assert.Equal(s.T(), true, session.KeepMeLoggedIn)
assert.Equal(s.T(), authentication.OneFactor, session.AuthenticationLevel)
assert.Equal(s.T(), []string{"test@example.com"}, session.Emails)
assert.Equal(s.T(), []string{"dev", "admins"}, session.Groups)
+}
+
+func (s *FirstFactorSuite) TestShouldAuthenticateUserWithRememberMeUnchecked() {
+ s.mock.UserProviderMock.
+ EXPECT().
+ CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")).
+ Return(true, nil)
+
+ s.mock.UserProviderMock.
+ EXPECT().
+ GetDetails(gomock.Eq("test")).
+ Return(&authentication.UserDetails{
+ Emails: []string{"test@example.com"},
+ Groups: []string{"dev", "admins"},
+ }, nil)
+ s.mock.StorageProviderMock.
+ EXPECT().
+ AppendAuthenticationLog(gomock.Any()).
+ Return(nil)
+
+ s.mock.Ctx.Request.SetBodyString(`{
+ "username": "test",
+ "password": "hello",
+ "keepMeLoggedIn": false
+ }`)
+ FirstFactorPost(s.mock.Ctx)
+
+ // Respond with 200.
+ assert.Equal(s.T(), 200, s.mock.Ctx.Response.StatusCode())
+ assert.Equal(s.T(), []byte("{\"status\":\"OK\"}"), s.mock.Ctx.Response.Body())
+
+ // And store authentication in session.
+ session := s.mock.Ctx.GetSession()
+ assert.Equal(s.T(), "test", session.Username)
+ assert.Equal(s.T(), false, session.KeepMeLoggedIn)
+ assert.Equal(s.T(), authentication.OneFactor, session.AuthenticationLevel)
+ assert.Equal(s.T(), []string{"test@example.com"}, session.Emails)
+ assert.Equal(s.T(), []string{"dev", "admins"}, session.Groups)
}
func TestFirstFactorSuite(t *testing.T) {