Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlyG55 committed Jan 2, 2025
1 parent a758847 commit 315d420
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 17 deletions.
6 changes: 4 additions & 2 deletions tests/acceptance/features/authentication.feature
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Feature: Authentication
Scenario: User successfully login without 2FA
Given the user comes from the stub relying party with options: "2fa-off"
Scenario: User successfully login
Given the user comes from the stub relying party with default options
Then the user is taken to the "Create your GOV.UK One Login or sign in" page
When the user selects sign in
Then the user is taken to the "Enter your email" page
When user enters "TEST_USER_EMAIL" email address
Then the user is taken to the "Enter your password" page
When the user enters their password
Then the user is taken to the "Check your phone" page
When the user enters the six digit security code from their phone
Then the user is returned to the service
And the RP receives the expected user info
And the user logs out
Expand Down
2 changes: 0 additions & 2 deletions tests/acceptance/pages/base-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ module.exports = class BasePage {

elementWithIdContainsText = async (elementId, text) => {
await this.waitForReadyStateComplete();
const element = await this.page.findElement(By.xpath(`//*[@id='${elementId}']`));
console.log(await element.getText());
await this.page.findElement(By.xpath(`//*[contains(text(), '${text}') and @id='${elementId}']`));
}
}
19 changes: 19 additions & 0 deletions tests/acceptance/pages/check-your-phone-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const BasePage = require("./base-page.js");
const { By } = require("selenium-webdriver");

module.exports = class CheckYourPhonePage extends BasePage {
constructor(page) {
super(page);
}

phoneCodeField = By.id("code");

enterCorrectPhoneCodeAndContinue = async () => {
await this.enterPhoneCode(process.env.TEST_USER_PHONE_VERIFY_CODE ?? "");
await this.findAndClickContinue();
}

enterPhoneCode = async (phoneCode) => {
await this.clearFieldAndEnter(this.phoneCodeField, phoneCode);
}
}
4 changes: 2 additions & 2 deletions tests/acceptance/pages/enter-your-password-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module.exports = class EnterYourPasswordPage extends BasePage {
await this.clearFieldAndEnter(this.passwordField, password);
}

enterPasswordAndContinue = async (emailAddress) => {
await this.enterPassword(emailAddress);
enterPasswordAndContinue = async (password) => {
await this.enterPassword(password);
await this.findAndClickContinue();
}
}
8 changes: 4 additions & 4 deletions tests/acceptance/pages/rp-stub-page.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const { By } = require("selenium-webdriver");
const BasePage = require("./base-page.js");

module.exports = class RpStubPage extends BasePage {
constructor(page) {
super(page);
}

goToRpStub = async () => {
goToRpStubAndContinue = async () => {
await this.page.get(this.RP_URL.toString());
await this.waitForThisText("Request Object");
await this.findAndClickContinue();
}

selectRpOptionsByIdAndContinue = async (opts) => {
/* selectRpOptionsByIdAndContinue = async (opts) => {
if (opts && opts.toLowerCase() !== "default") {
const ids = opts.split(",");
for (const id of ids) {
await this.page.findElement(By.id(id)).click();
}
}
await this.findAndClickContinue();
}
}*/
}
9 changes: 5 additions & 4 deletions tests/acceptance/step_definitions/common-step-def.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { When, Then } = require('@cucumber/cucumber');
const BasePage = require("../pages/base-page.js");
const { equal } = require("node:assert");
const { deepStrictEqual } = require("node:assert");

const TEST_USER_INFO_RESPONSE = {
sub: process.env.TEST_USER_SUB,
Expand All @@ -13,7 +13,8 @@ const TEST_USER_INFO_REQUEST = {
sub: process.env.TEST_USER_SUB,
email: process.env.TEST_USER_EMAIL,
emailVerified: process.env.TEST_USER_EMAIL_VERIFIED === "true",
phoneNumberVerified: process.env.TEST_USER_PHONE_NUMBER_VERIFIED === "true"
phoneNumberVerified: process.env.TEST_USER_PHONE_NUMBER_VERIFIED === "true",
phoneNumber: ""
};

Then("the user is taken to the {string} page", async function (pageTitle){
Expand Down Expand Up @@ -57,6 +58,6 @@ When("the simulator is sent the configuration", async function () {
})

Then("the simulator returns the expected user info", async function () {
const authorizeResponse = await fetch('http://localhost:3000/authorize?vtr=%5B%22Cl%22%5D&scope=openid+email&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3001%2Fcallback&state=QL1o9IKHyfTr4BpTCiMeROYKyd-8-k6vytO8OaUZspI&prompt=none&nonce=61SGsT-UYLpgIS2DmBKP-JUkMiqJx1jhe6mk8RpWjRQ&client_id=HGIOgho9HIRhgoepdIOPFdIUWgewi0jw');
equal(await authorizeResponse.text(), JSON.stringify(TEST_USER_INFO_RESPONSE));
const authorizeResponse = await fetch('http://localhost:3000/authorize?vtr=%5B%22Cl.Cm%22%5D&scope=openid+email+phone&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3001%2Fcallback&state=QL1o9IKHyfTr4BpTCiMeROYKyd-8-k6vytO8OaUZspI&prompt=none&nonce=61SGsT-UYLpgIS2DmBKP-JUkMiqJx1jhe6mk8RpWjRQ&client_id=HGIOgho9HIRhgoepdIOPFdIUWgewi0jw');
deepStrictEqual(await authorizeResponse.json(), TEST_USER_INFO_RESPONSE);
});
6 changes: 6 additions & 0 deletions tests/acceptance/step_definitions/login-step-def.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const EnterYourPasswordPage = require("../pages/enter-your-password-page.js");
const EnterYourEmailAddressToSignInPage = require("../pages/enter-your-email-address-to-sign-in-page.js");
const CreateOrSignInPage = require("../pages/create-or-sign-in-page.js");
const { When } = require("@cucumber/cucumber");
const CheckYourPhonePage = require("../pages/check-your-phone-page");


When("the user selects sign in", async function () {
Expand All @@ -21,4 +22,9 @@ When("the user enters their password", async function () {
await enterYourPasswordPage.enterPasswordAndContinue(process.env.TEST_USER_PASSWORD ?? "");
});

When("the user enters the six digit security code from their phone", async function () {
const checkYourPhonePage = new CheckYourPhonePage(this.driver);
await checkYourPhonePage.enterCorrectPhoneCodeAndContinue();
});

const sleep = async (ms) => await new Promise(resolve => setTimeout(resolve, ms))
5 changes: 2 additions & 3 deletions tests/acceptance/step_definitions/rp-stub-step-def.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const RpStubPage = require("../pages/rp-stub-page.js");
const { When } = require("@cucumber/cucumber");


When("the user comes from the stub relying party with options: {string}", async function (options) {
When("the user comes from the stub relying party with default options", async function () {
const rpStubPage = new RpStubPage(this.driver);
await rpStubPage.goToRpStub();
await rpStubPage.selectRpOptionsByIdAndContinue(options);
await rpStubPage.goToRpStubAndContinue();
});

0 comments on commit 315d420

Please sign in to comment.