From 2ee063c06a8392953e2cdef7529dcc361ba0bae4 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Mon, 25 Nov 2024 20:26:29 +0100 Subject: [PATCH] test: switch most thirdparty test to use mock provider --- test/end-to-end/generalerror.test.js | 8 +-- test/end-to-end/getRedirectionURL.test.js | 20 +++--- ...multitenancy.dynamic_login_methods.test.js | 3 +- test/end-to-end/thirdparty.test.js | 64 ++++++++++--------- .../thirdpartyemailpassword.test.js | 14 ++-- .../end-to-end/thirdpartypasswordless.test.js | 8 +-- .../thirdpartypasswordless.tp.test.js | 2 +- test/end-to-end/userContext.test.js | 3 +- test/helpers.js | 17 +++++ 9 files changed, 81 insertions(+), 58 deletions(-) diff --git a/test/end-to-end/generalerror.test.js b/test/end-to-end/generalerror.test.js index 1100c0150..228472f4a 100644 --- a/test/end-to-end/generalerror.test.js +++ b/test/end-to-end/generalerror.test.js @@ -37,7 +37,7 @@ import { assertProviders, clickOnProviderButton, clickOnProviderButtonWithoutWaiting, - loginWithAuth0, + loginWithMockProvider, isGeneralErrorSupported, setGeneralErrorToLocalStorage, backendBeforeEach, @@ -403,7 +403,7 @@ function getThirdPartyTests(rid, ridForStorage) { await assertProviders(page); let [_, response1] = await Promise.all([ - clickOnProviderButtonWithoutWaiting(page, "Auth0"), + clickOnProviderButtonWithoutWaiting(page, "Mock Provider"), page.waitForResponse( (response) => response.url().includes(GET_AUTH_URL_API) && @@ -428,10 +428,10 @@ function getThirdPartyTests(rid, ridForStorage) { await page.goto(`${TEST_CLIENT_BASE_URL}/auth`); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); let [_, response1] = await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); diff --git a/test/end-to-end/getRedirectionURL.test.js b/test/end-to-end/getRedirectionURL.test.js index f491f7ad9..77efb1cf4 100644 --- a/test/end-to-end/getRedirectionURL.test.js +++ b/test/end-to-end/getRedirectionURL.test.js @@ -7,7 +7,7 @@ import { screenshotOnFailure, assertProviders, clickOnProviderButton, - loginWithAuth0, + loginWithMockProvider, setPasswordlessFlowType, waitForSTElement, getPasswordlessDevice, @@ -114,9 +114,9 @@ describe("getRedirectionURL Tests", function () { page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck")); @@ -170,9 +170,9 @@ describe("getRedirectionURL Tests", function () { it("Test that isNewRecipeUser works correctly when signing up with auth 0", async function () { await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck")); @@ -354,9 +354,9 @@ describe("getRedirectionURL Tests", function () { page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck")); @@ -642,10 +642,10 @@ describe("getRedirectionURL Tests", function () { ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse( (response) => response.url() === SIGN_IN_UP_API && response.status() === 200 ), @@ -654,7 +654,7 @@ describe("getRedirectionURL Tests", function () { const urlAfterSignUp = await page.url(); const newUserCheck = await page.evaluate(() => localStorage.getItem("isNewUserCheck")); assert.equal(newUserCheck, "thirdparty-true"); - assert(urlAfterSignUp.includes("/auth/callback/auth0")); + assert(urlAfterSignUp.includes("/auth/callback/mock-provider")); }); }); }); diff --git a/test/end-to-end/multitenancy.dynamic_login_methods.test.js b/test/end-to-end/multitenancy.dynamic_login_methods.test.js index 6364161fd..303235eb9 100644 --- a/test/end-to-end/multitenancy.dynamic_login_methods.test.js +++ b/test/end-to-end/multitenancy.dynamic_login_methods.test.js @@ -34,13 +34,14 @@ import { loginWithGoogle, clearBrowserCookiesWithoutAffectingConsole, clickOnProviderButton, - loginWithAuth0, + loginWithMockProvider, isMultitenancySupported, isMultitenancyManagementEndpointsSupported, setupTenant, backendBeforeEach, getTextByDataSupertokens, setupBrowser, + loginWithAuth0, } from "../helpers"; import { TEST_CLIENT_BASE_URL, diff --git a/test/end-to-end/thirdparty.test.js b/test/end-to-end/thirdparty.test.js index 49411419b..4a659ea70 100644 --- a/test/end-to-end/thirdparty.test.js +++ b/test/end-to-end/thirdparty.test.js @@ -26,7 +26,7 @@ import { assertNoSTComponents, generateState, clickOnProviderButton, - loginWithAuth0, + loginWithMockProvider, getGeneralError, waitFor, screenshotOnFailure, @@ -34,6 +34,7 @@ import { backendBeforeEach, waitForUrl, setupBrowser, + loginWithAuth0, } from "../helpers"; import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SIGN_IN_UP_API, GET_AUTH_URL_API } from "../constants"; @@ -137,37 +138,37 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs, ]); }); - it("Successful sign in with Auth0 with redirectToPath (w/ leading slash) keeping query params", async function () { + it("Successful sign in with redirectToPath (w/ leading slash) keeping query params", async function () { await Promise.all([ page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%2Fredirect-here%3Ffoo%3Dbar`), page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); const { pathname, search } = await page.evaluate(() => window.location); assert.deepStrictEqual(pathname + search, "/redirect-here?foo=bar"); }); - it("Successful sign in with Auth0 with redirectToPath (w/o leading slash) keeping query params", async function () { + it("Successful sign in with SSO with redirectToPath (w/o leading slash) keeping query params", async function () { await Promise.all([ page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%3Ffoo%3Dbar`), page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); const { pathname, search } = await page.evaluate(() => window.location); assert.deepStrictEqual(pathname + search, "/?foo=bar"); }); - it("Successful sign in with Auth0 with redirectToPath (query params + fragment)", async function () { + it("Successful sign in with SSO with redirectToPath (query params + fragment)", async function () { await Promise.all([ page.goto( `${TEST_CLIENT_BASE_URL}/auth?redirectToPath=${encodeURIComponent( @@ -177,39 +178,39 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs, page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); const { pathname, search, hash } = await page.evaluate(() => window.location); assert.deepStrictEqual(pathname + search + hash, "/redirect-here?foo=bar#cell=4,1-6,2"); }); - it("Successful sign in with Auth0 with redirectToPath (only fragment)", async function () { + it("Successful sign in with SSO with redirectToPath (only fragment)", async function () { await Promise.all([ page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=${encodeURIComponent("#cell=4,1-6,2")}`), page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); const { pathname, search, hash } = await page.evaluate(() => window.location); assert.deepStrictEqual(pathname + search + hash, "/#cell=4,1-6,2"); }); - it("Successful signin with Auth0 and email verification", async function () { + it("Successful signin with SSO and email verification", async function () { await Promise.all([ page.goto(`${TEST_CLIENT_BASE_URL}/auth?mode=REQUIRED`), page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); await page.waitForSelector(".sessionInfo-user-id"); @@ -241,29 +242,29 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs, ]); }); - it("Successful signin with auth0 and redirectToPath", async function () { + it("Successful signin with SSO and redirectToPath", async function () { await Promise.all([ page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=/hello`), page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); await waitForUrl(page, "/hello"); }); - it("Successful signin with auth0 and redirectToPath case sensitive", async function () { + it("Successful signin with SSO and redirectToPath case sensitive", async function () { await Promise.all([ page.goto(`${TEST_CLIENT_BASE_URL}/auth?redirectToPath=%2FCasE%2FCase-SensItive1-PAth`), page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); await waitForUrl(page, "/CasE/Case-SensItive1-PAth"); @@ -271,7 +272,10 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs, it("should work with custom getRedirectUrl", async function () { await page.evaluate((TEST_CLIENT_BASE_URL) => { - localStorage.setItem("thirdPartyRedirectURL", `${TEST_CLIENT_BASE_URL}/auth/auth0-custom-redirect`); + localStorage.setItem( + "thirdPartyRedirectURL", + `${TEST_CLIENT_BASE_URL}/auth/mock-provider-custom-redirect` + ); }, TEST_CLIENT_BASE_URL); await Promise.all([ @@ -279,10 +283,10 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs, page.waitForNavigation({ waitUntil: "networkidle0" }), ]); await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); - await loginWithAuth0(page); + await clickOnProviderButton(page, "Mock Provider"); + await loginWithMockProvider(page); - await waitForUrl(page, "/auth/auth0-custom-redirect"); + await waitForUrl(page, "/auth/mock-provider-custom-redirect"); }); // it("Successful signin with facebook", async function () { @@ -354,8 +358,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs, } }; page.on("request", requestHandler); - await clickOnProviderButton(page, "Auth0"); - await loginWithAuth0(page); + await clickOnProviderButton(page, "Mock Provider"); + await loginWithMockProvider(page); const error = await getGeneralError(page); assert.deepStrictEqual(error, "TOS"); }); @@ -390,8 +394,8 @@ export function getThirdPartyTestCases({ authRecipe, rid, signInUpPageLoadLogs, }; page.on("request", requestHandler); - await clickOnProviderButton(page, "Auth0"); - await loginWithAuth0(page); + await clickOnProviderButton(page, "Mock Provider"); + await loginWithMockProvider(page); const error = await getGeneralError(page); assert.deepStrictEqual(error, "Test message!!!!"); diff --git a/test/end-to-end/thirdpartyemailpassword.test.js b/test/end-to-end/thirdpartyemailpassword.test.js index fb4bdef59..d4a9660a3 100644 --- a/test/end-to-end/thirdpartyemailpassword.test.js +++ b/test/end-to-end/thirdpartyemailpassword.test.js @@ -29,7 +29,7 @@ import { getLogoutButton, signUp, toggleSignInSignUp, - loginWithAuth0, + loginWithMockProvider, getLoginWithRedirectToSignIn, getLoginWithRedirectToSignUp, getAuthPageHeaderText, @@ -284,11 +284,11 @@ describe("SuperTokens Third Party Email Password", function () { await waitForSTElement(page, "[data-supertokens~=generalError]", true); }); - it("Successful signin/up with auth0", async function () { + it("Successful signin/up", async function () { await assertProviders(page); - await clickOnProviderButton(page, "Auth0"); + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); await page.waitForSelector(".sessionInfo-user-id"); @@ -339,10 +339,10 @@ describe("SuperTokens Third Party Email Password", function () { await Promise.all([await logoutButton.click(), page.waitForNavigation({ waitUntil: "networkidle0" })]); await waitForUrl(page, "/auth"); - // 2. Sign in with auth0 with same address. - await clickOnProviderButton(page, "Auth0"); + // 2. Sign in with SSO with same address. + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); await waitForUrl(page, "/dashboard"); diff --git a/test/end-to-end/thirdpartypasswordless.test.js b/test/end-to-end/thirdpartypasswordless.test.js index d97f74d34..36e0376eb 100644 --- a/test/end-to-end/thirdpartypasswordless.test.js +++ b/test/end-to-end/thirdpartypasswordless.test.js @@ -24,7 +24,7 @@ import { clickOnProviderButton, getUserIdWithFetch, getLogoutButton, - loginWithAuth0, + loginWithMockProvider, setInputValues, submitForm, waitForSTElement, @@ -139,10 +139,10 @@ describe("SuperTokens Third Party Passwordless", function () { await waitForSTElement(page, `input[name=email]`); - // 3. Sign in with auth0 with same address. - await clickOnProviderButton(page, "Auth0"); + // 3. Sign in with SSO with same address. + await clickOnProviderButton(page, "Mock Provider"); await Promise.all([ - loginWithAuth0(page), + loginWithMockProvider(page), page.waitForResponse((response) => response.url() === SIGN_IN_UP_API && response.status() === 200), ]); await Promise.all([page.waitForSelector(".sessionInfo-user-id"), page.waitForNetworkIdle()]); diff --git a/test/end-to-end/thirdpartypasswordless.tp.test.js b/test/end-to-end/thirdpartypasswordless.tp.test.js index c0cb7f139..4d919cde0 100644 --- a/test/end-to-end/thirdpartypasswordless.tp.test.js +++ b/test/end-to-end/thirdpartypasswordless.tp.test.js @@ -24,7 +24,7 @@ import { clickOnProviderButton, getUserIdWithFetch, getLogoutButton, - loginWithAuth0, + loginWithMockProvider, setInputValues, submitForm, waitForSTElement, diff --git a/test/end-to-end/userContext.test.js b/test/end-to-end/userContext.test.js index 2a5e120f8..91b6a16e7 100644 --- a/test/end-to-end/userContext.test.js +++ b/test/end-to-end/userContext.test.js @@ -23,10 +23,11 @@ import { submitFormReturnRequestAndResponse, assertProviders, clickOnProviderButton, - loginWithAuth0, + loginWithMockProvider, backendBeforeEach, waitForUrl, setupBrowser, + loginWithAuth0, } from "../helpers"; import { TEST_CLIENT_BASE_URL, diff --git a/test/helpers.js b/test/helpers.js index c9ddfeb08..b672e0c50 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -624,6 +624,23 @@ export async function loginWithFacebook(page) { await Promise.all([page.keyboard.press("Enter"), page.waitForNavigation({ waitUntil: "networkidle0" })]); } +export async function loginWithMockProvider( + page, + email = "st_test_user@supertokens.io", + userId = "123", + isVerified = true +) { + await Promise.all([ + page.goto( + `${TEST_CLIENT_BASE_URL}/auth/callback/mock-provider?code=asdf&email=${encodeURIComponent( + email + )}&userId=${encodeURIComponent(userId)}&isVerified=${isVerified}&state=${url.searchParams.get("state")}` + ), + page.waitForNavigation({ waitUntil: "networkidle0" }), + ]); +} +loginWithMockProvider; + export async function loginWithAuth0(page) { await page.focus("input[type=email]"); await page.keyboard.type(process.env.AUTH0_EMAIL);