2019-11-02 21:32:58 +07:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-11-25 03:27:59 +07:00
|
|
|
"testing"
|
2019-11-02 21:32:58 +07:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/pquerna/otp/totp"
|
2019-11-25 03:27:59 +07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-11-02 21:32:58 +07:00
|
|
|
)
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
func (wds *WebDriverSession) doRegisterTOTP(ctx context.Context, t *testing.T) string {
|
2020-04-22 10:33:14 +07:00
|
|
|
wds.WaitElementLocatedByID(ctx, t, "register-link").Click() //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
|
2019-11-25 03:27:59 +07:00
|
|
|
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)
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2019-11-02 21:32:58 +07:00
|
|
|
return secret
|
|
|
|
}
|
|
|
|
|
2019-11-25 03:27:59 +07:00
|
|
|
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++ {
|
2020-04-22 10:33:14 +07:00
|
|
|
inputs[i].SendKeys(string(code[i])) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
|
2019-11-25 03:27:59 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wds *WebDriverSession) doValidateTOTP(ctx context.Context, t *testing.T, secret string) {
|
2019-11-02 21:32:58 +07:00
|
|
|
code, err := totp.GenerateCode(secret, time.Now())
|
2019-11-25 03:27:59 +07:00
|
|
|
assert.NoError(t, err)
|
|
|
|
wds.doEnterOTP(ctx, t, code)
|
2019-11-02 21:32:58 +07:00
|
|
|
}
|