2020-02-04 21:18:02 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-08-02 06:15:38 +00:00
|
|
|
"fmt"
|
2020-02-04 21:18:02 +00:00
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
2020-03-06 00:31:09 +00:00
|
|
|
type OneFactorOnlySuite struct {
|
2021-11-05 13:14:42 +00:00
|
|
|
*RodSuite
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
func NewOneFactorOnlySuite() *OneFactorOnlySuite {
|
|
|
|
return &OneFactorOnlySuite{
|
|
|
|
RodSuite: NewRodSuite(oneFactorOnlySuiteName),
|
|
|
|
}
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) SetupSuite() {
|
|
|
|
s.BaseSuite.SetupSuite()
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
browser, err := StartRod()
|
2020-02-04 21:18:02 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-05 13:14:42 +00:00
|
|
|
s.RodSession = browser
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) TearDownSuite() {
|
2021-11-05 13:14:42 +00:00
|
|
|
err := s.RodSession.Stop()
|
2020-02-04 21:18:02 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) SetupTest() {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.Page = s.doCreateTab(s.T(), HomeBaseURL)
|
|
|
|
s.verifyIsHome(s.T(), s.Page)
|
|
|
|
}
|
2020-02-04 21:18:02 +00:00
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) TearDownTest() {
|
2021-11-05 13:14:42 +00:00
|
|
|
s.collectCoverage(s.Page)
|
|
|
|
s.MustClose()
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No target url is provided, then the user should be redirect to the default url.
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) TestShouldRedirectUserToDefaultURL() {
|
2020-02-04 21:18:02 +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)
|
|
|
|
}()
|
2020-02-04 21:18:02 +00:00
|
|
|
|
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.verifyIsHome(s.T(), s.Context(ctx))
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unsafe URL is provided, then the user should be redirect to the default url.
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) TestShouldRedirectUserToDefaultURLWhenURLIsUnsafe() {
|
2020-02-04 21:18:02 +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)
|
|
|
|
}()
|
2020-02-04 21:18:02 +00:00
|
|
|
|
2023-01-12 10:57:44 +00:00
|
|
|
s.doLoginOneFactor(s.T(), s.Context(ctx), "john", "password", false, BaseDomain, "http://unsafe.local")
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifyIsHome(s.T(), s.Context(ctx))
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// When use logged in and visit the portal again, she gets redirect to the authenticated view.
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) TestShouldDisplayAuthenticatedView() {
|
2020-02-04 21:18:02 +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)
|
|
|
|
}()
|
|
|
|
|
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.verifyIsHome(s.T(), s.Context(ctx))
|
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.verifyIsAuthenticatedPage(s.T(), s.Context(ctx))
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) TestShouldRedirectAlreadyAuthenticatedUser() {
|
2021-08-02 06:15:38 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
2021-11-05 13:14:42 +00:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2021-08-02 06:15:38 +00:00
|
|
|
|
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.verifyIsHome(s.T(), s.Context(ctx))
|
2021-08-02 06:15:38 +00:00
|
|
|
|
2023-01-12 10:57:44 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), fmt.Sprintf("%s?rd=https://singlefactor.example.com:8080/secret.html", GetLoginBaseURL(BaseDomain)))
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifySecretAuthorized(s.T(), s.Context(ctx))
|
|
|
|
s.verifyURLIs(s.T(), s.Context(ctx), "https://singlefactor.example.com:8080/secret.html")
|
2021-08-02 06:15:38 +00:00
|
|
|
}
|
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
func (s *OneFactorOnlySuite) TestShouldNotRedirectAlreadyAuthenticatedUserToUnsafeURL() {
|
2021-08-02 06:15:38 +00:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
2021-11-05 13:14:42 +00:00
|
|
|
defer func() {
|
|
|
|
cancel()
|
|
|
|
s.collectScreenshot(ctx.Err(), s.Page)
|
|
|
|
}()
|
2021-08-02 06:15:38 +00:00
|
|
|
|
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.verifyIsHome(s.T(), s.Context(ctx))
|
2021-08-02 06:15:38 +00:00
|
|
|
|
|
|
|
// Visit the login page and wait for redirection to 2FA page with success icon displayed.
|
2023-01-12 10:57:44 +00:00
|
|
|
s.doVisit(s.T(), s.Context(ctx), fmt.Sprintf("%s?rd=https://secure.example.local:8080", GetLoginBaseURL(BaseDomain)))
|
2021-11-05 13:14:42 +00:00
|
|
|
s.verifyNotificationDisplayed(s.T(), s.Context(ctx), "Redirection was determined to be unsafe and aborted. Ensure the redirection URL is correct.")
|
2021-08-02 06:15:38 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 00:31:09 +00:00
|
|
|
func TestOneFactorOnlySuite(t *testing.T) {
|
2021-03-14 07:08:26 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping suite test in short mode")
|
|
|
|
}
|
|
|
|
|
2023-01-25 04:11:05 +00:00
|
|
|
suite.Run(t, NewOneFactorOnlySuite())
|
2020-02-04 21:18:02 +00:00
|
|
|
}
|