mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
54694c4fca
* [MISC] Ignore errcheck recommendations for legacy code Some of this is likely intended to stay how it is, some could use refactoring, for now we will mark is and ignore it from the linter to be potentially addressed in the future. * [MISC] Ensure files are gofmt-ed
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package suites
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/pquerna/otp/totp"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func (wds *WebDriverSession) doRegisterTOTP(ctx context.Context, t *testing.T) string {
|
|
wds.WaitElementLocatedByID(ctx, t, "register-link").Click() //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
|
|
wds.verifyMailNotificationDisplayed(ctx, t)
|
|
link := doGetLinkFromLastMail(t)
|
|
wds.doVisit(t, link)
|
|
secret, err := wds.WaitElementLocatedByID(ctx, t, "base32-secret").GetAttribute("value")
|
|
assert.NoError(t, err)
|
|
assert.NotEqual(t, "", secret)
|
|
assert.NotNil(t, secret)
|
|
return secret
|
|
}
|
|
|
|
func (wds *WebDriverSession) doEnterOTP(ctx context.Context, t *testing.T, code string) {
|
|
inputs := wds.WaitElementsLocatedByCSSSelector(ctx, t, "#otp-input input")
|
|
|
|
for i := 0; i < 6; i++ {
|
|
inputs[i].SendKeys(string(code[i])) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
|
|
}
|
|
}
|
|
|
|
func (wds *WebDriverSession) doValidateTOTP(ctx context.Context, t *testing.T, secret string) {
|
|
code, err := totp.GenerateCode(secret, time.Now())
|
|
assert.NoError(t, err)
|
|
wds.doEnterOTP(ctx, t, code)
|
|
}
|