mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
b12528a65c
* This change provides the TOTP secret which allows users to copy and utilise for password managers and other applications. * Hide TextField if secret isn't present * This ensure that the TextField is removed on a page or if there is no secret present. * Add multiple buttons and set default value to OTP URL * Remove inline icon and add icons under text field which allow copying of the secret key and the whole OTP URL. * Fix integration tests * Add notifications on click for secret buttons * Also remove autoFocus on TextField so a user can identify that the full OTP URL is in focus.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package suites
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/pquerna/otp/totp"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func (wds *WebDriverSession) doRegisterTOTP(ctx context.Context, t *testing.T) string {
|
|
err := wds.WaitElementLocatedByID(ctx, t, "register-link").Click()
|
|
require.NoError(t, err)
|
|
wds.verifyMailNotificationDisplayed(ctx, t)
|
|
link := doGetLinkFromLastMail(t)
|
|
wds.doVisit(t, link)
|
|
secretURL, err := wds.WaitElementLocatedByID(ctx, t, "secret-url").GetAttribute("value")
|
|
assert.NoError(t, err)
|
|
|
|
secret := secretURL[strings.LastIndex(secretURL, "=")+1:]
|
|
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++ {
|
|
err := inputs[i].SendKeys(string(code[i]))
|
|
require.NoError(t, err)
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|