2020-02-05 04:18:02 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
type OneFactorOnlySuite struct {
|
2020-02-05 04:18:02 +07:00
|
|
|
suite.Suite
|
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
type OneFactorOnlyWebSuite struct {
|
2020-02-05 04:18:02 +07:00
|
|
|
*SeleniumSuite
|
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
func NewOneFactorOnlyWebSuite() *OneFactorOnlyWebSuite {
|
|
|
|
return &OneFactorOnlyWebSuite{SeleniumSuite: new(SeleniumSuite)}
|
2020-02-05 04:18:02 +07:00
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
func (s *OneFactorOnlyWebSuite) SetupSuite() {
|
2020-02-05 04:18:02 +07:00
|
|
|
wds, err := StartWebDriver()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
s.WebDriverSession = wds
|
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
func (s *OneFactorOnlyWebSuite) TearDownSuite() {
|
2020-02-05 04:18:02 +07:00
|
|
|
err := s.WebDriverSession.Stop()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
func (s *OneFactorOnlyWebSuite) SetupTest() {
|
2020-02-05 04:18:02 +07:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLogout(ctx, s.T())
|
|
|
|
}
|
|
|
|
|
|
|
|
// No target url is provided, then the user should be redirect to the default url.
|
2020-03-06 07:31:09 +07:00
|
|
|
func (s *OneFactorOnlyWebSuite) TestShouldRedirectUserToDefaultURL() {
|
2020-02-05 04:18:02 +07:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "")
|
|
|
|
s.verifyURLIs(ctx, s.T(), HomeBaseURL+"/")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unsafe URL is provided, then the user should be redirect to the default url.
|
2020-03-06 07:31:09 +07:00
|
|
|
func (s *OneFactorOnlyWebSuite) TestShouldRedirectUserToDefaultURLWhenURLIsUnsafe() {
|
2020-02-05 04:18:02 +07:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "http://unsafe.local")
|
|
|
|
s.verifyURLIs(ctx, s.T(), HomeBaseURL+"/")
|
|
|
|
}
|
|
|
|
|
|
|
|
// When use logged in and visit the portal again, she gets redirect to the authenticated view.
|
2020-03-06 07:31:09 +07:00
|
|
|
func (s *OneFactorOnlyWebSuite) TestShouldDisplayAuthenticatedView() {
|
2020-02-05 04:18:02 +07:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, "http://unsafe.local")
|
|
|
|
s.verifyURLIs(ctx, s.T(), HomeBaseURL+"/")
|
2020-05-27 18:55:44 +07:00
|
|
|
s.doVisit(s.T(), GetLoginBaseURL())
|
2020-02-05 04:18:02 +07:00
|
|
|
s.verifyIsAuthenticatedPage(ctx, s.T())
|
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
func (s *OneFactorOnlySuite) TestWeb() {
|
|
|
|
suite.Run(s.T(), NewOneFactorOnlyWebSuite())
|
2020-02-05 04:18:02 +07:00
|
|
|
}
|
|
|
|
|
2020-03-06 07:31:09 +07:00
|
|
|
func TestOneFactorOnlySuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(OneFactorOnlySuite))
|
2020-02-05 04:18:02 +07:00
|
|
|
}
|