diff --git a/examples/for-tests-react-16/src/App.js b/examples/for-tests-react-16/src/App.js index c772bbc9f..fdc197859 100644 --- a/examples/for-tests-react-16/src/App.js +++ b/examples/for-tests-react-16/src/App.js @@ -272,50 +272,52 @@ if (testContext.enableMFA) { ); } -SuperTokens.init({ - usesDynamicLoginMethods: testContext.usesDynamicLoginMethods, - clientType: testContext.clientType, - appInfo: { - appName: "SuperTokens", - websiteDomain: getWebsiteDomain(), - apiDomain: getApiDomain(), - websiteBasePath, - }, - languageTranslations: { - translations: { - en: { - AUTH_PAGE_FOOTER_TOS: "TOS", - }, - hu: { - AUTH_PAGE_FOOTER_TOS: "ÁSZF", +if (!window.location.pathname.startsWith("/mockProvider")) { + SuperTokens.init({ + usesDynamicLoginMethods: testContext.usesDynamicLoginMethods, + clientType: testContext.clientType, + appInfo: { + appName: "SuperTokens", + websiteDomain: getWebsiteDomain(), + apiDomain: getApiDomain(), + websiteBasePath, + }, + languageTranslations: { + translations: { + en: { + AUTH_PAGE_FOOTER_TOS: "TOS", + }, + hu: { + AUTH_PAGE_FOOTER_TOS: "ÁSZF", + }, }, }, - }, - getRedirectionURL: (context) => { - if (context.action === "SUCCESS") { - let logId = { - emailpassword: "EMAIL_PASSWORD", - thirdparty: "THIRD_PARTY", - passwordless: "PASSWORDLESS", - }[context.recipeId]; - - console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`); - setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser); - if (testContext.disableRedirectionAfterSuccessfulSignInUp) { - return null; + getRedirectionURL: (context) => { + if (context.action === "SUCCESS") { + let logId = { + emailpassword: "EMAIL_PASSWORD", + thirdparty: "THIRD_PARTY", + passwordless: "PASSWORDLESS", + }[context.recipeId]; + + console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`); + setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser); + if (testContext.disableRedirectionAfterSuccessfulSignInUp) { + return null; + } + return context.redirectToPath || "/dashboard"; + } else { + console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`); } - return context.redirectToPath || "/dashboard"; - } else { - console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`); - } - }, - useShadowDom, - privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", - termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", - defaultToSignUp, - disableAuthRoute: testContext.disableDefaultUI, - recipeList, -}); + }, + useShadowDom, + privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", + termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", + defaultToSignUp, + disableAuthRoute: testContext.disableDefaultUI, + recipeList, + }); +} /* App */ function App() { diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 071ada40f..62a6158f7 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -449,53 +449,55 @@ if (testContext.enableMFA) { ); } -SuperTokens.init({ - usesDynamicLoginMethods: testContext.usesDynamicLoginMethods, - clientType: testContext.clientType, - appInfo: { - appName: "SuperTokens", - websiteDomain: getWebsiteDomain(), - apiDomain: getApiDomain(), - websiteBasePath, - }, - languageTranslations: { - translations: { - en: { - AUTH_PAGE_FOOTER_TOS: "TOS", - }, - hu: { - AUTH_PAGE_FOOTER_TOS: "ÁSZF", +if (!window.location.pathname.startsWith("/mockProvider")) { + SuperTokens.init({ + usesDynamicLoginMethods: testContext.usesDynamicLoginMethods, + clientType: testContext.clientType, + appInfo: { + appName: "SuperTokens", + websiteDomain: getWebsiteDomain(), + apiDomain: getApiDomain(), + websiteBasePath, + }, + languageTranslations: { + translations: { + en: { + AUTH_PAGE_FOOTER_TOS: "TOS", + }, + hu: { + AUTH_PAGE_FOOTER_TOS: "ÁSZF", + }, }, }, - }, - getRedirectionURL: (context) => { - if (context.action === "SUCCESS") { - let logId = { - emailpassword: "EMAIL_PASSWORD", - thirdparty: "THIRD_PARTY", - passwordless: "PASSWORDLESS", - thirdpartypasswordless: "THIRDPARTYPASSWORDLESS", - thirdpartyemailpassword: "THIRD_PARTY_EMAIL_PASSWORD", - }[context.recipeId]; - - console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`); - setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser); - if (testContext.disableRedirectionAfterSuccessfulSignInUp) { - return null; + getRedirectionURL: (context) => { + if (context.action === "SUCCESS") { + let logId = { + emailpassword: "EMAIL_PASSWORD", + thirdparty: "THIRD_PARTY", + passwordless: "PASSWORDLESS", + thirdpartypasswordless: "THIRDPARTYPASSWORDLESS", + thirdpartyemailpassword: "THIRD_PARTY_EMAIL_PASSWORD", + }[context.recipeId]; + + console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`); + setIsNewUserToStorage(context.recipeId, context.isNewRecipeUser); + if (testContext.disableRedirectionAfterSuccessfulSignInUp) { + return null; + } + console.log(JSON.stringify(context)); + return context.redirectToPath || "/dashboard"; + } else { + console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`); } - console.log(JSON.stringify(context)); - return context.redirectToPath || "/dashboard"; - } else { - console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL ${context.action}`); - } - }, - useShadowDom, - privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", - termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", - defaultToSignUp, - disableAuthRoute: testContext.disableDefaultUI, - recipeList, -}); + }, + useShadowDom, + privacyPolicyLink: "https://supertokens.com/legal/privacy-policy", + termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions", + defaultToSignUp, + disableAuthRoute: testContext.disableDefaultUI, + recipeList, + }); +} /* App */ function App() { diff --git a/test/end-to-end/generalerror.test.js b/test/end-to-end/generalerror.test.js index 10160aebd..7d19105be 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, @@ -411,7 +411,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) && @@ -436,10 +436,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 fa0304c82..6a5c6a835 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, @@ -119,9 +119,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")); @@ -178,9 +178,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")); @@ -368,9 +368,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")); @@ -668,10 +668,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 ), @@ -680,7 +680,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 210a6864c..8722ce3c2 100644 --- a/test/end-to-end/multitenancy.dynamic_login_methods.test.js +++ b/test/end-to-end/multitenancy.dynamic_login_methods.test.js @@ -34,12 +34,13 @@ import { loginWithGoogle, clearBrowserCookiesWithoutAffectingConsole, clickOnProviderButton, - loginWithAuth0, + loginWithMockProvider, isMultitenancySupported, isMultitenancyManagementEndpointsSupported, setupTenant, backendBeforeEach, getTextByDataSupertokens, + 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 dac9a98b1..2000051b9 100644 --- a/test/end-to-end/thirdparty.test.js +++ b/test/end-to-end/thirdparty.test.js @@ -26,13 +26,14 @@ import { assertNoSTComponents, generateState, clickOnProviderButton, - loginWithAuth0, + loginWithMockProvider, getGeneralError, waitFor, screenshotOnFailure, clickOnProviderButtonWithoutWaiting, backendBeforeEach, waitForUrl, + loginWithAuth0, } from "../helpers"; import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL, SIGN_IN_UP_API, GET_AUTH_URL_API } from "../constants"; @@ -139,37 +140,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( @@ -179,39 +180,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"); @@ -243,29 +244,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"); @@ -356,8 +357,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"); }); @@ -392,8 +393,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 ae102d88d..9638051d8 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, @@ -286,11 +286,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"); @@ -341,10 +341,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 80fc4c485..e0b883357 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, @@ -141,10 +141,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 3903415c8..4aa08da60 100644 --- a/test/end-to-end/userContext.test.js +++ b/test/end-to-end/userContext.test.js @@ -23,9 +23,10 @@ import { submitFormReturnRequestAndResponse, assertProviders, clickOnProviderButton, - loginWithAuth0, + loginWithMockProvider, backendBeforeEach, waitForUrl, + loginWithAuth0, } from "../helpers"; import { TEST_CLIENT_BASE_URL, diff --git a/test/helpers.js b/test/helpers.js index 4cbaf99d3..39a1e046c 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -622,6 +622,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 +) { + const url = new URL(page.url()); + 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" }), + ]); +} + export async function loginWithAuth0(page) { await page.focus("input[type=email]"); await page.keyboard.type(process.env.AUTH0_EMAIL);