From d2b359fe6403de83b11e325f9808cc7c5b293208 Mon Sep 17 00:00:00 2001 From: cargil Date: Mon, 2 Dec 2024 14:42:29 +0000 Subject: [PATCH] wip --- .../features/authentication.feature | 4 +++- tests/acceptance/pages/base-page.js | 2 -- .../acceptance/pages/check-your-phone-page.js | 19 +++++++++++++++++++ .../pages/enter-your-password-page.js | 4 ++-- tests/acceptance/pages/rp-stub-page.js | 8 ++++---- .../step_definitions/common-step-def.js | 9 +++++---- .../step_definitions/login-step-def.js | 6 ++++++ .../step_definitions/rp-stub-step-def.js | 5 ++--- 8 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 tests/acceptance/pages/check-your-phone-page.js diff --git a/tests/acceptance/features/authentication.feature b/tests/acceptance/features/authentication.feature index 53854a09..f0719aed 100644 --- a/tests/acceptance/features/authentication.feature +++ b/tests/acceptance/features/authentication.feature @@ -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" + 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 diff --git a/tests/acceptance/pages/base-page.js b/tests/acceptance/pages/base-page.js index 9f82c088..6d87d0a1 100644 --- a/tests/acceptance/pages/base-page.js +++ b/tests/acceptance/pages/base-page.js @@ -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}']`)); } } \ No newline at end of file diff --git a/tests/acceptance/pages/check-your-phone-page.js b/tests/acceptance/pages/check-your-phone-page.js new file mode 100644 index 00000000..9a0ea073 --- /dev/null +++ b/tests/acceptance/pages/check-your-phone-page.js @@ -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); + } +} \ No newline at end of file diff --git a/tests/acceptance/pages/enter-your-password-page.js b/tests/acceptance/pages/enter-your-password-page.js index 526e2e8c..886be547 100644 --- a/tests/acceptance/pages/enter-your-password-page.js +++ b/tests/acceptance/pages/enter-your-password-page.js @@ -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(); } } \ No newline at end of file diff --git a/tests/acceptance/pages/rp-stub-page.js b/tests/acceptance/pages/rp-stub-page.js index 638141fc..caeece3a 100644 --- a/tests/acceptance/pages/rp-stub-page.js +++ b/tests/acceptance/pages/rp-stub-page.js @@ -1,4 +1,3 @@ -const { By } = require("selenium-webdriver"); const BasePage = require("./base-page.js"); module.exports = class RpStubPage extends BasePage { @@ -6,12 +5,13 @@ module.exports = class RpStubPage extends BasePage { 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) { @@ -19,5 +19,5 @@ module.exports = class RpStubPage extends BasePage { } } await this.findAndClickContinue(); - } + }*/ } \ No newline at end of file diff --git a/tests/acceptance/step_definitions/common-step-def.js b/tests/acceptance/step_definitions/common-step-def.js index 1d229f1b..50914b57 100644 --- a/tests/acceptance/step_definitions/common-step-def.js +++ b/tests/acceptance/step_definitions/common-step-def.js @@ -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, @@ -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){ @@ -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); }); diff --git a/tests/acceptance/step_definitions/login-step-def.js b/tests/acceptance/step_definitions/login-step-def.js index 9c26bc71..169dd26c 100644 --- a/tests/acceptance/step_definitions/login-step-def.js +++ b/tests/acceptance/step_definitions/login-step-def.js @@ -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 () { @@ -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)) \ No newline at end of file diff --git a/tests/acceptance/step_definitions/rp-stub-step-def.js b/tests/acceptance/step_definitions/rp-stub-step-def.js index 54899384..d1c9a8d4 100644 --- a/tests/acceptance/step_definitions/rp-stub-step-def.js +++ b/tests/acceptance/step_definitions/rp-stub-step-def.js @@ -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(); }); \ No newline at end of file