From 00fce25413736abbcd89beb51fa7b090e8aec342 Mon Sep 17 00:00:00 2001 From: Harry Le Date: Tue, 3 Sep 2024 09:31:54 +0700 Subject: [PATCH] test: update new mfa flow --- .../AuthServicePage.ts | 28 +++++++++++++++++++ .../auth-case-2.test.ts | 20 +++---------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/authservice/login-with-passwordless/AuthServicePage.ts b/authservice/login-with-passwordless/AuthServicePage.ts index 8a34cd2..3b035fb 100644 --- a/authservice/login-with-passwordless/AuthServicePage.ts +++ b/authservice/login-with-passwordless/AuthServicePage.ts @@ -35,6 +35,18 @@ export class AuthServicePage { await this.page.click(`[data-testid="confirmPassword"]`); } + async inputPasswordFactorNewMFAFlow(password: string) { + await this.page.click(`[data-testid="passwordFactor"]`); + + await this.page.fill(`input[data-testid="auth-password"]`, password); + await this.page.fill(`input[data-testid="auth-confirm-password"]`, password); + await this.page.click(`[data-testid="confirmPassword"]`); + } + + async finishSetupNewMFAList() { + await this.page.click(`[data-testid="finish-setup"]`); + } + async confirmDone2FASetup() { await this.page.click(`[data-testid="done"]`); } @@ -88,4 +100,20 @@ export class AuthServicePage { await this.page.locator(`xpath=.//input[@data-test='single-input']`).first().type(token); return secret; } + + async setupAuthenticatorNewMFAFlow() { + await this.page.locator('[data-testid="authenticatorFactor"]').click(); + await this.page.locator('text="Enter code manually"').click(); + + const secret = await this.page.locator(`div>span`).textContent(); + await this.page.click(`button[aria-label="Next"]`); + + // Generate TOTP token + const token = speakeasy.totp({ + secret, + encoding: "base32", + }); + await this.page.locator(`xpath=.//input[@data-test='single-input']`).first().type(token); + return secret; + } } diff --git a/authservice/login-with-passwordless/auth-case-2.test.ts b/authservice/login-with-passwordless/auth-case-2.test.ts index c43ed42..5a79ef7 100644 --- a/authservice/login-with-passwordless/auth-case-2.test.ts +++ b/authservice/login-with-passwordless/auth-case-2.test.ts @@ -18,7 +18,7 @@ test.describe.serial("Passwordless Login scenarios", () => { await loginPage.gotoLoginPage(authServiceURL); await loginPage.selectBuildEnv("testing"); - await loginPage.selectAllMFAFactor(); + await loginPage.selectMFAFactor(["DEVICE", "PASSWORD", "AUTHENTICATOR"]); await loginPage.selectMFALevel("none"); await loginPage.selectMFAMandantory(["DEVICE", "PASSWORD", "AUTHENTICATOR"]); await loginPage.selectOpenloginNetwork("sapphire_devnet"); @@ -74,29 +74,17 @@ test.describe.serial("Passwordless Login scenarios", () => { await authServicePage.clickSetup2FA(); - // SETUP DEVICE FACTOR - - await authServicePage.saveTheDevice(); - - // SKIP SOCIAL FACTOR - - await authServicePage.skipTheFactorSetup(); - // SETUP AUTHENTICATOR FACTOR - await authServicePage.setupAuthenticator(); - - // SKIP RECOVERY FACTOR - - await authServicePage.skipTheFactorSetup(); + await authServicePage.setupAuthenticatorNewMFAFlow(); // SETUP PASSWORD - await authServicePage.inputPasswordFactor(passwordTestingFactor); + await authServicePage.inputPasswordFactorNewMFAFlow(passwordTestingFactor); // SKIP PASSKEY - await authServicePage.skipPasskeySetup(); + await authServicePage.finishSetupNewMFAList(); await authServicePage.confirmDone2FASetup(); // GET INFO KEY AFTER 2FA SETUP AND VERIFY