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 {
|
2019-11-02 14:32:58 +00:00
|
|
|
*SeleniumSuite
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func NewDuoPushWebDriverSuite() *DuoPushWebDriverSuite {
|
|
|
|
return &DuoPushWebDriverSuite{SeleniumSuite: new(SeleniumSuite)}
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) SetupSuite() {
|
2019-11-24 20:27:59 +00:00
|
|
|
wds, err := StartWebDriver()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.WebDriverSession = wds
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) TearDownSuite() {
|
2019-11-24 20:27:59 +00:00
|
|
|
err := s.WebDriverSession.Stop()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:35:03 +00:00
|
|
|
func (s *DuoPushWebDriverSuite) SetupTest() {
|
2020-02-01 12:54:50 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
2019-11-30 16:49:52 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLogout(ctx, s.T())
|
|
|
|
}
|
|
|
|
|
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)
|
2019-11-24 20:27:59 +00:00
|
|
|
defer cancel()
|
|
|
|
|
2020-02-04 21:18:02 +00:00
|
|
|
s.doLogout(ctx, s.T())
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "")
|
|
|
|
s.verifyIsSecondFactorPage(ctx, s.T())
|
2019-11-24 20:27:59 +00:00
|
|
|
s.doChangeMethod(ctx, s.T(), "one-time-password")
|
2019-11-30 16:49:52 +00:00
|
|
|
s.WaitElementLocatedByID(ctx, s.T(), "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)
|
2019-11-24 20:27:59 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
ConfigureDuo(s.T(), Allow)
|
|
|
|
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "")
|
|
|
|
s.doChangeMethod(ctx, s.T(), "push-notification")
|
2020-02-04 21:18:02 +00:00
|
|
|
s.verifyIsHome(ctx, s.T())
|
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)
|
2019-11-24 20:27:59 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
ConfigureDuo(s.T(), Deny)
|
|
|
|
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "")
|
|
|
|
s.doChangeMethod(ctx, s.T(), "push-notification")
|
|
|
|
s.WaitElementLocatedByClassName(ctx, s.T(), "failure-icon")
|
|
|
|
}
|
|
|
|
|
2020-02-01 12:54:50 +00:00
|
|
|
type DuoPushDefaultRedirectionSuite struct {
|
|
|
|
*SeleniumSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDuoPushDefaultRedirectionSuite() *DuoPushDefaultRedirectionSuite {
|
|
|
|
return &DuoPushDefaultRedirectionSuite{SeleniumSuite: new(SeleniumSuite)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) SetupSuite() {
|
|
|
|
wds, err := StartWebDriver()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.WebDriverSession = wds
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) TearDownSuite() {
|
|
|
|
err := s.WebDriverSession.Stop()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) SetupTest() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLogout(ctx, s.T())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DuoPushDefaultRedirectionSuite) TestUserIsRedirectedToDefaultURL() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "")
|
|
|
|
s.doChangeMethod(ctx, s.T(), "push-notification")
|
|
|
|
s.verifyURLIs(ctx, s.T(), HomeBaseURL+"/")
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
suite.Run(t, NewDuoPushSuite())
|
2019-11-02 14:32:58 +00:00
|
|
|
}
|