mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
26 lines
712 B
Go
26 lines
712 B
Go
package suites
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/pquerna/otp/totp"
|
|
)
|
|
|
|
func doRegisterTOTP(ctx context.Context, s *SeleniumSuite) string {
|
|
WaitElementLocatedByClassName(ctx, s, "register-totp").Click()
|
|
verifyBodyContains(ctx, s, "Please check your e-mails")
|
|
link := doGetLinkFromLastMail(s)
|
|
doVisit(s, link)
|
|
secret, err := WaitElementLocatedByClassName(ctx, s, "base32-secret").Text()
|
|
s.Assert().NoError(err)
|
|
return secret
|
|
}
|
|
|
|
func doValidateTOTP(ctx context.Context, s *SeleniumSuite, secret string) {
|
|
code, err := totp.GenerateCode(secret, time.Now())
|
|
s.Assert().NoError(err)
|
|
WaitElementLocatedByID(ctx, s, "totp-token").SendKeys(code)
|
|
WaitElementLocatedByID(ctx, s, "totp-button").Click()
|
|
}
|