authelia/internal/suites/action_totp.go
Amir Zarrinkafsh b989c1b169
[MISC] Refactor and address most errcheck linter ignores (#1511)
* [MISC] Refactor and address most errcheck linter ignores

This is mostly a quality of life change.
When we first implemented the errcheck linter we ignored a number of items in our legacy codebase with intent to revisit down the track.

* Handle errors for regulation marks and remove unnecessary logging
2020-12-16 12:47:31 +11:00

41 lines
1.1 KiB
Go

package suites
import (
"context"
"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)
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++ {
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)
}