authelia/internal/suites/scenario_regulation_test.go
Amir Zarrinkafsh de2c5836fd
[Buildkite] Introduce CI linting with golangci-lint and reviewdog (#832)
* [Buildkite] Introduce CI linting with golangci-lint and reviewdog

* Initial pass of golangci-lint

* Add gosimple (megacheck) recommendations

* Add golint recommendations

* [BUGFIX] Migrate authentication traces from v3 mongodb

* Add deadcode recommendations

* [BUGFIX] Fix ShortTimeouts suite when run in dev workflow

* Add unused recommendations

* Add unparam recommendations

* Disable linting on unfixable errors instead of skipping files

* Adjust nolint notation for unparam

* Fix ineffectual assignment to err raised by linter.

* Export environment variable in agent hook

* Add ineffassign recommendations

* Add staticcheck recommendations

* Add gocyclo recommendations

* Adjust ineffassign recommendations

Co-authored-by: Clement Michaud <clement.michaud34@gmail.com>
2020-04-09 11:05:17 +10:00

81 lines
2.0 KiB
Go

package suites
import (
"context"
"log"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type RegulationScenario struct {
*SeleniumSuite
}
func NewRegulationScenario() *RegulationScenario {
return &RegulationScenario{
SeleniumSuite: new(SeleniumSuite),
}
}
func (s *RegulationScenario) SetupSuite() {
wds, err := StartWebDriver()
if err != nil {
log.Fatal(err)
}
s.WebDriverSession = wds
}
func (s *RegulationScenario) TearDownSuite() {
err := s.WebDriverSession.Stop()
if err != nil {
log.Fatal(err)
}
}
func (s *RegulationScenario) SetupTest() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
s.doLogout(ctx, s.T())
s.doVisit(s.T(), HomeBaseURL)
s.verifyIsHome(ctx, s.T())
}
func (s *RegulationScenario) TestShouldBanUserAfterTooManyAttempt() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
s.doVisitLoginPage(ctx, s.T(), "")
s.doFillLoginPageAndClick(ctx, s.T(), "john", "bad-password", false)
s.verifyNotificationDisplayed(ctx, s.T(), "Incorrect username or password.")
for i := 0; i < 3; i++ {
s.WaitElementLocatedByID(ctx, s.T(), "password-textfield").SendKeys("bad-password")
s.WaitElementLocatedByID(ctx, s.T(), "sign-in-button").Click()
time.Sleep(1 * time.Second)
}
// Enter the correct password and test the regulation lock out
s.WaitElementLocatedByID(ctx, s.T(), "password-textfield").SendKeys("password")
s.WaitElementLocatedByID(ctx, s.T(), "sign-in-button").Click()
s.verifyNotificationDisplayed(ctx, s.T(), "Incorrect username or password.")
time.Sleep(1 * time.Second)
s.verifyIsFirstFactorPage(ctx, s.T())
time.Sleep(9 * time.Second)
// Enter the correct password and test a successful login
s.WaitElementLocatedByID(ctx, s.T(), "password-textfield").SendKeys("password")
s.WaitElementLocatedByID(ctx, s.T(), "sign-in-button").Click()
s.verifyIsSecondFactorPage(ctx, s.T())
}
func TestBlacklistingScenario(t *testing.T) {
suite.Run(t, NewRegulationScenario())
}