2019-11-25 03:27:59 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-12-16 08:47:31 +07:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-11-25 03:27:59 +07:00
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type RegulationScenario struct {
|
2021-11-05 20:14:42 +07:00
|
|
|
*RodSuite
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewRegulationScenario() *RegulationScenario {
|
|
|
|
return &RegulationScenario{
|
2021-11-05 20:14:42 +07:00
|
|
|
RodSuite: new(RodSuite),
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulationScenario) SetupSuite() {
|
2021-11-05 20:14:42 +07:00
|
|
|
browser, err := StartRod()
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.RodSession = browser
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulationScenario) TearDownSuite() {
|
2021-11-05 20:14:42 +07:00
|
|
|
err := s.RodSession.Stop()
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulationScenario) SetupTest() {
|
2021-11-05 20:14:42 +07:00
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
|
|
|
}
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
func (s *RegulationScenario) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RegulationScenario) TestShouldBanUserAfterTooManyAttempt() {
|
2020-05-21 05:03:15 +07:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
2021-11-05 20:14:42 +07:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doVisitLoginPage(s.T(), s.Context(ctx), "")
|
|
|
|
s.doFillLoginPageAndClick(s.T(), s.Context(ctx), "john", "bad-password", false)
|
|
|
|
s.verifyNotificationDisplayed(s.T(), s.Context(ctx), "Incorrect username or password.")
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
for i := 0; i < 3; i++ {
|
2022-04-07 12:33:53 +07:00
|
|
|
err := s.WaitElementLocatedByID(s.T(), s.Context(ctx), "password-textfield").Input("bad-password")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(s.T(), err)
|
2022-04-07 12:33:53 +07:00
|
|
|
err = s.WaitElementLocatedByID(s.T(), s.Context(ctx), "sign-in-button").Click("left")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(s.T(), err)
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
2022-01-31 12:25:15 +07:00
|
|
|
// Enter the correct password and test the regulation lock out.
|
2022-04-07 12:33:53 +07:00
|
|
|
err := s.WaitElementLocatedByID(s.T(), s.Context(ctx), "password-textfield").Input("password")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(s.T(), err)
|
2022-04-07 12:33:53 +07:00
|
|
|
err = s.WaitElementLocatedByID(s.T(), s.Context(ctx), "sign-in-button").Click("left")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(s.T(), err)
|
2021-11-05 20:14:42 +07:00
|
|
|
s.verifyNotificationDisplayed(s.T(), s.Context(ctx), "Incorrect username or password.")
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.verifyIsFirstFactorPage(s.T(), s.Context(ctx))
|
|
|
|
time.Sleep(10 * time.Second)
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2022-01-31 12:25:15 +07:00
|
|
|
// Enter the correct password and test a successful login.
|
2022-04-07 12:33:53 +07:00
|
|
|
err = s.WaitElementLocatedByID(s.T(), s.Context(ctx), "password-textfield").Input("password")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(s.T(), err)
|
2022-04-07 12:33:53 +07:00
|
|
|
err = s.WaitElementLocatedByID(s.T(), s.Context(ctx), "sign-in-button").Click("left")
|
2020-12-16 08:47:31 +07:00
|
|
|
require.NoError(s.T(), err)
|
2021-11-05 20:14:42 +07:00
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlacklistingScenario(t *testing.T) {
|
2021-03-14 14:08:26 +07:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping suite test in short mode")
|
|
|
|
}
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
suite.Run(t, NewRegulationScenario())
|
|
|
|
}
|