2019-11-24 20:27:59 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-12-16 01:47:31 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-24 20:27:59 +00:00
|
|
|
"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() {
|
2020-05-20 22:03:15 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
2019-11-24 20:27:59 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doVisitLoginPage(ctx, s.T(), "")
|
|
|
|
s.doFillLoginPageAndClick(ctx, s.T(), "john", "bad-password", false)
|
2020-03-31 23:27:54 +00:00
|
|
|
s.verifyNotificationDisplayed(ctx, s.T(), "Incorrect username or password.")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
for i := 0; i < 3; i++ {
|
2020-12-16 01:47:31 +00:00
|
|
|
err := s.WaitElementLocatedByID(ctx, s.T(), "password-textfield").SendKeys("bad-password")
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = s.WaitElementLocatedByID(ctx, s.T(), "sign-in-button").Click()
|
|
|
|
require.NoError(s.T(), err)
|
2019-11-30 16:49:52 +00:00
|
|
|
time.Sleep(1 * time.Second)
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 23:27:54 +00:00
|
|
|
// Enter the correct password and test the regulation lock out
|
2020-12-16 01:47:31 +00:00
|
|
|
err := s.WaitElementLocatedByID(ctx, s.T(), "password-textfield").SendKeys("password")
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = s.WaitElementLocatedByID(ctx, s.T(), "sign-in-button").Click()
|
|
|
|
require.NoError(s.T(), err)
|
2020-03-31 23:27:54 +00:00
|
|
|
s.verifyNotificationDisplayed(ctx, s.T(), "Incorrect username or password.")
|
2019-11-24 20:27:59 +00:00
|
|
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
s.verifyIsFirstFactorPage(ctx, s.T())
|
|
|
|
time.Sleep(9 * time.Second)
|
|
|
|
|
2020-03-31 23:27:54 +00:00
|
|
|
// Enter the correct password and test a successful login
|
2020-12-16 01:47:31 +00:00
|
|
|
err = s.WaitElementLocatedByID(ctx, s.T(), "password-textfield").SendKeys("password")
|
|
|
|
require.NoError(s.T(), err)
|
|
|
|
err = s.WaitElementLocatedByID(ctx, s.T(), "sign-in-button").Click()
|
|
|
|
require.NoError(s.T(), err)
|
2019-11-24 20:27:59 +00:00
|
|
|
s.verifyIsSecondFactorPage(ctx, s.T())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlacklistingScenario(t *testing.T) {
|
|
|
|
suite.Run(t, NewRegulationScenario())
|
|
|
|
}
|