2019-04-24 21:52:08 +00:00
|
|
|
package regulation_test
|
|
|
|
|
|
|
|
import (
|
2023-05-24 12:33:05 +00:00
|
|
|
"fmt"
|
|
|
|
"net"
|
2019-04-24 21:52:08 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-04-05 12:37:21 +00:00
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2023-05-24 12:33:05 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
2020-04-05 12:37:21 +00:00
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/v4/internal/mocks"
|
2022-03-06 05:47:40 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/model"
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/regulation"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type RegulatorSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
mock *mocks.MockAutheliaCtx
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) SetupTest() {
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock = mocks.NewMockAutheliaCtx(s.T())
|
2023-01-26 02:23:47 +00:00
|
|
|
s.mock.Ctx.Configuration.Regulation = schema.Regulation{
|
2019-04-24 21:52:08 +00:00
|
|
|
MaxRetries: 3,
|
2022-03-02 06:40:26 +00:00
|
|
|
BanTime: time.Second * 180,
|
|
|
|
FindTime: time.Second * 30,
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
2023-05-24 12:33:05 +00:00
|
|
|
|
|
|
|
s.mock.Ctx.Request.Header.Set(fasthttp.HeaderXForwardedFor, "127.0.0.1")
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) TearDownTest() {
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.Ctrl.Finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) TestShouldMark() {
|
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
|
|
|
|
|
|
|
s.mock.StorageMock.EXPECT().AppendAuthenticationLog(s.mock.Ctx, model.AuthenticationAttempt{
|
|
|
|
Time: s.mock.Clock.Now(),
|
|
|
|
Successful: true,
|
|
|
|
Banned: false,
|
|
|
|
Username: "john",
|
|
|
|
Type: "1fa",
|
|
|
|
RemoteIP: model.NewNullIP(net.ParseIP("127.0.0.1")),
|
|
|
|
RequestURI: "https://google.com",
|
|
|
|
RequestMethod: fasthttp.MethodGet,
|
|
|
|
})
|
|
|
|
|
|
|
|
s.NoError(regulator.Mark(s.mock.Ctx, true, false, "john", "https://google.com", fasthttp.MethodGet, "1fa"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) TestShouldHandleRegulateError() {
|
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
|
|
|
|
|
|
|
s.mock.StorageMock.EXPECT().LoadAuthenticationLogs(s.mock.Ctx, "john", s.mock.Clock.Now().Add(-s.mock.Ctx.Configuration.Regulation.BanTime), 10, 0).Return(nil, fmt.Errorf("failed"))
|
|
|
|
|
|
|
|
until, err := regulator.Regulate(s.mock.Ctx, "john")
|
|
|
|
|
|
|
|
s.NoError(err)
|
|
|
|
s.Equal(time.Time{}, until)
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) TestShouldNotThrowWhenUserIsLegitimate() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: true,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-4 * time.Minute),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2020-01-26 21:42:05 +00:00
|
|
|
Return(attemptsInDB, nil)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.NoError(s.T(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test checks the case in which a user failed to authenticate many times but always
|
|
|
|
// with a certain amount of time larger than FindTime. Meaning the user should not be banned.
|
|
|
|
func (s *RegulatorSuite) TestShouldNotThrowWhenFailedAuthenticationNotInFindTime() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-1 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-90 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-180 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2019-04-24 21:52:08 +00:00
|
|
|
Return(attemptsInDB, nil)
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.NoError(s.T(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test checks the case in which a user failed to authenticate many times only a few
|
|
|
|
// seconds ago (meaning we are checking from now back to now-FindTime).
|
|
|
|
func (s *RegulatorSuite) TestShouldBanUserIfLatestAttemptsAreWithinFinTime() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-1 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-4 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-6 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-180 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2019-04-24 21:52:08 +00:00
|
|
|
Return(attemptsInDB, nil)
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.Equal(s.T(), regulation.ErrUserIsBanned, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// This test checks the case in which a user failed to authenticate many times only a few
|
|
|
|
// seconds ago (meaning we are checking from now-FindTime+X back to now-2FindTime+X knowing that
|
|
|
|
// we are within now and now-BanTime). It means the user has been banned some time ago and is still
|
|
|
|
// banned right now.
|
|
|
|
func (s *RegulatorSuite) TestShouldCheckUserIsStillBanned() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-31 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-34 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-36 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2019-04-24 21:52:08 +00:00
|
|
|
Return(attemptsInDB, nil)
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.Equal(s.T(), regulation.ErrUserIsBanned, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) TestShouldCheckUserIsNotYetBanned() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-34 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-36 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2019-04-24 21:52:08 +00:00
|
|
|
Return(attemptsInDB, nil)
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.NoError(s.T(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) TestShouldCheckUserWasAboutToBeBanned() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-14 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
// more than 30 seconds elapsed between this auth and the preceding one.
|
|
|
|
// In that case we don't need to regulate the user even though the number
|
|
|
|
// of retrieved attempts is 3.
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-94 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-96 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2019-04-24 21:52:08 +00:00
|
|
|
Return(attemptsInDB, nil)
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.NoError(s.T(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulatorSuite) TestShouldCheckRegulationHasBeenResetOnSuccessfulAttempt() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-90 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: true,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-93 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
// The user was almost banned but he did a successful attempt. Therefore, even if the next
|
2020-01-05 23:03:16 +00:00
|
|
|
// failure happens within FindTime, he should not be banned.
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-94 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2019-04-24 21:52:08 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-96 * time.Second),
|
2019-04-24 21:52:08 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2019-04-24 21:52:08 +00:00
|
|
|
Return(attemptsInDB, nil)
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(s.mock.Ctx.Configuration.Regulation, s.mock.StorageMock, &s.mock.Clock)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2019-04-24 21:52:08 +00:00
|
|
|
assert.NoError(s.T(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunRegulatorSuite(t *testing.T) {
|
|
|
|
s := new(RegulatorSuite)
|
|
|
|
suite.Run(t, s)
|
|
|
|
}
|
2020-01-26 21:42:05 +00:00
|
|
|
|
|
|
|
// This test checks that the regulator is disabled when configuration is set to 0.
|
|
|
|
func (s *RegulatorSuite) TestShouldHaveRegulatorDisabled() {
|
2022-03-06 05:47:40 +00:00
|
|
|
attemptsInDB := []model.AuthenticationAttempt{
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2020-01-26 21:42:05 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-31 * time.Second),
|
2020-01-26 21:42:05 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2020-01-26 21:42:05 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-34 * time.Second),
|
2020-01-26 21:42:05 +00:00
|
|
|
},
|
2020-04-09 01:05:17 +00:00
|
|
|
{
|
2020-01-26 21:42:05 +00:00
|
|
|
Username: "john",
|
|
|
|
Successful: false,
|
2023-05-24 12:33:05 +00:00
|
|
|
Time: s.mock.Clock.Now().Add(-36 * time.Second),
|
2020-01-26 21:42:05 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
s.mock.StorageMock.EXPECT().
|
|
|
|
LoadAuthenticationLogs(s.mock.Ctx, gomock.Eq("john"), gomock.Any(), gomock.Eq(10), gomock.Eq(0)).
|
2020-01-26 21:42:05 +00:00
|
|
|
Return(attemptsInDB, nil)
|
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Check Disabled Functionality.
|
2023-01-26 02:23:47 +00:00
|
|
|
config := schema.Regulation{
|
2020-01-26 21:42:05 +00:00
|
|
|
MaxRetries: 0,
|
2022-03-02 06:40:26 +00:00
|
|
|
FindTime: time.Second * 180,
|
|
|
|
BanTime: time.Second * 180,
|
2020-01-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator := regulation.NewRegulator(config, s.mock.StorageMock, &s.mock.Clock)
|
|
|
|
_, err := regulator.Regulate(s.mock.Ctx, "john")
|
2020-01-26 21:42:05 +00:00
|
|
|
assert.NoError(s.T(), err)
|
|
|
|
|
2022-01-31 05:25:15 +00:00
|
|
|
// Check Enabled Functionality.
|
2023-01-26 02:23:47 +00:00
|
|
|
config = schema.Regulation{
|
2020-01-26 21:42:05 +00:00
|
|
|
MaxRetries: 1,
|
2022-03-02 06:40:26 +00:00
|
|
|
FindTime: time.Second * 180,
|
|
|
|
BanTime: time.Second * 180,
|
2020-01-26 21:42:05 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 12:33:05 +00:00
|
|
|
regulator = regulation.NewRegulator(config, s.mock.StorageMock, &s.mock.Clock)
|
|
|
|
_, err = regulator.Regulate(s.mock.Ctx, "john")
|
2020-01-26 21:42:05 +00:00
|
|
|
assert.Equal(s.T(), regulation.ErrUserIsBanned, err)
|
|
|
|
}
|