2019-11-02 21:32:58 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OneFactorSuite struct {
|
|
|
|
*SeleniumSuite
|
|
|
|
}
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
func NewOneFactorScenario() *OneFactorSuite {
|
2019-11-02 21:32:58 +07:00
|
|
|
return &OneFactorSuite{
|
|
|
|
SeleniumSuite: new(SeleniumSuite),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *OneFactorSuite) SetupSuite() {
|
|
|
|
wds, err := StartWebDriver()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
s.WebDriverSession = wds
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *OneFactorSuite) TearDownSuite() {
|
|
|
|
err := s.WebDriverSession.Stop()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *OneFactorSuite) SetupTest() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
s.doLogout(ctx, s.T())
|
|
|
|
s.doVisit(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(ctx, s.T())
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *OneFactorSuite) TestShouldAuthorizeSecretAfterOneFactor() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
targetURL := fmt.Sprintf("%s/secret.html", SingleFactorBaseURL)
|
2019-11-25 03:27:59 +07:00
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, targetURL)
|
|
|
|
s.verifySecretAuthorized(ctx, s.T())
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *OneFactorSuite) TestShouldRedirectToSecondFactor() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
targetURL := fmt.Sprintf("%s/secret.html", AdminBaseURL)
|
2019-11-25 03:27:59 +07:00
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, targetURL)
|
|
|
|
s.verifyIsSecondFactorPage(ctx, s.T())
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *OneFactorSuite) TestShouldDenyAccessOnBadPassword() {
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
targetURL := fmt.Sprintf("%s/secret.html", AdminBaseURL)
|
2019-11-25 03:27:59 +07:00
|
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "bad-password", false, targetURL)
|
|
|
|
s.verifyIsFirstFactorPage(ctx, s.T())
|
2020-04-01 06:27:54 +07:00
|
|
|
s.verifyNotificationDisplayed(ctx, s.T(), "Incorrect username or password.")
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRunOneFactor(t *testing.T) {
|
2019-11-25 03:27:59 +07:00
|
|
|
suite.Run(t, NewOneFactorScenario())
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|