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