2017-07-26 21:45:26 +00:00
|
|
|
import Cucumber = require("cucumber");
|
|
|
|
import seleniumWebdriver = require("selenium-webdriver");
|
|
|
|
import Assert = require("assert");
|
|
|
|
import Fs = require("fs");
|
|
|
|
import Speakeasy = require("speakeasy");
|
|
|
|
import CustomWorld = require("../support/world");
|
2017-10-06 22:09:42 +00:00
|
|
|
import BluebirdPromise = require("bluebird");
|
2017-07-26 21:45:26 +00:00
|
|
|
|
|
|
|
Cucumber.defineSupportCode(function ({ Given, When, Then }) {
|
2017-09-24 21:19:03 +00:00
|
|
|
When(/^I visit "(https:\/\/[a-zA-Z0-9:%&._\/=?-]+)"$/, function (link: string) {
|
2017-07-26 21:45:26 +00:00
|
|
|
return this.visit(link);
|
|
|
|
});
|
|
|
|
|
|
|
|
When("I set field {stringInDoubleQuotes} to {stringInDoubleQuotes}", function (fieldName: string, content: string) {
|
|
|
|
return this.setFieldTo(fieldName, content);
|
|
|
|
});
|
|
|
|
|
2017-08-02 22:30:41 +00:00
|
|
|
When("I clear field {stringInDoubleQuotes}", function (fieldName: string) {
|
|
|
|
return this.clearField(fieldName);
|
|
|
|
});
|
|
|
|
|
2017-07-26 21:45:26 +00:00
|
|
|
When("I click on {stringInDoubleQuotes}", function (text: string) {
|
|
|
|
return this.clickOnButton(text);
|
|
|
|
});
|
|
|
|
|
2017-09-02 23:25:43 +00:00
|
|
|
Given("I login with user {stringInDoubleQuotes} and password {stringInDoubleQuotes}",
|
|
|
|
function (username: string, password: string) {
|
|
|
|
return this.loginWithUserPassword(username, password);
|
|
|
|
});
|
|
|
|
|
|
|
|
Given("I login with user {stringInDoubleQuotes} and password {stringInDoubleQuotes} \
|
|
|
|
and I use TOTP token handle {stringInDoubleQuotes}",
|
|
|
|
function (username: string, password: string, totpTokenHandle: string) {
|
|
|
|
const that = this;
|
|
|
|
return this.loginWithUserPassword(username, password)
|
|
|
|
.then(function () {
|
|
|
|
return that.useTotpTokenHandle(totpTokenHandle);
|
|
|
|
});
|
|
|
|
});
|
2017-07-26 21:45:26 +00:00
|
|
|
|
|
|
|
Given("I register a TOTP secret called {stringInDoubleQuotes}", function (handle: string) {
|
|
|
|
return this.registerTotpSecret(handle);
|
|
|
|
});
|
|
|
|
|
|
|
|
Given("I use {stringInDoubleQuotes} as TOTP token", function (token: string) {
|
|
|
|
return this.useTotpToken(token);
|
|
|
|
});
|
|
|
|
|
|
|
|
Given("I use {stringInDoubleQuotes} as TOTP token handle", function (handle) {
|
|
|
|
return this.useTotpTokenHandle(handle);
|
|
|
|
});
|
|
|
|
|
2017-09-02 23:25:43 +00:00
|
|
|
When("I visit {stringInDoubleQuotes} and get redirected {stringInDoubleQuotes}",
|
|
|
|
function (url: string, redirectUrl: string) {
|
|
|
|
const that = this;
|
|
|
|
return this.driver.get(url)
|
|
|
|
.then(function () {
|
|
|
|
return that.driver.wait(seleniumWebdriver.until.urlIs(redirectUrl), 2000);
|
|
|
|
});
|
|
|
|
});
|
2017-07-26 21:45:26 +00:00
|
|
|
|
2017-09-02 23:25:43 +00:00
|
|
|
Given("I register TOTP and login with user {stringInDoubleQuotes} and password {stringInDoubleQuotes}",
|
|
|
|
function (username: string, password: string) {
|
|
|
|
return this.registerTotpAndSignin(username, password);
|
|
|
|
});
|
2017-07-26 21:45:26 +00:00
|
|
|
|
2017-08-02 22:30:41 +00:00
|
|
|
function hasAccessToSecret(link: string, that: any) {
|
|
|
|
return that.driver.get(link)
|
2017-07-26 21:45:26 +00:00
|
|
|
.then(function () {
|
2017-09-24 21:19:03 +00:00
|
|
|
return that.waitUntilUrlContains(link);
|
2017-07-26 21:45:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-02 22:30:41 +00:00
|
|
|
function hasNoAccessToSecret(link: string, that: any) {
|
|
|
|
return that.driver.get(link)
|
2017-07-26 21:45:26 +00:00
|
|
|
.then(function () {
|
2017-08-02 22:30:41 +00:00
|
|
|
return that.getErrorPage(403);
|
2017-07-26 21:45:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Then("I have access to:", function (dataTable: Cucumber.TableDefinition) {
|
2017-09-03 13:22:09 +00:00
|
|
|
const promises: any = [];
|
2017-07-26 21:45:26 +00:00
|
|
|
for (let i = 0; i < dataTable.rows().length; i++) {
|
|
|
|
const url = (dataTable.hashes() as any)[i].url;
|
2017-08-02 22:30:41 +00:00
|
|
|
promises.push(hasAccessToSecret(url, this));
|
2017-07-26 21:45:26 +00:00
|
|
|
}
|
2017-10-06 22:09:42 +00:00
|
|
|
return BluebirdPromise.all(promises);
|
2017-07-26 21:45:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Then("I have no access to:", function (dataTable: Cucumber.TableDefinition) {
|
|
|
|
const promises = [];
|
|
|
|
for (let i = 0; i < dataTable.rows().length; i++) {
|
|
|
|
const url = (dataTable.hashes() as any)[i].url;
|
2017-08-02 22:30:41 +00:00
|
|
|
promises.push(hasNoAccessToSecret(url, this));
|
2017-07-26 21:45:26 +00:00
|
|
|
}
|
2017-10-06 22:09:42 +00:00
|
|
|
return BluebirdPromise.all(promises);
|
2017-07-26 21:45:26 +00:00
|
|
|
});
|
|
|
|
});
|