summaryrefslogtreecommitdiff
path: root/internal/handlers/handler_firstfactor_test.go
diff options
context:
space:
mode:
authorClement Michaud <clement.michaud34@gmail.com>2019-11-30 15:33:45 +0100
committerClément Michaud <clement.michaud34@gmail.com>2019-12-05 11:05:24 +0100
commitbe802cfc7b5cf7d8c85bb7053dd652efa992ed00 (patch)
treee71c7b166e8bb5687089d78b037cad1867827832 /internal/handlers/handler_firstfactor_test.go
parent1617d98b110f1d3f50012f548b30293418b95d46 (diff)
Fix unit tests.
Diffstat (limited to 'internal/handlers/handler_firstfactor_test.go')
-rw-r--r--internal/handlers/handler_firstfactor_test.go31
1 files changed, 15 insertions, 16 deletions
diff --git a/internal/handlers/handler_firstfactor_test.go b/internal/handlers/handler_firstfactor_test.go
index 241c362a0..b9c61cc9e 100644
--- a/internal/handlers/handler_firstfactor_test.go
+++ b/internal/handlers/handler_firstfactor_test.go
@@ -3,7 +3,6 @@ package handlers
import (
"fmt"
"testing"
- "time"
"github.com/clems4ever/authelia/internal/mocks"
"github.com/clems4ever/authelia/internal/models"
@@ -61,6 +60,14 @@ func (s *FirstFactorSuite) TestShouldFailIfUserProviderCheckPasswordFail() {
CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")).
Return(false, fmt.Errorf("Failed"))
+ s.mock.StorageProviderMock.
+ EXPECT().
+ AppendAuthenticationLog(gomock.Eq(models.AuthenticationAttempt{
+ Username: "test",
+ Successful: false,
+ Time: s.mock.Clock.Now(),
+ }))
+
s.mock.Ctx.Request.SetBodyString(`{
"username": "test",
"password": "hello",
@@ -73,9 +80,6 @@ func (s *FirstFactorSuite) TestShouldFailIfUserProviderCheckPasswordFail() {
}
func (s *FirstFactorSuite) TestShouldCheckAuthenticationIsMarkedWhenInvalidCredentials() {
- t, _ := time.Parse("2006-Jan-02", "2013-Feb-03")
- s.mock.Clock.Set(t)
-
s.mock.UserProviderMock.
EXPECT().
CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")).
@@ -86,7 +90,7 @@ func (s *FirstFactorSuite) TestShouldCheckAuthenticationIsMarkedWhenInvalidCrede
AppendAuthenticationLog(gomock.Eq(models.AuthenticationAttempt{
Username: "test",
Successful: false,
- Time: t,
+ Time: s.mock.Clock.Now(),
}))
s.mock.Ctx.Request.SetBodyString(`{
@@ -104,16 +108,16 @@ func (s *FirstFactorSuite) TestShouldFailIfUserProviderGetDetailsFail() {
CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")).
Return(true, nil)
- s.mock.UserProviderMock.
- EXPECT().
- GetDetails(gomock.Eq("test")).
- Return(nil, fmt.Errorf("Failed"))
-
s.mock.StorageProviderMock.
EXPECT().
AppendAuthenticationLog(gomock.Any()).
Return(nil)
+ s.mock.UserProviderMock.
+ EXPECT().
+ GetDetails(gomock.Eq("test")).
+ Return(nil, fmt.Errorf("Failed"))
+
s.mock.Ctx.Request.SetBodyString(`{
"username": "test",
"password": "hello",
@@ -125,17 +129,12 @@ func (s *FirstFactorSuite) TestShouldFailIfUserProviderGetDetailsFail() {
s.mock.Assert200KO(s.T(), "Authentication failed. Check your credentials.")
}
-func (s *FirstFactorSuite) TestShouldFailIfAuthenticationLoggingFail() {
+func (s *FirstFactorSuite) TestShouldFailIfAuthenticationMarkFail() {
s.mock.UserProviderMock.
EXPECT().
CheckUserPassword(gomock.Eq("test"), gomock.Eq("hello")).
Return(true, nil)
- s.mock.UserProviderMock.
- EXPECT().
- GetDetails(gomock.Eq("test")).
- Return(nil, nil)
-
s.mock.StorageProviderMock.
EXPECT().
AppendAuthenticationLog(gomock.Any()).