2019-01-30 15:50:49 +00:00
|
|
|
import FillLoginPageWithUserAndPasswordAndClick from '../../../helpers/FillLoginPageAndClick';
|
|
|
|
import ValidateTotp from '../../../helpers/ValidateTotp';
|
2019-02-12 22:23:43 +00:00
|
|
|
import VerifySecretObserved from "../../../helpers/assertions/VerifySecretObserved";
|
2019-01-30 15:50:49 +00:00
|
|
|
import LoginAndRegisterTotp from '../../../helpers/LoginAndRegisterTotp';
|
|
|
|
import { AUTHENTICATION_TOTP_FAILED } from '../../../../shared/UserMessages';
|
2019-02-12 22:41:19 +00:00
|
|
|
import VisitPageAndWaitUrlIs from '../../../helpers/behaviors/VisitPageAndWaitUrlIs';
|
2019-02-13 22:08:28 +00:00
|
|
|
import VerifyNotificationDisplayed from '../../../helpers/assertions/VerifyNotificationDisplayed';
|
2019-02-13 22:10:00 +00:00
|
|
|
import VerifyUrlIs from '../../../helpers/assertions/VerifyUrlIs';
|
2019-02-13 22:31:12 +00:00
|
|
|
import { StartDriver, StopDriver } from '../../../helpers/context/WithDriver';
|
2019-01-30 15:47:03 +00:00
|
|
|
|
|
|
|
export default function() {
|
|
|
|
/**
|
|
|
|
* Given john has registered a TOTP secret,
|
|
|
|
* When he validates the TOTP second factor,
|
|
|
|
* Then he has access to secret page.
|
|
|
|
*/
|
|
|
|
describe('Successfully pass second factor with TOTP', function() {
|
2019-02-13 22:31:12 +00:00
|
|
|
before(async function() {
|
|
|
|
this.driver = await StartDriver();
|
2019-02-13 23:27:43 +00:00
|
|
|
const secret = await LoginAndRegisterTotp(this.driver, "john", "password", true);
|
2019-01-30 15:47:03 +00:00
|
|
|
if (!secret) throw new Error('No secret!');
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
await VisitPageAndWaitUrlIs(this.driver, "https://login.example.com:8080/#/?rd=https://admin.example.com:8080/secret.html");
|
2019-01-30 15:47:03 +00:00
|
|
|
await FillLoginPageWithUserAndPasswordAndClick(this.driver, 'john', 'password');
|
|
|
|
await ValidateTotp(this.driver, secret);
|
2019-02-13 22:31:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(async function() {
|
|
|
|
await StopDriver(this.driver);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be automatically redirected to secret page", async function() {
|
2019-02-13 22:10:00 +00:00
|
|
|
await VerifyUrlIs(this.driver, "https://admin.example.com:8080/secret.html");
|
2019-01-30 15:47:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should access the secret", async function() {
|
2019-02-12 22:23:43 +00:00
|
|
|
await VerifySecretObserved(this.driver);
|
2019-01-30 15:47:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given john has registered a TOTP secret,
|
|
|
|
* When he fails the TOTP challenge,
|
|
|
|
* Then he gets a notification message.
|
|
|
|
*/
|
|
|
|
describe('Fail validation of second factor with TOTP', function() {
|
2019-02-13 22:31:12 +00:00
|
|
|
before(async function() {
|
|
|
|
this.driver = await StartDriver();
|
2019-02-13 23:27:43 +00:00
|
|
|
await LoginAndRegisterTotp(this.driver, "john", "password", true);
|
2019-01-30 15:47:03 +00:00
|
|
|
const BAD_TOKEN = "125478";
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
await VisitPageAndWaitUrlIs(this.driver, "https://login.example.com:8080/#/?rd=https://admin.example.com:8080/secret.html");
|
2019-02-09 22:20:37 +00:00
|
|
|
await FillLoginPageWithUserAndPasswordAndClick(this.driver, 'john', 'password');
|
|
|
|
await ValidateTotp(this.driver, BAD_TOKEN);
|
2019-01-30 15:47:03 +00:00
|
|
|
});
|
|
|
|
|
2019-02-13 22:31:12 +00:00
|
|
|
after(async function() {
|
|
|
|
await StopDriver(this.driver);
|
|
|
|
});
|
|
|
|
|
2019-01-30 15:47:03 +00:00
|
|
|
it("get a notification message", async function() {
|
2019-02-13 22:08:28 +00:00
|
|
|
await VerifyNotificationDisplayed(this.driver, AUTHENTICATION_TOTP_FAILED);
|
2019-01-30 15:47:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|