2019-11-25 03:27:59 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserPreferencesScenario struct {
|
2021-11-05 20:14:42 +07:00
|
|
|
*RodSuite
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewUserPreferencesScenario() *UserPreferencesScenario {
|
|
|
|
return &UserPreferencesScenario{
|
2021-11-05 20:14:42 +07:00
|
|
|
RodSuite: new(RodSuite),
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *UserPreferencesScenario) 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 *UserPreferencesScenario) 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 *UserPreferencesScenario) 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 *UserPreferencesScenario) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *UserPreferencesScenario) TestShouldRememberLastUsed2FAMethod() {
|
2021-11-05 20:14:42 +07:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
|
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2022-01-31 12:25:15 +07:00
|
|
|
// Authenticate.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2022-01-31 12:25:15 +07:00
|
|
|
// Then switch to push notification method.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doChangeMethod(s.T(), s.Context(ctx), "push-notification")
|
2022-04-07 12:33:53 +07:00
|
|
|
s.WaitElementLocatedByID(s.T(), s.Context(ctx), "push-notification-method")
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
// Switch context to clean up state in portal.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
// Then go back to portal.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), GetLoginBaseURL())
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
// And check the latest method is still used.
|
2022-04-07 12:33:53 +07:00
|
|
|
s.WaitElementLocatedByID(s.T(), s.Context(ctx), "push-notification-method")
|
2022-01-31 12:25:15 +07:00
|
|
|
// Meaning the authentication is successful.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
|
|
|
|
// Logout the user and see what user 'harry' sees.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doLogout(s.T(), s.Context(ctx))
|
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "harry", "password", false, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2022-04-07 12:33:53 +07:00
|
|
|
s.WaitElementLocatedByID(s.T(), s.Context(ctx), "one-time-password-method")
|
2020-02-05 04:18:02 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doLogout(s.T(), s.Context(ctx))
|
|
|
|
s.verifyIsFirstFactorPage(s.T(), s.Context(ctx))
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2022-01-31 12:25:15 +07:00
|
|
|
// Then log back as previous user and verify the push notification is still the default method.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
2022-04-07 12:33:53 +07:00
|
|
|
s.WaitElementLocatedByID(s.T(), s.Context(ctx), "push-notification-method")
|
2021-11-05 20:14:42 +07:00
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
2020-02-05 04:18:02 +07:00
|
|
|
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doLogout(s.T(), s.Context(ctx))
|
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
2019-11-25 03:27:59 +07:00
|
|
|
|
2022-01-31 12:25:15 +07:00
|
|
|
// Eventually restore the default method.
|
2021-11-05 20:14:42 +07:00
|
|
|
s.doChangeMethod(s.T(), s.Context(ctx), "one-time-password")
|
2022-04-07 12:33:53 +07:00
|
|
|
s.WaitElementLocatedByID(s.T(), s.Context(ctx), "one-time-password-method")
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserPreferencesScenario(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, NewUserPreferencesScenario())
|
|
|
|
}
|