2019-11-02 14:32:58 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
2019-11-24 20:27:59 +00:00
|
|
|
"context"
|
|
|
|
"log"
|
2019-11-02 14:32:58 +00:00
|
|
|
"testing"
|
2019-11-24 20:27:59 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
2019-11-02 14:32:58 +00:00
|
|
|
)
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
type DuoPushWebDriverSuite struct {
|
2021-11-05 13:14:42 +00:00
|
|
|
*RodSuite
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func NewDuoPushWebDriverSuite() *DuoPushWebDriverSuite {
|
2021-11-05 13:14:42 +00:00
|
|
|
return &DuoPushWebDriverSuite{RodSuite: new(RodSuite)}
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) 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
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) SetupTest() {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
2019-11-30 16:49:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) TearDownTest() {
|
2020-02-01 12:54:50 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
2021-11-05 13:14:42 +00:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
|
|
|
}()
|
2019-11-24 20:27:59 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLogout(s.T(), s.Context(ctx))
|
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.verifyIsSecondFactorPage(s.T(), s.Context(ctx))
|
|
|
|
s.doChangeMethod(s.T(), s.Context(ctx), "one-time-password")
|
|
|
|
s.WaitElementLocatedByCSSSelector(s.T(), s.Context(ctx), "one-time-password-method")
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) TestShouldSucceedAuthentication() {
|
2019-11-30 16:49:52 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*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
|
|
|
|
|
|
|
ConfigureDuo(s.T(), Allow)
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.doChangeMethod(s.T(), s.Context(ctx), "push-notification")
|
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) TestShouldFailAuthentication() {
|
2019-11-30 16:49:52 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*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
|
|
|
|
|
|
|
ConfigureDuo(s.T(), Deny)
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.doChangeMethod(s.T(), s.Context(ctx), "push-notification")
|
|
|
|
s.WaitElementLocatedByClassName(s.T(), s.Context(ctx), "failure-icon")
|
2019-11-24 20:27:59 +00:00
|
|
|
}
|
|
|
|
|
2020-02-01 12:54:50 +00:00
|
|
|
type DuoPushDefaultRedirectionSuite struct {
|
2021-11-05 13:14:42 +00:00
|
|
|
*RodSuite
|
2020-02-01 12:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDuoPushDefaultRedirectionSuite() *DuoPushDefaultRedirectionSuite {
|
2021-11-05 13:14:42 +00:00
|
|
|
return &DuoPushDefaultRedirectionSuite{RodSuite: new(RodSuite)}
|
2020-02-01 12:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) SetupSuite() {
|
2021-11-05 13:14:42 +00:00
|
|
|
browser, err := StartRod()
|
2020-02-01 12:54:50 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.RodSession = browser
|
2020-02-01 12:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) TearDownSuite() {
|
2021-11-05 13:14:42 +00:00
|
|
|
err := s.RodSession.Stop()
|
2020-02-01 12:54:50 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) SetupTest() {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
|
|
|
}
|
2020-02-01 12:54:50 +00:00
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
func (s *DuoPushDefaultRedirectionSuite) TearDownTest() {
|
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2020-02-01 12:54:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) TestUserIsRedirectedToDefaultURL() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
2021-11-05 13:14:42 +00:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
|
|
|
|
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, "")
|
|
|
|
s.doChangeMethod(s.T(), s.Context(ctx), "push-notification")
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
2020-02-01 12:54:50 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
type DuoPushSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDuoPushSuite() *DuoPushSuite {
|
|
|
|
return &DuoPushSuite{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushSuite) TestDuoPushWebDriverSuite() {
|
|
|
|
suite.Run(s.T(), NewDuoPushWebDriverSuite())
|
|
|
|
}
|
|
|
|
|
2020-02-01 12:54:50 +00:00
|
|
|
func (s *DuoPushSuite) TestDuoPushRedirectionURLSuite() {
|
|
|
|
suite.Run(s.T(), NewDuoPushDefaultRedirectionSuite())
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushSuite) TestAvailableMethodsScenario() {
|
|
|
|
suite.Run(s.T(), NewAvailableMethodsScenario([]string{
|
2021-02-12 05:59:42 +00:00
|
|
|
"TIME-BASED ONE-TIME PASSWORD",
|
2019-11-24 20:27:59 +00:00
|
|
|
"PUSH NOTIFICATION",
|
|
|
|
}))
|
2019-12-05 21:35:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushSuite) TestUserPreferencesScenario() {
|
|
|
|
suite.Run(s.T(), NewUserPreferencesScenario())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDuoPushSuite(t *testing.T) {
|
2021-03-14 07:08:26 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping suite test in short mode")
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
suite.Run(t, NewDuoPushSuite())
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|