authelia/internal/suites/suite_one_factor_default_policy_test.go
Clément Michaud d1d02d9eae
[FIX] Redirect to default URL after 1FA when default policy is one_factor. (#611)
* Redirect to default URL after 1FA when default policy is one_factor.

User is now redirected to the default redirection URL after 1FA if
the default policy is set to one_factor and there is no target URL
or if the target URL is unsafe.

Also, if the default policy is set to one_factor and the user is already
authenticated, if she visits the login portal, the 'already authenticated'
view is displayed with a logout button.

This fixes #581.

* Update users.yml

* Fix permissions issue causing suite test failure
2020-02-05 08:18:02 +11:00

85 lines
2.2 KiB
Go

package suites
import (
"context"
"log"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type OneFactorDefaultPolicySuite struct {
suite.Suite
}
type OneFactorDefaultPolicyWebSuite struct {
*SeleniumSuite
}
func NewOneFactorDefaultPolicyWebSuite() *OneFactorDefaultPolicyWebSuite {
return &OneFactorDefaultPolicyWebSuite{SeleniumSuite: new(SeleniumSuite)}
}
func (s *OneFactorDefaultPolicyWebSuite) SetupSuite() {
wds, err := StartWebDriver()
if err != nil {
log.Fatal(err)
}
s.WebDriverSession = wds
}
func (s *OneFactorDefaultPolicyWebSuite) TearDownSuite() {
err := s.WebDriverSession.Stop()
if err != nil {
log.Fatal(err)
}
}
func (s *OneFactorDefaultPolicyWebSuite) SetupTest() {
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.
func (s *OneFactorDefaultPolicyWebSuite) TestShouldRedirectUserToDefaultURL() {
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.
func (s *OneFactorDefaultPolicyWebSuite) TestShouldRedirectUserToDefaultURLWhenURLIsUnsafe() {
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.
func (s *OneFactorDefaultPolicyWebSuite) TestShouldDisplayAuthenticatedView() {
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+"/")
s.doVisit(s.T(), LoginBaseURL)
s.verifyIsAuthenticatedPage(ctx, s.T())
}
func (s *OneFactorDefaultPolicySuite) TestWeb() {
suite.Run(s.T(), NewOneFactorDefaultPolicyWebSuite())
}
func TestOneFactorDefaultPolicySuite(t *testing.T) {
suite.Run(t, new(OneFactorDefaultPolicySuite))
}