mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
* [Buildkite] Introduce CI linting with golangci-lint and reviewdog * Initial pass of golangci-lint * Add gosimple (megacheck) recommendations * Add golint recommendations * [BUGFIX] Migrate authentication traces from v3 mongodb * Add deadcode recommendations * [BUGFIX] Fix ShortTimeouts suite when run in dev workflow * Add unused recommendations * Add unparam recommendations * Disable linting on unfixable errors instead of skipping files * Adjust nolint notation for unparam * Fix ineffectual assignment to err raised by linter. * Export environment variable in agent hook * Add ineffassign recommendations * Add staticcheck recommendations * Add gocyclo recommendations * Adjust ineffassign recommendations Co-authored-by: Clement Michaud <clement.michaud34@gmail.com>
59 lines
2.2 KiB
Go
59 lines
2.2 KiB
Go
package suites
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func (wds *WebDriverSession) doFillLoginPageAndClick(ctx context.Context, t *testing.T, username, password string, keepMeLoggedIn bool) {
|
|
usernameElement := wds.WaitElementLocatedByID(ctx, t, "username-textfield")
|
|
err := usernameElement.SendKeys(username)
|
|
require.NoError(t, err)
|
|
|
|
passwordElement := wds.WaitElementLocatedByID(ctx, t, "password-textfield")
|
|
err = passwordElement.SendKeys(password)
|
|
require.NoError(t, err)
|
|
|
|
if keepMeLoggedIn {
|
|
keepMeLoggedInElement := wds.WaitElementLocatedByID(ctx, t, "remember-checkbox")
|
|
err = keepMeLoggedInElement.Click()
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
buttonElement := wds.WaitElementLocatedByID(ctx, t, "sign-in-button")
|
|
err = buttonElement.Click()
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
// Login 1FA
|
|
func (wds *WebDriverSession) doLoginOneFactor(ctx context.Context, t *testing.T, username, password string, keepMeLoggedIn bool, targetURL string) {
|
|
wds.doVisitLoginPage(ctx, t, targetURL)
|
|
wds.doFillLoginPageAndClick(ctx, t, username, password, keepMeLoggedIn)
|
|
}
|
|
|
|
// Login 1FA and 2FA subsequently (must already be registered)
|
|
func (wds *WebDriverSession) doLoginTwoFactor(ctx context.Context, t *testing.T, username, password string, keepMeLoggedIn bool, otpSecret, targetURL string) {
|
|
wds.doLoginOneFactor(ctx, t, username, password, keepMeLoggedIn, targetURL)
|
|
wds.verifyIsSecondFactorPage(ctx, t)
|
|
wds.doValidateTOTP(ctx, t, otpSecret)
|
|
}
|
|
|
|
// Login 1FA and register 2FA.
|
|
func (wds *WebDriverSession) doLoginAndRegisterTOTP(ctx context.Context, t *testing.T, username, password string, keepMeLoggedIn bool) string {
|
|
wds.doLoginOneFactor(ctx, t, username, password, keepMeLoggedIn, "")
|
|
secret := wds.doRegisterTOTP(ctx, t)
|
|
wds.doVisit(t, LoginBaseURL)
|
|
wds.verifyIsSecondFactorPage(ctx, t)
|
|
return secret
|
|
}
|
|
|
|
// Register a user with TOTP, logout and then authenticate until TOTP-2FA.
|
|
func (wds *WebDriverSession) doRegisterAndLogin2FA(ctx context.Context, t *testing.T, username, password string, keepMeLoggedIn bool, targetURL string) string { //nolint:unparam
|
|
// Register TOTP secret and logout.
|
|
secret := wds.doRegisterThenLogout(ctx, t, username, password)
|
|
wds.doLoginTwoFactor(ctx, t, username, password, false, secret, targetURL)
|
|
return secret
|
|
}
|