From 59724d5b94de70d64e6677d5248610440ceab8ce Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 31 Jan 2025 19:24:07 +0530 Subject: [PATCH] Add recovery email related helpers and init test --- examples/for-tests/src/App.js | 5 -- lib/build/webauthnprebuiltui.js | 5 +- test/end-to-end/webauthn.helpers.js | 15 +++- .../webauthn.recovery_email.test.js | 76 +++++++++++++++++++ 4 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 test/end-to-end/webauthn.recovery_email.test.js diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 765abf4e3..3c40437b9 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -1154,11 +1154,6 @@ function setIsNewUserToStorage(recipeName, isNewRecipeUser) { function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) { return Webauthn.init({ - style: ` - [data-supertokens~=container] { - font-family: cursive; - } - `, override: { functions: (implementation) => { const log = logWithPrefix(`ST_LOGS WEBAUTHN OVERRIDE`); diff --git a/lib/build/webauthnprebuiltui.js b/lib/build/webauthnprebuiltui.js index 413373e0d..4847548cb 100644 --- a/lib/build/webauthnprebuiltui.js +++ b/lib/build/webauthnprebuiltui.js @@ -1202,7 +1202,7 @@ function PasskeySignInTheme(props) { // Define the code to handle sign in properly through this component. var handleWebauthnSignInClick = function () { return genericComponentOverrideContext.__awaiter(_this, void 0, void 0, function () { - var fieldUpdates, _a, result, generalError, fetchError, e_1; + var fieldUpdates, _a, result, generalError, fetchError; return genericComponentOverrideContext.__generator(this, function (_b) { switch (_b.label) { case 0: @@ -1242,8 +1242,7 @@ function PasskeySignInTheme(props) { } return [3 /*break*/, 5]; case 3: - e_1 = _b.sent(); - console.debug(e_1); + _b.sent(); setError("SOMETHING_WENT_WRONG_ERROR"); return [3 /*break*/, 5]; case 4: diff --git a/test/end-to-end/webauthn.helpers.js b/test/end-to-end/webauthn.helpers.js index e82034b30..01ade6187 100644 --- a/test/end-to-end/webauthn.helpers.js +++ b/test/end-to-end/webauthn.helpers.js @@ -1,5 +1,5 @@ import { TEST_CLIENT_BASE_URL } from "../constants"; -import { toggleSignInSignUp, setInputValues, submitForm } from "../helpers"; +import { toggleSignInSignUp, setInputValues, submitForm, waitForSTElement } from "../helpers"; export async function tryWebauthnSignUp(page, email) { await Promise.all([ @@ -24,3 +24,16 @@ export async function tryWebauthnSignIn(page) { await submitForm(page); await new Promise((res) => setTimeout(res, 1000)); } + +export async function openRecoveryAccountPage(page) { + await Promise.all([ + page.goto(`${TEST_CLIENT_BASE_URL}/auth?authRecipe=webauthn`), + page.waitForNavigation({ waitUntil: "networkidle0" }), + ]); + + await toggleSignInSignUp(page); + + const recoverAccountLink = await waitForSTElement(page, "[data-supertokens~='recoverAccountTrigger']"); + await recoverAccountLink.click(); + await new Promise((res) => setTimeout(res, 1000)); +} diff --git a/test/end-to-end/webauthn.recovery_email.test.js b/test/end-to-end/webauthn.recovery_email.test.js new file mode 100644 index 000000000..98f705f63 --- /dev/null +++ b/test/end-to-end/webauthn.recovery_email.test.js @@ -0,0 +1,76 @@ +import fetch from "isomorphic-fetch"; +import { TEST_SERVER_BASE_URL } from "../constants"; +import { + backendBeforeEach, + setupBrowser, + screenshotOnFailure, + clearBrowserCookiesWithoutAffectingConsole, + toggleSignInSignUp, + setEnabledRecipes, + waitForSTElement, + submitForm, +} from "../helpers"; +import { tryWebauthnSignIn, openRecoveryAccountPage } from "./webauthn.helpers"; +import assert from "assert"; + +describe("SuperTokens Webauthn Recovery Email", () => { + let browser; + let page; + let consoleLogs = []; + + before(async function () { + await backendBeforeEach(); + + await fetch(`${TEST_SERVER_BASE_URL}/startst`, { + method: "POST", + }).catch(console.error); + + browser = await setupBrowser(); + page = await browser.newPage(); + page.on("console", (consoleObj) => { + const log = consoleObj.text(); + if (log.startsWith("ST_LOGS")) { + consoleLogs.push(log); + } + }); + }); + + after(async function () { + await browser.close(); + await fetch(`${TEST_SERVER_BASE_URL}/after`, { + method: "POST", + }).catch(console.error); + + await fetch(`${TEST_SERVER_BASE_URL}/stopst`, { + method: "POST", + }).catch(console.error); + }); + + afterEach(function () { + return screenshotOnFailure(this, browser); + }); + + beforeEach(async function () { + consoleLogs = []; + consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs); + await toggleSignInSignUp(page); + }); + + describe("Recovery Email Test", () => { + it("should show the recovery email page", async () => { + await openRecoveryAccountPage(page); + + const headerTextContainer = await waitForSTElement( + page, + "[data-supertokens~='passkeyRecoverAccountFormHeader']" + ); + const headerText = await headerTextContainer.evaluate((el) => el.textContent); + assert.strictEqual(headerText, "Recover Account"); + assert.deepStrictEqual(consoleLogs, [ + "ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH", + "ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS", + "ST_LOGS WEBAUTHN GET_REDIRECTION_URL SEND_RECOVERY_EMAIL", + ]); + }); + }); +});