authelia/test/suites/simple/scenarii/RegisterTotp.ts

51 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-02-10 05:20:37 +07:00
import SeleniumWebdriver, { WebDriver } from "selenium-webdriver";
import Assert from 'assert';
import LoginAndRegisterTotp from '../../../helpers/LoginAndRegisterTotp';
2019-02-14 05:31:12 +07:00
import { StartDriver, StopDriver } from "../../../helpers/context/WithDriver";
/**
* Given the user logs in as john,
* When he register a TOTP token,
* Then he reach a page containing the secret as string an qrcode
*/
export default function() {
describe('successfully login as john', function() {
2019-02-14 05:31:12 +07:00
this.timeout(10000);
beforeEach(async function() {
this.driver = await StartDriver();
await LoginAndRegisterTotp(this.driver, "john", "password", true);
2019-02-14 05:31:12 +07:00
});
afterEach(async function() {
await StopDriver(this.driver);
})
it("should see generated qrcode", async function() {
await this.driver.wait(
SeleniumWebdriver.until.elementLocated(
SeleniumWebdriver.By.className("qrcode")),
5000);
});
it("should see generated secret", async function() {
await this.driver.wait(
SeleniumWebdriver.until.elementLocated(
SeleniumWebdriver.By.className("base32-secret")),
5000);
});
2019-02-10 05:20:37 +07:00
it("should have user and issuer in otp url", async function() {
const el = await (this.driver as WebDriver).wait(
SeleniumWebdriver.until.elementLocated(
SeleniumWebdriver.By.className('otpauth-secret')), 5000);
const otpauthUrl = await el.getAttribute('innerText');
const label = 'john';
const issuer = 'example.com';
Assert(new RegExp(`^otpauth://totp/${label}\\?secret=[A-Z0-9]+&issuer=${issuer}$`).test(otpauthUrl));
})
});
};