mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
d82b46a3ec
* [FEATURE] Autofocus on authentication and OTP pages This change sets the input focus on the first factor authentication and OTP pages. The behaviour for the first factor authentication page has also been amended slightly, if an incorrect username or password is provided the password field will be cleared and set as the focus. One thing to note is that the OTP page does not focus on any re-rendering and this is because the component doesn't handle focusing. This means that the OTP input only is auto-focused when you first visit it, if you enter an incorrect OTP there will be no focus. Ideally we should be looking for a different library or writing a component for this ourselves in future. Closes #511. * Add TODO markers for potential refactor
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package suites
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type OneFactorSuite struct {
|
|
*SeleniumSuite
|
|
}
|
|
|
|
func NewOneFactorScenario() *OneFactorSuite {
|
|
return &OneFactorSuite{
|
|
SeleniumSuite: new(SeleniumSuite),
|
|
}
|
|
}
|
|
|
|
func (s *OneFactorSuite) SetupSuite() {
|
|
wds, err := StartWebDriver()
|
|
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
s.WebDriverSession = wds
|
|
}
|
|
|
|
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()
|
|
|
|
s.doLogout(ctx, s.T())
|
|
s.doVisit(s.T(), HomeBaseURL)
|
|
s.verifyIsHome(ctx, s.T())
|
|
}
|
|
|
|
func (s *OneFactorSuite) TestShouldAuthorizeSecretAfterOneFactor() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
targetURL := fmt.Sprintf("%s/secret.html", SingleFactorBaseURL)
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, targetURL)
|
|
s.verifySecretAuthorized(ctx, s.T())
|
|
}
|
|
|
|
func (s *OneFactorSuite) TestShouldRedirectToSecondFactor() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
targetURL := fmt.Sprintf("%s/secret.html", AdminBaseURL)
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "password", false, targetURL)
|
|
s.verifyIsSecondFactorPage(ctx, s.T())
|
|
}
|
|
|
|
func (s *OneFactorSuite) TestShouldDenyAccessOnBadPassword() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
|
|
targetURL := fmt.Sprintf("%s/secret.html", AdminBaseURL)
|
|
s.doLoginOneFactor(ctx, s.T(), "john", "bad-password", false, targetURL)
|
|
s.verifyIsFirstFactorPage(ctx, s.T())
|
|
s.verifyNotificationDisplayed(ctx, s.T(), "Incorrect username or password.")
|
|
}
|
|
|
|
func TestRunOneFactor(t *testing.T) {
|
|
suite.Run(t, NewOneFactorScenario())
|
|
}
|