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