From e61cff5c772231a712c7dbf60253c93afc04d431 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Wed, 12 Jul 2023 11:13:36 +0530 Subject: [PATCH] fix: test fixes (#630) * fix: test fixes * fix: claims build * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: tests * fix: cleanup * fix: tests * fix: tests * fix: pr comments --- lib/build/recipe/dashboard/utils.d.ts | 4 - lib/build/recipe/dashboard/utils.js | 72 +---- lib/build/recipe/emailpassword/index.d.ts | 2 +- lib/build/recipe/passwordless/index.d.ts | 2 +- lib/build/recipe/session/sessionClass.js | 2 +- .../recipe/session/sessionRequestFunctions.js | 2 +- .../recipe/thirdpartyemailpassword/index.d.ts | 2 +- .../recipe/thirdpartypasswordless/index.d.ts | 2 +- .../recipe/thirdpartypasswordless/types.d.ts | 2 +- lib/build/recipeModule.js | 7 +- lib/build/supertokens.js | 9 +- lib/ts/recipe/dashboard/utils.ts | 105 +------ lib/ts/recipe/session/sessionClass.ts | 2 +- .../recipe/session/sessionRequestFunctions.ts | 2 +- lib/ts/recipe/thirdpartypasswordless/types.ts | 2 +- lib/ts/recipeModule.ts | 5 +- lib/ts/supertokens.ts | 5 +- test/emailpassword/emailDelivery.test.js | 97 ++----- test/emailpassword/emailverify.test.js | 105 +++++-- test/emailpassword/passwordreset.test.js | 37 ++- test/framework/awsLambda.test.js | 109 +++++--- test/framework/fastify.test.js | 118 +++++--- test/framework/hapi.test.js | 118 +++++--- test/framework/koa.test.js | 118 +++++--- test/framework/loopback.test.js | 109 +++++--- test/import.test.js | 9 +- test/nextjs.test.js | 50 ++-- test/passwordless/apis.test.js | 251 +++++++++++++---- test/passwordless/config.test.js | 264 ++++++++++++------ test/passwordless/emailDelivery.test.js | 38 +-- test/passwordless/smsDelivery.test.js | 38 +-- test/recipeModuleManager.test.js | 4 +- test/session.test.js | 13 +- test/session/claims/removeClaim.test.js | 6 +- test/session/claims/setClaimValue.test.js | 6 +- test/sessionExpress.test.js | 2 +- .../emailDelivery.test.js | 142 ++-------- .../emailverify.test.js | 20 +- test/thirdpartypasswordless/api.test.js | 133 ++++++--- test/thirdpartypasswordless/config.test.js | 205 +++++++++----- .../emailDelivery.test.js | 167 ++--------- .../recipeFunctions.test.js | 30 +- .../smsDelivery.test.js | 27 +- test/userContext.test.js | 6 +- test/utils.js | 2 +- 45 files changed, 1342 insertions(+), 1109 deletions(-) diff --git a/lib/build/recipe/dashboard/utils.d.ts b/lib/build/recipe/dashboard/utils.d.ts index d25d7166a..46510227d 100644 --- a/lib/build/recipe/dashboard/utils.d.ts +++ b/lib/build/recipe/dashboard/utils.d.ts @@ -1,7 +1,5 @@ // @ts-nocheck import { BaseRequest, BaseResponse } from "../../framework"; -import NormalisedURLPath from "../../normalisedURLPath"; -import { HTTPMethod } from "../../types"; import { EmailPasswordUser, PasswordlessUser, @@ -11,8 +9,6 @@ import { TypeNormalisedInput, } from "./types"; export declare function validateAndNormaliseUserInput(config?: TypeInput): TypeNormalisedInput; -export declare function isApiPath(path: NormalisedURLPath, basePath: NormalisedURLPath): boolean; -export declare function getApiIdIfMatched(path: NormalisedURLPath, method: HTTPMethod): string | undefined; export declare function sendUnauthorisedAccess(res: BaseResponse): void; export declare function isValidRecipeId(recipeId: string): recipeId is RecipeIdForUser; export declare function getUserForRecipeId( diff --git a/lib/build/recipe/dashboard/utils.js b/lib/build/recipe/dashboard/utils.js index d01805fd8..2927cc4ea 100644 --- a/lib/build/recipe/dashboard/utils.js +++ b/lib/build/recipe/dashboard/utils.js @@ -50,8 +50,7 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getApiPathWithDashboardBase = exports.validateApiKey = exports.isRecipeInitialised = exports.getUserForRecipeId = exports.isValidRecipeId = exports.sendUnauthorisedAccess = exports.getApiIdIfMatched = exports.isApiPath = exports.validateAndNormaliseUserInput = void 0; -const normalisedURLPath_1 = __importDefault(require("../../normalisedURLPath")); +exports.getApiPathWithDashboardBase = exports.validateApiKey = exports.isRecipeInitialised = exports.getUserForRecipeId = exports.isValidRecipeId = exports.sendUnauthorisedAccess = exports.validateAndNormaliseUserInput = void 0; const utils_1 = require("../../utils"); const constants_1 = require("./constants"); const recipe_1 = __importDefault(require("../emailpassword/recipe")); @@ -78,75 +77,6 @@ function validateAndNormaliseUserInput(config) { }); } exports.validateAndNormaliseUserInput = validateAndNormaliseUserInput; -function isApiPath(path, basePath) { - const dashboardRecipeBasePath = basePath.appendPath(new normalisedURLPath_1.default(constants_1.DASHBOARD_API)); - if (!path.startsWith(dashboardRecipeBasePath)) { - return false; - } - let pathWithoutDashboardPath = path.getAsStringDangerous().split(constants_1.DASHBOARD_API)[1]; - if (pathWithoutDashboardPath.charAt(0) === "/") { - pathWithoutDashboardPath = pathWithoutDashboardPath.substring(1, pathWithoutDashboardPath.length); - } - if (pathWithoutDashboardPath.split("/")[0] === "api") { - return true; - } - return false; -} -exports.isApiPath = isApiPath; -function getApiIdIfMatched(path, method) { - if (path.getAsStringDangerous().endsWith(constants_1.VALIDATE_KEY_API) && method === "post") { - return constants_1.VALIDATE_KEY_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.SIGN_IN_API) && method === "post") { - return constants_1.SIGN_IN_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.SIGN_OUT_API) && method === "post") { - return constants_1.SIGN_OUT_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.USERS_LIST_GET_API) && method === "get") { - return constants_1.USERS_LIST_GET_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.USERS_COUNT_API) && method === "get") { - return constants_1.USERS_COUNT_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.USER_API)) { - if (method === "get" || method === "delete" || method === "put") { - return constants_1.USER_API; - } - } - if (path.getAsStringDangerous().endsWith(constants_1.USER_EMAIL_VERIFY_API)) { - if (method === "get" || method === "put") { - return constants_1.USER_EMAIL_VERIFY_API; - } - } - if (path.getAsStringDangerous().endsWith(constants_1.USER_METADATA_API)) { - if (method === "get" || method === "put") { - return constants_1.USER_METADATA_API; - } - } - if (path.getAsStringDangerous().endsWith(constants_1.USER_SESSIONS_API)) { - if (method === "get" || method === "post") { - return constants_1.USER_SESSIONS_API; - } - } - if (path.getAsStringDangerous().endsWith(constants_1.USER_PASSWORD_API) && method === "put") { - return constants_1.USER_PASSWORD_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.USER_EMAIL_VERIFY_TOKEN_API) && method === "post") { - return constants_1.USER_EMAIL_VERIFY_TOKEN_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.USER_PASSWORD_API) && method === "put") { - return constants_1.USER_PASSWORD_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.SEARCH_TAGS_API) && method === "get") { - return constants_1.SEARCH_TAGS_API; - } - if (path.getAsStringDangerous().endsWith(constants_1.DASHBOARD_ANALYTICS_API) && method === "post") { - return constants_1.DASHBOARD_ANALYTICS_API; - } - return undefined; -} -exports.getApiIdIfMatched = getApiIdIfMatched; function sendUnauthorisedAccess(res) { utils_1.sendNon200ResponseWithMessage(res, "Unauthorised access", 401); } diff --git a/lib/build/recipe/emailpassword/index.d.ts b/lib/build/recipe/emailpassword/index.d.ts index b230b3a82..25d559129 100644 --- a/lib/build/recipe/emailpassword/index.d.ts +++ b/lib/build/recipe/emailpassword/index.d.ts @@ -71,7 +71,7 @@ export default class Wrapper { tenantIdForPasswordPolicy?: string; }): Promise< | { - status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; + status: "OK" | "EMAIL_ALREADY_EXISTS_ERROR" | "UNKNOWN_USER_ID_ERROR"; } | { status: "PASSWORD_POLICY_VIOLATED_ERROR"; diff --git a/lib/build/recipe/passwordless/index.d.ts b/lib/build/recipe/passwordless/index.d.ts index caf1e86be..6e5fde2f5 100644 --- a/lib/build/recipe/passwordless/index.d.ts +++ b/lib/build/recipe/passwordless/index.d.ts @@ -98,7 +98,7 @@ export default class Wrapper { phoneNumber?: string | null; userContext?: any; }): Promise<{ - status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR" | "PHONE_NUMBER_ALREADY_EXISTS_ERROR"; + status: "OK" | "EMAIL_ALREADY_EXISTS_ERROR" | "UNKNOWN_USER_ID_ERROR" | "PHONE_NUMBER_ALREADY_EXISTS_ERROR"; }>; static revokeAllCodes( input: diff --git a/lib/build/recipe/session/sessionClass.js b/lib/build/recipe/session/sessionClass.js index 65b9d1b44..f38bee793 100644 --- a/lib/build/recipe/session/sessionClass.js +++ b/lib/build/recipe/session/sessionClass.js @@ -281,7 +281,7 @@ class Session { // Any update to this function should also be reflected in the respective JWT version fetchAndSetClaim(claim, userContext) { return __awaiter(this, void 0, void 0, function* () { - const update = yield claim.build(this.getUserId(userContext), userContext); + const update = yield claim.build(this.getUserId(userContext), this.getTenantId(), userContext); return this.mergeIntoAccessTokenPayload(update, userContext); }); } diff --git a/lib/build/recipe/session/sessionRequestFunctions.js b/lib/build/recipe/session/sessionRequestFunctions.js index d32db1fca..5ab36ca75 100644 --- a/lib/build/recipe/session/sessionRequestFunctions.js +++ b/lib/build/recipe/session/sessionRequestFunctions.js @@ -338,7 +338,7 @@ function createNewSessionInRequest({ const issuer = appInfo.apiDomain.getAsStringDangerous() + appInfo.apiBasePath.getAsStringDangerous(); let finalAccessTokenPayload = Object.assign(Object.assign({}, accessTokenPayload), { iss: issuer }); for (const claim of claimsAddedByOtherRecipes) { - const update = yield claim.build(userId, userContext); + const update = yield claim.build(userId, tenantId, userContext); finalAccessTokenPayload = Object.assign(Object.assign({}, finalAccessTokenPayload), update); } logger_1.logDebugMessage("createNewSession: Access token payload built"); diff --git a/lib/build/recipe/thirdpartyemailpassword/index.d.ts b/lib/build/recipe/thirdpartyemailpassword/index.d.ts index 62a4f7ca8..b0638f1fb 100644 --- a/lib/build/recipe/thirdpartyemailpassword/index.d.ts +++ b/lib/build/recipe/thirdpartyemailpassword/index.d.ts @@ -100,7 +100,7 @@ export default class Wrapper { tenantIdForPasswordPolicy?: string; }): Promise< | { - status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; + status: "OK" | "EMAIL_ALREADY_EXISTS_ERROR" | "UNKNOWN_USER_ID_ERROR"; } | { status: "PASSWORD_POLICY_VIOLATED_ERROR"; diff --git a/lib/build/recipe/thirdpartypasswordless/index.d.ts b/lib/build/recipe/thirdpartypasswordless/index.d.ts index 6736dbad2..3709b8d4d 100644 --- a/lib/build/recipe/thirdpartypasswordless/index.d.ts +++ b/lib/build/recipe/thirdpartypasswordless/index.d.ts @@ -127,7 +127,7 @@ export default class Wrapper { phoneNumber?: string | null; userContext?: any; }): Promise<{ - status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR" | "PHONE_NUMBER_ALREADY_EXISTS_ERROR"; + status: "OK" | "EMAIL_ALREADY_EXISTS_ERROR" | "UNKNOWN_USER_ID_ERROR" | "PHONE_NUMBER_ALREADY_EXISTS_ERROR"; }>; static revokeAllCodes( input: diff --git a/lib/build/recipe/thirdpartypasswordless/types.d.ts b/lib/build/recipe/thirdpartypasswordless/types.d.ts index fec3217a3..d27303681 100644 --- a/lib/build/recipe/thirdpartypasswordless/types.d.ts +++ b/lib/build/recipe/thirdpartypasswordless/types.d.ts @@ -67,7 +67,7 @@ export declare type TypeInput = ( smsDelivery?: SmsDeliveryTypeInput; providers?: ProviderInput[]; flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; override?: { functions?: ( originalImplementation: RecipeInterface, diff --git a/lib/build/recipeModule.js b/lib/build/recipeModule.js index 60efb3097..708f3ea09 100644 --- a/lib/build/recipeModule.js +++ b/lib/build/recipeModule.js @@ -52,7 +52,6 @@ var __importDefault = Object.defineProperty(exports, "__esModule", { value: true }); const normalisedURLPath_1 = __importDefault(require("./normalisedURLPath")); const constants_1 = require("./recipe/multitenancy/constants"); -const recipe_1 = __importDefault(require("./recipe/multitenancy/recipe")); class RecipeModule { constructor(recipeId, appInfo) { this.getRecipeId = () => { @@ -74,7 +73,11 @@ class RecipeModule { tenantId = match[1]; remainingPath = new normalisedURLPath_1.default(match[2]); } - const mtRecipe = recipe_1.default.getInstanceOrThrowError(); + // Multitenancy recipe is an always initialized recipe and needs to be imported this way + // so that there is no circular dependency. Otherwise there would be cyclic dependency + // between `supertokens.ts` -> `recipeModule.ts` -> `multitenancy/recipe.ts` + let MultitenancyRecipe = require("./recipe/multitenancy/recipe").default; + const mtRecipe = MultitenancyRecipe.getInstanceOrThrowError(); for (let i = 0; i < apisHandled.length; i++) { let currAPI = apisHandled[i]; if (!currAPI.disabled && currAPI.method === method) { diff --git a/lib/build/supertokens.js b/lib/build/supertokens.js index 104c7895a..a93f1f1b7 100644 --- a/lib/build/supertokens.js +++ b/lib/build/supertokens.js @@ -58,7 +58,6 @@ const normalisedURLPath_1 = __importDefault(require("./normalisedURLPath")); const error_1 = __importDefault(require("./error")); const logger_1 = require("./logger"); const postSuperTokensInitCallbacks_1 = require("./postSuperTokensInitCallbacks"); -const recipe_1 = __importDefault(require("./recipe/multitenancy/recipe")); const constants_2 = require("./recipe/multitenancy/constants"); class SuperTokens { constructor(config) { @@ -391,15 +390,19 @@ class SuperTokens { } this.isInServerlessEnv = config.isInServerlessEnv === undefined ? false : config.isInServerlessEnv; let multitenancyFound = false; + // Multitenancy recipe is an always initialized recipe and needs to be imported this way + // so that there is no circular dependency. Otherwise there would be cyclic dependency + // between `supertokens.ts` -> `recipeModule.ts` -> `multitenancy/recipe.ts` + let MultitenancyRecipe = require("./recipe/multitenancy/recipe").default; this.recipeModules = config.recipeList.map((func) => { const recipeModule = func(this.appInfo, this.isInServerlessEnv); - if (recipeModule.getRecipeId() === recipe_1.default.RECIPE_ID) { + if (recipeModule.getRecipeId() === MultitenancyRecipe.RECIPE_ID) { multitenancyFound = true; } return recipeModule; }); if (!multitenancyFound) { - this.recipeModules.push(recipe_1.default.init()(this.appInfo, this.isInServerlessEnv)); + this.recipeModules.push(MultitenancyRecipe.init()(this.appInfo, this.isInServerlessEnv)); } this.telemetryEnabled = config.telemetry === undefined ? process.env.TEST_MODE !== "testing" : config.telemetry; } diff --git a/lib/ts/recipe/dashboard/utils.ts b/lib/ts/recipe/dashboard/utils.ts index ecb98cd67..9d4b7c418 100644 --- a/lib/ts/recipe/dashboard/utils.ts +++ b/lib/ts/recipe/dashboard/utils.ts @@ -14,25 +14,8 @@ */ import { BaseRequest, BaseResponse } from "../../framework"; -import NormalisedURLPath from "../../normalisedURLPath"; -import { HTTPMethod } from "../../types"; import { sendNon200ResponseWithMessage } from "../../utils"; -import { - DASHBOARD_API, - SEARCH_TAGS_API, - SIGN_IN_API, - SIGN_OUT_API, - USERS_COUNT_API, - USERS_LIST_GET_API, - USER_API, - USER_EMAIL_VERIFY_API, - USER_EMAIL_VERIFY_TOKEN_API, - USER_METADATA_API, - USER_PASSWORD_API, - USER_SESSIONS_API, - VALIDATE_KEY_API, - DASHBOARD_ANALYTICS_API, -} from "./constants"; +import { DASHBOARD_API } from "./constants"; import { APIInterface, EmailPasswordUser, @@ -68,92 +51,6 @@ export function validateAndNormaliseUserInput(config?: TypeInput): TypeNormalise }; } -export function isApiPath(path: NormalisedURLPath, basePath: NormalisedURLPath): boolean { - const dashboardRecipeBasePath = basePath.appendPath(new NormalisedURLPath(DASHBOARD_API)); - if (!path.startsWith(dashboardRecipeBasePath)) { - return false; - } - - let pathWithoutDashboardPath = path.getAsStringDangerous().split(DASHBOARD_API)[1]; - - if (pathWithoutDashboardPath.charAt(0) === "/") { - pathWithoutDashboardPath = pathWithoutDashboardPath.substring(1, pathWithoutDashboardPath.length); - } - - if (pathWithoutDashboardPath.split("/")[0] === "api") { - return true; - } - - return false; -} - -export function getApiIdIfMatched(path: NormalisedURLPath, method: HTTPMethod): string | undefined { - if (path.getAsStringDangerous().endsWith(VALIDATE_KEY_API) && method === "post") { - return VALIDATE_KEY_API; - } - - if (path.getAsStringDangerous().endsWith(SIGN_IN_API) && method === "post") { - return SIGN_IN_API; - } - - if (path.getAsStringDangerous().endsWith(SIGN_OUT_API) && method === "post") { - return SIGN_OUT_API; - } - - if (path.getAsStringDangerous().endsWith(USERS_LIST_GET_API) && method === "get") { - return USERS_LIST_GET_API; - } - - if (path.getAsStringDangerous().endsWith(USERS_COUNT_API) && method === "get") { - return USERS_COUNT_API; - } - - if (path.getAsStringDangerous().endsWith(USER_API)) { - if (method === "get" || method === "delete" || method === "put") { - return USER_API; - } - } - - if (path.getAsStringDangerous().endsWith(USER_EMAIL_VERIFY_API)) { - if (method === "get" || method === "put") { - return USER_EMAIL_VERIFY_API; - } - } - - if (path.getAsStringDangerous().endsWith(USER_METADATA_API)) { - if (method === "get" || method === "put") { - return USER_METADATA_API; - } - } - - if (path.getAsStringDangerous().endsWith(USER_SESSIONS_API)) { - if (method === "get" || method === "post") { - return USER_SESSIONS_API; - } - } - - if (path.getAsStringDangerous().endsWith(USER_PASSWORD_API) && method === "put") { - return USER_PASSWORD_API; - } - - if (path.getAsStringDangerous().endsWith(USER_EMAIL_VERIFY_TOKEN_API) && method === "post") { - return USER_EMAIL_VERIFY_TOKEN_API; - } - - if (path.getAsStringDangerous().endsWith(USER_PASSWORD_API) && method === "put") { - return USER_PASSWORD_API; - } - if (path.getAsStringDangerous().endsWith(SEARCH_TAGS_API) && method === "get") { - return SEARCH_TAGS_API; - } - - if (path.getAsStringDangerous().endsWith(DASHBOARD_ANALYTICS_API) && method === "post") { - return DASHBOARD_ANALYTICS_API; - } - - return undefined; -} - export function sendUnauthorisedAccess(res: BaseResponse) { sendNon200ResponseWithMessage(res, "Unauthorised access", 401); } diff --git a/lib/ts/recipe/session/sessionClass.ts b/lib/ts/recipe/session/sessionClass.ts index d250b3b4f..76f61c776 100644 --- a/lib/ts/recipe/session/sessionClass.ts +++ b/lib/ts/recipe/session/sessionClass.ts @@ -232,7 +232,7 @@ export default class Session implements SessionContainerInterface { // Any update to this function should also be reflected in the respective JWT version async fetchAndSetClaim(claim: SessionClaim, userContext?: any): Promise { - const update = await claim.build(this.getUserId(userContext), userContext); + const update = await claim.build(this.getUserId(userContext), this.getTenantId(), userContext); return this.mergeIntoAccessTokenPayload(update, userContext); } diff --git a/lib/ts/recipe/session/sessionRequestFunctions.ts b/lib/ts/recipe/session/sessionRequestFunctions.ts index 4e2533b96..c1f52cdbb 100644 --- a/lib/ts/recipe/session/sessionRequestFunctions.ts +++ b/lib/ts/recipe/session/sessionRequestFunctions.ts @@ -357,7 +357,7 @@ export async function createNewSessionInRequest({ }; for (const claim of claimsAddedByOtherRecipes) { - const update = await claim.build(userId, userContext); + const update = await claim.build(userId, tenantId, userContext); finalAccessTokenPayload = { ...finalAccessTokenPayload, ...update, diff --git a/lib/ts/recipe/thirdpartypasswordless/types.ts b/lib/ts/recipe/thirdpartypasswordless/types.ts index 2ab87b256..c3144df30 100644 --- a/lib/ts/recipe/thirdpartypasswordless/types.ts +++ b/lib/ts/recipe/thirdpartypasswordless/types.ts @@ -88,7 +88,7 @@ export type TypeInput = ( // Override this to override how user input codes are generated // By default (=undefined) it is done in the Core - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; override?: { functions?: ( originalImplementation: RecipeInterface, diff --git a/lib/ts/recipeModule.ts b/lib/ts/recipeModule.ts index 2aacff54b..73a665a88 100644 --- a/lib/ts/recipeModule.ts +++ b/lib/ts/recipeModule.ts @@ -18,7 +18,6 @@ import { NormalisedAppinfo, APIHandled, HTTPMethod } from "./types"; import NormalisedURLPath from "./normalisedURLPath"; import { BaseRequest, BaseResponse } from "./framework"; import { DEFAULT_TENANT_ID } from "./recipe/multitenancy/constants"; -import MultitenancyRecipe from "./recipe/multitenancy/recipe"; export default abstract class RecipeModule { private recipeId: string; @@ -58,6 +57,10 @@ export default abstract class RecipeModule { remainingPath = new NormalisedURLPath(match[2]); } + // Multitenancy recipe is an always initialized recipe and needs to be imported this way + // so that there is no circular dependency. Otherwise there would be cyclic dependency + // between `supertokens.ts` -> `recipeModule.ts` -> `multitenancy/recipe.ts` + let MultitenancyRecipe = require("./recipe/multitenancy/recipe").default; const mtRecipe = MultitenancyRecipe.getInstanceOrThrowError(); for (let i = 0; i < apisHandled.length; i++) { diff --git a/lib/ts/supertokens.ts b/lib/ts/supertokens.ts index 39a34597e..4f2f2dd80 100644 --- a/lib/ts/supertokens.ts +++ b/lib/ts/supertokens.ts @@ -31,7 +31,6 @@ import { TypeFramework } from "./framework/types"; import STError from "./error"; import { logDebugMessage } from "./logger"; import { PostSuperTokensInitCallbacks } from "./postSuperTokensInitCallbacks"; -import MultitenancyRecipe from "./recipe/multitenancy/recipe"; import { DEFAULT_TENANT_ID } from "./recipe/multitenancy/constants"; export default class SuperTokens { @@ -83,6 +82,10 @@ export default class SuperTokens { this.isInServerlessEnv = config.isInServerlessEnv === undefined ? false : config.isInServerlessEnv; let multitenancyFound = false; + // Multitenancy recipe is an always initialized recipe and needs to be imported this way + // so that there is no circular dependency. Otherwise there would be cyclic dependency + // between `supertokens.ts` -> `recipeModule.ts` -> `multitenancy/recipe.ts` + let MultitenancyRecipe = require("./recipe/multitenancy/recipe").default; this.recipeModules = config.recipeList.map((func) => { const recipeModule = func(this.appInfo, this.isInServerlessEnv); if (recipeModule.getRecipeId() === MultitenancyRecipe.RECIPE_ID) { diff --git a/test/emailpassword/emailDelivery.test.js b/test/emailpassword/emailDelivery.test.js index 0205da7cb..2daea84cc 100644 --- a/test/emailpassword/emailDelivery.test.js +++ b/test/emailpassword/emailDelivery.test.js @@ -167,11 +167,13 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }, recipeList: [ EmailPassword.init({ - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: async (input, passwordResetLink) => { - email = input.email; - passwordResetURL = passwordResetLink; - timeJoined = input.timeJoined; + emailDelivery: { + service: { + sendEmail: async (input) => { + email = input.user.email; + passwordResetURL = input.passwordResetLink; + timeJoined = input.user.timeJoined; + }, }, }, }), @@ -219,9 +221,11 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }, recipeList: [ EmailPassword.init({ - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: async (input, passwordResetLink) => { - functionCalled = true; + emailDelivery: { + service: { + sendEmail: async (input) => { + functionCalled = true; + }, }, }, }), @@ -570,10 +574,14 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }, recipeList: [ EmailVerification.init({ - createAndSendCustomEmail: async (input, emailVerificationURLWithToken) => { - email = input.email; - userIdInCb = input.id; - emailVerifyURL = emailVerificationURLWithToken; + emailDelivery: { + service: { + sendEmail: async (input) => { + email = input.user.email; + userIdInCb = input.user.id; + emailVerifyURL = input.emailVerifyLink; + }, + }, }, }), EmailPassword.init(), @@ -772,69 +780,4 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] assert(sendRawEmailCalled); assert.notStrictEqual(emailVerifyURL, undefined); }); - - it("test backward compatibility: reset password and sendEmail override", async function () { - await startST(); - let email = undefined; - let passwordResetURL = undefined; - let timeJoined = undefined; - STExpress.init({ - supertokens: { - connectionURI: "http://localhost:8080", - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - EmailPassword.init({ - emailDelivery: { - override: (oI) => { - return { - ...oI, - sendEmail: async function (input) { - input.user.email = "override@example.com"; - return oI.sendEmail(input); - }, - }; - }, - }, - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: async (input, passwordResetLink) => { - email = input.email; - passwordResetURL = passwordResetLink; - timeJoined = input.timeJoined; - }, - }, - }), - Session.init(), - ], - telemetry: false, - }); - - const app = express(); - app.use(middleware()); - app.use(errorHandler()); - - await EmailPassword.signUp("test@example.com", "1234abcd"); - - await supertest(app) - .post("/auth/user/password/reset/token") - .set("rid", "emailpassword") - .send({ - formFields: [ - { - id: "email", - value: "test@example.com", - }, - ], - }) - .expect(200); - - await delay(2); - assert.strictEqual(email, "override@example.com"); - assert.notStrictEqual(passwordResetURL, undefined); - assert.notStrictEqual(timeJoined, undefined); - }); }); diff --git a/test/emailpassword/emailverify.test.js b/test/emailpassword/emailverify.test.js index c9c4a58f9..906976acb 100644 --- a/test/emailpassword/emailverify.test.js +++ b/test/emailpassword/emailverify.test.js @@ -38,11 +38,6 @@ const express = require("express"); const request = require("supertest"); let { middleware, errorHandler } = require("../../framework/express"); -/** - * TODO: (later) in emailVerificationFunctions.ts: - * - (later) check that createAndSendCustomEmail works fine - */ - describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}`, function () { beforeEach(async function () { await killAllST(); @@ -282,9 +277,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - userInfo = user; - emailToken = emailVerificationURLWithToken; + emailDelivery: { + service: { + sendEmail: async (input) => { + userInfo = input.user; + emailToken = input.emailVerifyLink; + }, + }, }, }), EmailPassword.init(), @@ -350,8 +349,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, }), EmailPassword.init({}), @@ -512,8 +516,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, override: { apis: (oI) => { @@ -596,8 +605,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, }), EmailPassword.init(), @@ -723,8 +737,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, }), EmailPassword.init(), @@ -840,8 +859,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, override: { apis: (oI) => { @@ -918,8 +942,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, override: { functions: (oI) => { @@ -996,8 +1025,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, override: { apis: (oI) => { @@ -1083,8 +1117,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` EmailPassword.init(), EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, override: { functions: (oI) => { @@ -1261,8 +1300,13 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` EmailPassword.init(), EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - token = emailVerificationURLWithToken.split("?token=")[1].split("&rid=")[0]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, }, }), Session.init({ @@ -1346,7 +1390,14 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` EmailPassword.init(), EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => {}, + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.emailVerifyLink).search); + token = searchParams.get("token"); + }, + }, + }, }), Session.init({ antiCsrf: "VIA_TOKEN", diff --git a/test/emailpassword/passwordreset.test.js b/test/emailpassword/passwordreset.test.js index f993d2d3e..2588509bd 100644 --- a/test/emailpassword/passwordreset.test.js +++ b/test/emailpassword/passwordreset.test.js @@ -33,8 +33,6 @@ let { middleware, errorHandler } = require("../../framework/express"); let { maxVersion } = require("../../lib/build/utils"); /** - * TODO: (later) in passwordResetFunctions.ts: - * - (later) check that createAndSendCustomEmail works fine * TODO: generate token API: * - (later) Call the createResetPasswordToken function with valid input * - (later) Call the createResetPasswordToken with unknown userId and test error thrown @@ -124,13 +122,24 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }, recipeList: [ EmailPassword.init({ - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: (user, passwordResetURLWithToken) => { - resetURL = passwordResetURLWithToken.split("?")[0]; - tokenInfo = passwordResetURLWithToken.split("?")[1].split("&")[0]; - ridInfo = passwordResetURLWithToken.split("?")[1].split("&")[1]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.passwordResetLink).search); + resetURL = input.passwordResetLink.split("?")[0]; + tokenInfo = searchParams.get("token"); + ridInfo = searchParams.get("rid"); + }, }, }, + // resetPasswordUsingTokenFeature: { + + // // createAndSendCustomEmail: (user, passwordResetURLWithToken) => { + // // resetURL = passwordResetURLWithToken.split("?")[0]; + // // tokenInfo = passwordResetURLWithToken.split("?")[1].split("&")[0]; + // // ridInfo = passwordResetURLWithToken.split("?")[1].split("&")[1]; + // // }, + // }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), ], @@ -166,8 +175,9 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }) ); assert(resetURL === "https://supertokens.io/auth/reset-password"); - assert(tokenInfo.startsWith("token=")); - assert(ridInfo.startsWith("rid=emailpassword")); + assert.notStrictEqual(tokenInfo, undefined); + assert.notStrictEqual(tokenInfo, null); + assert.strictEqual(ridInfo, "emailpassword"); }); /* @@ -360,9 +370,12 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }; }, }, - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: (user, passwordResetURLWithToken) => { - token = passwordResetURLWithToken.split("?")[1].split("&")[0].split("=")[1]; + emailDelivery: { + service: { + sendEmail: async (input) => { + const searchParams = new URLSearchParams(new URL(input.passwordResetLink).search); + token = searchParams.get("token"); + }, }, }, }), diff --git a/test/framework/awsLambda.test.js b/test/framework/awsLambda.test.js index a6fb35686..edc88585c 100644 --- a/test/framework/awsLambda.test.js +++ b/test/framework/awsLambda.test.js @@ -30,7 +30,6 @@ let Session = require("../../recipe/session"); let EmailPassword = require("../../recipe/emailpassword"); let Passwordless = require("../../recipe/passwordless"); let ThirdParty = require("../../recipe/thirdparty"); -let { Apple, Google, Github } = require("../../recipe/thirdparty"); let { verifySession } = require("../../recipe/session/framework/awsLambda"); let Dashboard = require("../../recipe/dashboard"); let { createUsers } = require("../utils"); @@ -1045,23 +1044,45 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], + }, + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], }, - }), + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], + }, + }, ], }, }), @@ -1133,23 +1154,45 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], + }, + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], }, - }), + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], + }, + }, ], }, }), diff --git a/test/framework/fastify.test.js b/test/framework/fastify.test.js index 0f329b26d..167dcd800 100644 --- a/test/framework/fastify.test.js +++ b/test/framework/fastify.test.js @@ -36,7 +36,6 @@ const { Querier } = require("../../lib/build/querier"); const { maxVersion } = require("../../lib/build/utils"); const Passwordless = require("../../recipe/passwordless"); const ThirdParty = require("../../recipe/thirdparty"); -const { Apple, Google, Github } = require("../../recipe/thirdparty"); describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function () { beforeEach(async function () { @@ -1143,7 +1142,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( assert(frontendInfo.uid === "user1"); assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 8); + assert.strictEqual(Object.keys(frontendInfo.up).length, 9); //call the updateAccessTokenPayload api to add jwt payload let updatedResponse = extractInfoFromResponse( @@ -1162,7 +1161,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.key, "value"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 9); + assert.strictEqual(Object.keys(frontendInfo.up).length, 10); //call the getAccessTokenPayload api to get jwt payload let response2 = await this.server.inject({ @@ -1193,7 +1192,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.key, "value"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 9); + assert.strictEqual(Object.keys(frontendInfo.up).length, 10); // change the value of the inserted jwt payload let updatedResponse2 = extractInfoFromResponse( @@ -1211,7 +1210,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( assert(frontendInfo.uid === "user1"); assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 8); + assert.strictEqual(Object.keys(frontendInfo.up).length, 9); //retrieve the changed jwt payload let response3 = await this.server.inject({ @@ -1235,6 +1234,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( "sessionHandle", "sub", "iss", + "tId", ]) ); //invalid session handle when updating the jwt payload @@ -1781,23 +1781,45 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], }, - }), + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], + }, + }, ], }, }), @@ -1860,23 +1882,45 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], + }, + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], }, - }), + }, ], }, }), diff --git a/test/framework/hapi.test.js b/test/framework/hapi.test.js index 854461d46..668ed8fac 100644 --- a/test/framework/hapi.test.js +++ b/test/framework/hapi.test.js @@ -28,7 +28,6 @@ const { Querier } = require("../../lib/build/querier"); const { maxVersion } = require("../../lib/build/utils"); const Passwordless = require("../../recipe/passwordless"); const ThirdParty = require("../../recipe/thirdparty"); -const { Apple, Google, Github } = require("../../recipe/thirdparty"); describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { beforeEach(async function () { @@ -1178,7 +1177,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { assert(frontendInfo.uid === "user1"); assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 8); + assert.strictEqual(Object.keys(frontendInfo.up).length, 9); //call the updateAccessTokenPayload api to add jwt payload let updatedResponse = extractInfoFromResponse( @@ -1197,7 +1196,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.key, "value"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 9); + assert.strictEqual(Object.keys(frontendInfo.up).length, 10); //call the getAccessTokenPayload api to get jwt payload let response2 = await this.server.inject({ @@ -1228,7 +1227,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.key, "value"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 9); + assert.strictEqual(Object.keys(frontendInfo.up).length, 10); // change the value of the inserted jwt payload let updatedResponse2 = extractInfoFromResponse( @@ -1246,7 +1245,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { assert(frontendInfo.uid === "user1"); assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 8); + assert.strictEqual(Object.keys(frontendInfo.up).length, 9); //retrieve the changed jwt payload let response3 = await this.server.inject({ @@ -1270,6 +1269,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { "sessionHandle", "sub", "iss", + "tId", ]) ); @@ -1796,23 +1796,45 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], }, - }), + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], + }, + }, ], }, }), @@ -1877,23 +1899,45 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], + }, + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], }, - }), + }, ], }, }), diff --git a/test/framework/koa.test.js b/test/framework/koa.test.js index c1e2f975c..02b610f48 100644 --- a/test/framework/koa.test.js +++ b/test/framework/koa.test.js @@ -29,7 +29,6 @@ const { Querier } = require("../../lib/build/querier"); const { maxVersion } = require("../../lib/build/utils"); const Passwordless = require("../../recipe/passwordless"); const ThirdParty = require("../../recipe/thirdparty"); -const { Google, Github, Apple } = require("../../recipe/thirdparty"); describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { beforeEach(async function () { @@ -1312,7 +1311,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { assert(frontendInfo.uid === "user1"); assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 8); + assert.strictEqual(Object.keys(frontendInfo.up).length, 9); //call the updateAccessTokenPayload api to add jwt payload let updatedResponse = extractInfoFromResponse( @@ -1337,7 +1336,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.key, "value"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 9); + assert.strictEqual(Object.keys(frontendInfo.up).length, 10); //call the getAccessTokenPayload api to get jwt payload let response2 = await new Promise((resolve) => @@ -1380,7 +1379,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.key, "value"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 9); + assert.strictEqual(Object.keys(frontendInfo.up).length, 10); // change the value of the inserted jwt payload let updatedResponse2 = extractInfoFromResponse( @@ -1404,7 +1403,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { assert(frontendInfo.uid === "user1"); assert.strictEqual(frontendInfo.up.sub, "user1"); assert.strictEqual(frontendInfo.up.exp, Math.floor(frontendInfo.ate / 1000)); - assert.strictEqual(Object.keys(frontendInfo.up).length, 8); + assert.strictEqual(Object.keys(frontendInfo.up).length, 9); //retrieve the changed jwt payload response2 = await new Promise((resolve) => @@ -1434,6 +1433,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { "sessionHandle", "sub", "iss", + "tId", ]) ); //invalid session handle when updating the jwt payload @@ -1975,23 +1975,45 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], }, - }), + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], + }, + }, ], }, }), @@ -2061,23 +2083,45 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], + }, + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], }, - }), + }, ], }, }), diff --git a/test/framework/loopback.test.js b/test/framework/loopback.test.js index 0ac544cc4..940011028 100644 --- a/test/framework/loopback.test.js +++ b/test/framework/loopback.test.js @@ -26,7 +26,6 @@ const { Querier } = require("../../lib/build/querier"); const { maxVersion } = require("../../lib/build/utils"); const Passwordless = require("../../recipe/passwordless"); const ThirdParty = require("../../recipe/thirdparty"); -const { Apple, Google, Github } = require("../../recipe/thirdparty"); const { default: fetch } = require("cross-fetch"); describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function () { @@ -668,23 +667,45 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], }, - }), + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], + }, + }, ], }, }), @@ -754,23 +775,45 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function ThirdParty.init({ signInAndUpFeature: { providers: [ - Google({ - clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", - clientSecret: "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", - }), - Github({ - clientId: "467101b197249757c71f", - clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", - }), - Apple({ - clientId: "4398792-io.supertokens.example.service", - clientSecret: { - keyId: "7M48Y4RYDL", - privateKey: - "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", - teamId: "YWQCXGJRJL", + { + config: { + thirdPartyId: "google", + clients: [ + { + clientId: + "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", + clientSecret: "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", + }, + ], + }, + }, + { + config: { + thirdPartyId: "github", + clients: [ + { + clientId: "467101b197249757c71f", + clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd", + }, + ], + }, + }, + { + config: { + thirdPartyId: "apple", + clients: [ + { + clientId: "4398792-io.supertokens.example.service", + additionalConfig: { + keyId: "7M48Y4RYDL", + privateKey: + "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----", + teamId: "YWQCXGJRJL", + }, + }, + ], }, - }), + }, ], }, }), diff --git a/test/import.test.js b/test/import.test.js index cc1997f92..d423be472 100644 --- a/test/import.test.js +++ b/test/import.test.js @@ -36,8 +36,13 @@ describe(`importTests: ${printPath("[test/import.test.js]")}`, function () { const relativeFilePath = fileName.replace(process.cwd(), ""); writeFileSync(testFilePath, `require(".${relativeFilePath}")`); - // This will throw an error if the command fails - execSync(`node ${resolve(process.cwd(), `./${testFileName}`)}`); + try { + // This will throw an error if the command fails + execSync(`node ${resolve(process.cwd(), `./${testFileName}`)}`); + } catch (err) { + console.log(`Testing file: ${relativeFilePath}`); + throw err; + } }); }); }); diff --git a/test/nextjs.test.js b/test/nextjs.test.js index 677f8da18..47e644495 100644 --- a/test/nextjs.test.js +++ b/test/nextjs.test.js @@ -491,33 +491,33 @@ describe(`NextJS Middleware Test: ${printPath("[test/nextjs.test.js]")}`, functi await testApiHandler({ handler: nextApiHandlerWithMiddleware, url: "/api/auth/callback/apple", - body: { - state: "eyJyZWRpcmVjdFVSSSI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMC9yZWRpcmVjdCJ9", - code: "testing", - }, - }); - - const response = httpMocks.createResponse({ - eventEmitter: require("events").EventEmitter, - }); - - response.on("end", () => { - assert.deepStrictEqual(Buffer.from(response._getData()).toString(), ""); - assert.deepStrictEqual(response._getStatusCode(), 303); - assert.deepStrictEqual( - response._getHeaders().location, - "http://localhost:3000/redirect?state=eyJyZWRpcmVjdFVSSSI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMC9yZWRpcmVjdCJ9&code=testing" - ); - return done(); - }); + test: async ({ fetch }) => { + let state = Buffer.from(JSON.stringify({ redirectURI: "http://localhost:3000/redirect" })).toString( + "base64" + ); + let formData = { state, code: "testing" }; + var encodedData = Object.keys(formData) + .map(function (key) { + return encodeURIComponent(key) + "=" + encodeURIComponent(formData[key]); + }) + .join("&"); - superTokensNextWrapper( - async (next) => { - return middleware()(request, response, next); + const res = await fetch({ + method: "POST", + headers: { + rid: "thirdpartyemailpassword", + "content-type": "application/x-www-form-urlencoded", + }, + body: encodedData, + redirect: "manual", + }); + assert.deepStrictEqual(res.status, 303); + assert.deepEqual( + res.headers.get("location"), + "http://localhost:3000/redirect?state=eyJyZWRpcmVjdFVSSSI6Imh0dHA6Ly9sb2NhbGhvc3Q6MzAwMC9yZWRpcmVjdCJ9&code=testing" + ); }, - request, - response - ); + }); }); }); diff --git a/test/passwordless/apis.test.js b/test/passwordless/apis.test.js index 962c6e87c..f3b1d0b7d 100644 --- a/test/passwordless/apis.test.js +++ b/test/passwordless/apis.test.js @@ -69,12 +69,20 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - userInputCode = input.userInputCode; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -164,12 +172,20 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - userInputCode = input.userInputCode; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, }), ], @@ -259,12 +275,20 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + isCreateAndSendCustomEmailCalled = true; + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - isCreateAndSendCustomEmailCalled = true; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -346,12 +370,20 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - isCreateAndSendCustomTextMessageCalled = true; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + isCreateAndSendCustomTextMessageCalled = true; + return; + }, + }, }, }), ], @@ -432,11 +464,19 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -535,13 +575,21 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - userInputCode = input.userInputCode; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - userInputCode = input.userInputCode; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, }), ], @@ -664,8 +712,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -724,8 +776,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -814,8 +870,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: () => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -933,8 +993,19 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, + }, + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1000,8 +1071,19 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, + }, + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1081,8 +1163,19 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, + }, + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1163,8 +1256,20 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - magicLinkURL = new URL(input.urlWithLinkCode); + emailDelivery: { + service: { + sendEmail: async (input) => { + magicLinkURL = new URL(input.urlWithLinkCode); + return; + }, + }, + }, + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1227,8 +1332,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -1316,8 +1425,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1407,8 +1520,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1491,8 +1608,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1531,8 +1652,12 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -1581,12 +1706,20 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + isCreateAndSendCustomEmailCalled = true; + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - isCreateAndSendCustomEmailCalled = true; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], diff --git a/test/passwordless/config.test.js b/test/passwordless/config.test.js index 16085d55e..d0c39b3d5 100644 --- a/test/passwordless/config.test.js +++ b/test/passwordless/config.test.js @@ -58,11 +58,19 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -110,11 +118,19 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun isValidatePhoneNumberCalled = true; return undefined; }, - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -200,12 +216,20 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - isCreateAndSendCustomEmailCalled = true; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + isCreateAndSendCustomEmailCalled = true; + return; + }, + }, }, - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -270,12 +294,20 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomTextMessage: (input) => { - isCreateAndSendCustomTextMessageCalled = true; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + isCreateAndSendCustomTextMessageCalled = true; + return; + }, + }, }, }), ], @@ -336,8 +368,12 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -377,10 +413,14 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, - validatePhoneNumber: (phoneNumber) => { + validatePhoneNumber: (phoneNumber, tenantId) => { isValidatePhoneNumberCalled = true; return undefined; }, @@ -443,10 +483,14 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, - validatePhoneNumber: (phoneNumber) => { + validatePhoneNumber: (phoneNumber, tenantId) => { isValidatePhoneNumberCalled = true; return "test error"; }, @@ -503,18 +547,22 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE", - createAndSendCustomTextMessage: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } - - if ( - typeof input.codeLifetime === "number" && - typeof input.phoneNumber === "string" && - typeof input.preAuthSessionId === "string" - ) { - isOtherInputValid = true; - } + smsDelivery: { + service: { + sendSms: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + + if ( + typeof input.codeLifetime === "number" && + typeof input.phoneNumber === "string" && + typeof input.preAuthSessionId === "string" + ) { + isOtherInputValid = true; + } + }, + }, }, }), ], @@ -575,10 +623,14 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "PHONE", flowType: "MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + smsDelivery: { + service: { + sendSms: async (input) => { + if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -637,10 +689,14 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + smsDelivery: { + service: { + sendSms: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -700,9 +756,13 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "PHONE", flowType: "MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - isCreateAndSendCustomTextMessageCalled = true; - throw new Error("test message"); + smsDelivery: { + service: { + sendSms: async (input) => { + isCreateAndSendCustomTextMessageCalled = true; + throw new Error("test message"); + }, + }, }, }), ], @@ -765,8 +825,12 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -807,8 +871,12 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, validateEmailAddress: (email) => { isValidateEmailAddressCalled = true; @@ -934,18 +1002,22 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE", - createAndSendCustomEmail: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } - - if ( - typeof input.codeLifetime === "number" && - typeof input.email === "string" && - typeof input.preAuthSessionId === "string" - ) { - isOtherInputValid = true; - } + emailDelivery: { + service: { + sendEmail: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + + if ( + typeof input.codeLifetime === "number" && + typeof input.email === "string" && + typeof input.preAuthSessionId === "string" + ) { + isOtherInputValid = true; + } + }, + }, }, }), ], @@ -1006,10 +1078,14 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "MAGIC_LINK", - createAndSendCustomEmail: (input) => { - if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + emailDelivery: { + service: { + sendEmail: async (input) => { + if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -1068,10 +1144,14 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + emailDelivery: { + service: { + sendEmail: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -1131,9 +1211,13 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "MAGIC_LINK", - createAndSendCustomEmail: (input) => { - isCreateAndSendCustomEmailCalled = true; - throw new Error("test message"); + emailDelivery: { + service: { + sendEmail: async (input) => { + isCreateAndSendCustomEmailCalled = true; + throw new Error("test message"); + }, + }, }, }), ], @@ -1269,12 +1353,16 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE", - getCustomUserInputCode: (input) => { + getCustomUserInputCode: (tenantId) => { customCode = generateRandomCode(5); return customCode; }, - createAndSendCustomEmail: (input) => { - userCodeSent = input.userInputCode; + emailDelivery: { + service: { + sendEmail: async (input) => { + userCodeSent = input.userInputCode; + }, + }, }, }), ], @@ -1355,11 +1443,15 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE", - getCustomUserInputCode: (input) => { + getCustomUserInputCode: (tenantId) => { return customCode; }, - createAndSendCustomEmail: (input) => { - userCodeSent = input.userInputCode; + emailDelivery: { + service: { + sendEmail: async (input) => { + userCodeSent = input.userInputCode; + }, + }, }, }), ], @@ -1443,8 +1535,12 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, override: { apis: (oI) => { diff --git a/test/passwordless/emailDelivery.test.js b/test/passwordless/emailDelivery.test.js index 0f59eb138..3dee4170e 100644 --- a/test/passwordless/emailDelivery.test.js +++ b/test/passwordless/emailDelivery.test.js @@ -125,11 +125,15 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: async (input) => { - email = input.email; - codeLifetime = input.codeLifetime; - urlWithLinkCode = input.urlWithLinkCode; - userInputCode = input.userInputCode; + emailDelivery: { + service: { + sendEmail: async (input) => { + email = input.email; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + }, + }, }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), @@ -523,18 +527,18 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" Passwordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: async (input) => { - /** - * when the function is called for the first time, - * it will be for signinup - */ - if (sendCustomEmailCalled) { - email = input.email; - codeLifetime = input.codeLifetime; - urlWithLinkCode = input.urlWithLinkCode; - userInputCode = input.userInputCode; - } - sendCustomEmailCalled = true; + emailDelivery: { + service: { + sendEmail: async (input) => { + if (sendCustomEmailCalled) { + email = input.email; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + } + sendCustomEmailCalled = true; + }, + }, }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), diff --git a/test/passwordless/smsDelivery.test.js b/test/passwordless/smsDelivery.test.js index 5a5afe333..55ad21cbe 100644 --- a/test/passwordless/smsDelivery.test.js +++ b/test/passwordless/smsDelivery.test.js @@ -129,11 +129,15 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: async (input) => { - phoneNumber = input.phoneNumber; - codeLifetime = input.codeLifetime; - urlWithLinkCode = input.urlWithLinkCode; - userInputCode = input.userInputCode; + smsDelivery: { + service: { + sendSms: async (input) => { + phoneNumber = input.phoneNumber; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + }, + }, }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), @@ -680,18 +684,18 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, Passwordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: async (input) => { - /** - * when the function is called for the first time, - * it will be for signinup - */ - if (sendCustomSMSCalled) { - phoneNumber = input.phoneNumber; - codeLifetime = input.codeLifetime; - urlWithLinkCode = input.urlWithLinkCode; - userInputCode = input.userInputCode; - } - sendCustomSMSCalled = true; + smsDelivery: { + service: { + sendSms: async (input) => { + if (sendCustomSMSCalled) { + phoneNumber = input.phoneNumber; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + } + sendCustomSMSCalled = true; + }, + }, }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), diff --git a/test/recipeModuleManager.test.js b/test/recipeModuleManager.test.js index 0f055c9c6..20d551bca 100644 --- a/test/recipeModuleManager.test.js +++ b/test/recipeModuleManager.test.js @@ -685,7 +685,7 @@ class TestRecipe extends RecipeModule { ]; } - async handleAPIRequest(id, req, res, next) { + async handleAPIRequest(id, tenantId, req, res, next) { if (id === "/") { res.setStatusCode(200); res.sendJSONResponse({ message: "success TestRecipe /" }); @@ -801,7 +801,7 @@ class TestRecipe1 extends RecipeModule { ]; } - async handleAPIRequest(id, req, res) { + async handleAPIRequest(id, tenantId, req, res) { if (id === "/") { res.setStatusCode(200); res.sendJSONResponse({ message: "success TestRecipe1 /" }); diff --git a/test/session.test.js b/test/session.test.js index 296407161..7b88c4281 100644 --- a/test/session.test.js +++ b/test/session.test.js @@ -527,7 +527,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { true ); assert(response2.session != undefined); - assert(Object.keys(response2.session).length === 4); + assert(Object.keys(response2.session).length === 5); let response3 = await SessionFunctions.getSession( s.recipeInterfaceImpl.helpers, @@ -537,7 +537,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { true ); assert(response3.session != undefined); - assert(Object.keys(response3.session).length === 4); + assert(Object.keys(response3.session).length === 5); }); //check session verify for with / without anti-csrf present** @@ -569,7 +569,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { ); assert.notStrictEqual(response2.session, undefined); - assert.strictEqual(Object.keys(response2.session).length, 4); // TODO check why this changed + assert.strictEqual(Object.keys(response2.session).length, 5); //passing anti-csrf token as undefined and anti-csrf check as true try { @@ -1001,7 +1001,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { true ); assert(response2.session != undefined); - assert(Object.keys(response2.session).length === 4); + assert(Object.keys(response2.session).length === 5); //passing anti-csrf token as undefined and anti-csrf check as true let response3 = await SessionFunctions.getSession( @@ -1012,7 +1012,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { true ); assert(response3.session != undefined); - assert(Object.keys(response3.session).length === 4); + assert(Object.keys(response3.session).length === 5); }); it("test that anti-csrf disabled and sameSite none does not throw an error", async function () { @@ -1131,13 +1131,12 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { let res = await SessionFunctions.createNewSession(s.helpers, "", false, {}, null); let res2 = await SessionFunctions.getSessionInformation(s.helpers, res.session.handle); - assert(typeof res2.status === "string"); - assert(res2.status === "OK"); assert(typeof res2.userId === "string"); assert(typeof res2.sessionDataInDatabase === "object"); assert(typeof res2.expiry === "number"); assert(typeof res2.customClaimsInAccessTokenPayload === "object"); assert(typeof res2.timeCreated === "number"); + assert.strictEqual(res2.tenantId, "public"); }); it("test that revoked session throws error when calling get session by session handle", async function () { diff --git a/test/session/claims/removeClaim.test.js b/test/session/claims/removeClaim.test.js index 000cbdac7..9242e40b3 100644 --- a/test/session/claims/removeClaim.test.js +++ b/test/session/claims/removeClaim.test.js @@ -83,7 +83,7 @@ describe(`sessionClaims/removeClaim: ${printPath("[test/session/claims/removeCla const res = await Session.createNewSession(mockRequest(), response, "someId"); const payload = res.getAccessTokenPayload(); - assert.equal(Object.keys(payload).length, 9); + assert.equal(Object.keys(payload).length, 10); assert.ok(payload["st-true"]); assert.equal(payload["st-true"].v, true); assert(payload["st-true"].t > Date.now() - 10000); @@ -91,7 +91,7 @@ describe(`sessionClaims/removeClaim: ${printPath("[test/session/claims/removeCla await res.removeClaim(TrueClaim); const payloadAfter = res.getAccessTokenPayload(); - assert.equal(Object.keys(payloadAfter).length, 8); + assert.equal(Object.keys(payloadAfter).length, 9); }); it("should clear previously set claim using a handle", async function () { @@ -129,7 +129,7 @@ describe(`sessionClaims/removeClaim: ${printPath("[test/session/claims/removeCla const session = await Session.createNewSession(mockRequest(), response, "someId"); const payload = session.getAccessTokenPayload(); - assert.equal(Object.keys(payload).length, 9); + assert.equal(Object.keys(payload).length, 10); assert.ok(payload["st-true"]); assert.equal(payload["st-true"].v, true); assert(payload["st-true"].t > Date.now() - 10000); diff --git a/test/session/claims/setClaimValue.test.js b/test/session/claims/setClaimValue.test.js index 5634c100f..af07badc4 100644 --- a/test/session/claims/setClaimValue.test.js +++ b/test/session/claims/setClaimValue.test.js @@ -90,7 +90,7 @@ describe(`sessionClaims/setClaimValue: ${printPath("[test/session/claims/setClai const res = await Session.createNewSession(mockRequest(), response, "someId"); const payload = res.getAccessTokenPayload(); - assert.equal(Object.keys(payload).length, 9); + assert.equal(Object.keys(payload).length, 10); assert.ok(payload["st-true"]); assert.equal(payload["st-true"].v, true); assert(payload["st-true"].t > Date.now() - 2000); @@ -98,7 +98,7 @@ describe(`sessionClaims/setClaimValue: ${printPath("[test/session/claims/setClai await res.setClaimValue(TrueClaim, false); const payloadAfter = res.getAccessTokenPayload(); - assert.equal(Object.keys(payloadAfter).length, 9); + assert.equal(Object.keys(payloadAfter).length, 10); assert.ok(payloadAfter["st-true"]); assert.equal(payloadAfter["st-true"].v, false); assert(payloadAfter["st-true"].t > payload["st-true"].t); @@ -139,7 +139,7 @@ describe(`sessionClaims/setClaimValue: ${printPath("[test/session/claims/setClai const res = await Session.createNewSession(mockRequest(), response, "someId"); const payload = res.getAccessTokenPayload(); - assert.equal(Object.keys(payload).length, 9); + assert.equal(Object.keys(payload).length, 10); assert.ok(payload["st-true"]); assert.equal(payload["st-true"].v, true); assert(payload["st-true"].t > Date.now() - 10000); diff --git a/test/sessionExpress.test.js b/test/sessionExpress.test.js index 4e00ed2fe..4d459a9b6 100644 --- a/test/sessionExpress.test.js +++ b/test/sessionExpress.test.js @@ -195,7 +195,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi Session.init({ getTokenTransferMethod: () => "cookie", errorHandlers: { - onTokenTheftDetected: async (sessionHandle, userId, tenantId, request, response) => { + onTokenTheftDetected: async (sessionHandle, userId, request, response) => { response.sendJSONResponse({ success: true, }); diff --git a/test/thirdpartyemailpassword/emailDelivery.test.js b/test/thirdpartyemailpassword/emailDelivery.test.js index 7b495ed2b..835b53137 100644 --- a/test/thirdpartyemailpassword/emailDelivery.test.js +++ b/test/thirdpartyemailpassword/emailDelivery.test.js @@ -167,11 +167,13 @@ describe(`emailDelivery: ${printPath("[test/thirdpartyemailpassword/emailDeliver }, recipeList: [ ThirdPartyEmailPassword.init({ - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: async (input, passwordResetLink) => { - email = input.email; - passwordResetURL = passwordResetLink; - timeJoined = input.timeJoined; + emailDelivery: { + service: { + sendEmail: async (input) => { + email = input.user.email; + passwordResetURL = input.passwordResetLink; + timeJoined = input.user.timeJoined; + }, }, }, }), @@ -221,11 +223,13 @@ describe(`emailDelivery: ${printPath("[test/thirdpartyemailpassword/emailDeliver }, recipeList: [ ThirdPartyEmailPassword.init({ - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: async (input, passwordResetLink) => { - functionCalled = true; - email = input.email; - passwordResetURL = passwordResetLink; + emailDelivery: { + service: { + sendEmail: async (input) => { + functionCalled = true; + email = input.user.email; + passwordResetURL = input.passwordResetLink; + }, }, }, }), @@ -290,9 +294,11 @@ describe(`emailDelivery: ${printPath("[test/thirdpartyemailpassword/emailDeliver }, recipeList: [ ThirdPartyEmailPassword.init({ - resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: async (input, passwordResetLink) => { - functionCalled = true; + emailDelivery: { + service: { + sendEmail: async (input) => { + functionCalled = true; + }, }, }, }), @@ -613,116 +619,6 @@ describe(`emailDelivery: ${printPath("[test/thirdpartyemailpassword/emailDeliver assert.strictEqual(result.body.status, "OK"); }); - it("test backward compatibility: email verify (emailpassword user)", async function () { - await startST(); - let idInCallback = undefined; - let email = undefined; - let emailVerifyURL = undefined; - STExpress.init({ - supertokens: { - connectionURI: "http://localhost:8080", - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - EmailVerification.init({ - mode: "OPTIONAL", - createAndSendCustomEmail: async (input, emailVerificationURLWithToken) => { - email = input.email; - idInCallback = input.id; - emailVerifyURL = emailVerificationURLWithToken; - }, - }), - ThirdPartyEmailPassword.init(), - Session.init({ getTokenTransferMethod: () => "cookie" }), - ], - telemetry: false, - }); - - const app = express(); - app.use(express.json()); - app.use(middleware()); - app.post("/create", async (req, res) => { - await Session.createNewSession(req, res, req.body.id, {}, {}); - res.status(200).send(""); - }); - app.use(errorHandler()); - - let user = await ThirdPartyEmailPassword.emailPasswordSignUp("test@example.com", "1234abcd"); - let res = extractInfoFromResponse(await supertest(app).post("/create").send({ id: user.user.id }).expect(200)); - - await supertest(app) - .post("/auth/user/email/verify/token") - .set("rid", "emailverification") - .set("Cookie", ["sAccessToken=" + res.accessToken]) - .expect(200); - await delay(2); - assert.strictEqual(idInCallback, user.user.id); - assert.strictEqual(email, "test@example.com"); - assert.notStrictEqual(emailVerifyURL, undefined); - }); - - it("test backward compatibility: email verify (thirdparty user)", async function () { - await startST(); - let idInCallback = undefined; - let email = undefined; - let emailVerifyURL = undefined; - STExpress.init({ - supertokens: { - connectionURI: "http://localhost:8080", - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - EmailVerification.init({ - mode: "OPTIONAL", - createAndSendCustomEmail: async (input, emailVerificationURLWithToken) => { - email = input.email; - idInCallback = input.id; - emailVerifyURL = emailVerificationURLWithToken; - }, - }), - ThirdPartyEmailPassword.init({ - providers: [{ config: { thirdPartyId: "custom-provider" } }], - }), - Session.init({ getTokenTransferMethod: () => "cookie" }), - ], - telemetry: false, - }); - - const app = express(); - app.use(express.json()); - app.use(middleware()); - app.post("/create", async (req, res) => { - await Session.createNewSession(req, res, req.body.id, {}, {}); - res.status(200).send(""); - }); - app.use(errorHandler()); - - let user = await ThirdPartyEmailPassword.thirdPartyManuallyCreateOrUpdateUser( - "custom-provider", - "test-user-id", - "test@example.com" - ); - let res = extractInfoFromResponse(await supertest(app).post("/create").send({ id: user.user.id }).expect(200)); - - await supertest(app) - .post("/auth/user/email/verify/token") - .set("rid", "emailverification") - .set("Cookie", ["sAccessToken=" + res.accessToken]) - .expect(200); - await delay(2); - assert.strictEqual(idInCallback, user.user.id); - assert.strictEqual(email, "test@example.com"); - assert.notStrictEqual(emailVerifyURL, undefined); - }); - it("test custom override: email verify", async function () { await startST(); let email = undefined; diff --git a/test/thirdpartyemailpassword/emailverify.test.js b/test/thirdpartyemailpassword/emailverify.test.js index 1f67e7cc8..f566b3153 100644 --- a/test/thirdpartyemailpassword/emailverify.test.js +++ b/test/thirdpartyemailpassword/emailverify.test.js @@ -208,9 +208,13 @@ describe(`emailverify: ${printPath("[test/thirdpartyemailpassword/emailverify.te recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - userInfo = user; - emailToken = emailVerificationURLWithToken; + emailDelivery: { + service: { + sendEmail: async (input) => { + userInfo = input.user; + emailToken = input.emailVerifyLink; + }, + }, }, }), ThirdPartyEmailPassword.init(), @@ -266,9 +270,13 @@ describe(`emailverify: ${printPath("[test/thirdpartyemailpassword/emailverify.te recipeList: [ EmailVerification.init({ mode: "OPTIONAL", - createAndSendCustomEmail: (user, emailVerificationURLWithToken) => { - userInfo = user; - emailToken = emailVerificationURLWithToken; + emailDelivery: { + service: { + sendEmail: async (input) => { + userInfo = input.user; + emailToken = input.emailVerifyLink; + }, + }, }, }), ThirdPartyEmailPassword.init({ diff --git a/test/thirdpartypasswordless/api.test.js b/test/thirdpartypasswordless/api.test.js index 37bc8c039..f9493552e 100644 --- a/test/thirdpartypasswordless/api.test.js +++ b/test/thirdpartypasswordless/api.test.js @@ -59,12 +59,20 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - userInputCode = input.userInputCode; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, }), ], @@ -127,7 +135,7 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") assert(typeof validUserInputCodeResponse.user.id === "string"); assert(typeof validUserInputCodeResponse.user.email === "string"); assert(typeof validUserInputCodeResponse.user.timeJoined === "number"); - assert(Object.keys(validUserInputCodeResponse.user).length === 3); + assert(Object.keys(validUserInputCodeResponse.user).length === 4); assert(Object.keys(validUserInputCodeResponse).length === 3); }); @@ -154,12 +162,20 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - userInputCode = input.userInputCode; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -222,7 +238,8 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") assert(typeof validUserInputCodeResponse.user.id === "string"); assert(typeof validUserInputCodeResponse.user.phoneNumber === "string"); assert(typeof validUserInputCodeResponse.user.timeJoined === "number"); - assert(Object.keys(validUserInputCodeResponse.user).length === 3); + assert(validUserInputCodeResponse.user.tenantIds.length === 1); + assert(Object.keys(validUserInputCodeResponse.user).length === 4); assert(Object.keys(validUserInputCodeResponse).length === 3); }); @@ -249,12 +266,20 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - isCreateAndSendCustomEmailCalled = true; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + isCreateAndSendCustomEmailCalled = true; + return; + }, + }, }, }), ], @@ -336,12 +361,20 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - isCreateAndSendCustomTextMessageCalled = true; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + isCreateAndSendCustomTextMessageCalled = true; + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -422,11 +455,19 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, }), ], @@ -507,13 +548,21 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - userInputCode = input.userInputCode; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, - createAndSendCustomEmail: (input) => { - userInputCode = input.userInputCode; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + userInputCode = input.userInputCode; + return; + }, + }, }, }), ], @@ -764,7 +813,7 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") assert(typeof validLinkCodeResponse.user.id === "string"); assert(typeof validLinkCodeResponse.user.email === "string"); assert(typeof validLinkCodeResponse.user.timeJoined === "number"); - assert(Object.keys(validLinkCodeResponse.user).length === 3); + assert(Object.keys(validLinkCodeResponse.user).length === 4); assert(Object.keys(validLinkCodeResponse).length === 3); } }); @@ -860,7 +909,7 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") assert(typeof validUserInputCodeResponse.user.id === "string"); assert(typeof validUserInputCodeResponse.user.email === "string"); assert(typeof validUserInputCodeResponse.user.timeJoined === "number"); - assert(Object.keys(validUserInputCodeResponse.user).length === 3); + assert(Object.keys(validUserInputCodeResponse.user).length === 4); assert(Object.keys(validUserInputCodeResponse).length === 3); } @@ -1135,8 +1184,12 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - magicLinkURL = new URL(input.urlWithLinkCode); + emailDelivery: { + service: { + sendEmail: async (input) => { + magicLinkURL = new URL(input.urlWithLinkCode); + }, + }, }, }), ], @@ -1379,8 +1432,12 @@ describe(`apiFunctions: ${printPath("[test/thirdpartypasswordless/api.test.js]") ThirdPartyPasswordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], diff --git a/test/thirdpartypasswordless/config.test.js b/test/thirdpartypasswordless/config.test.js index 9056ba551..91321e998 100644 --- a/test/thirdpartypasswordless/config.test.js +++ b/test/thirdpartypasswordless/config.test.js @@ -102,19 +102,27 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - validateEmailAddress: (email) => { + validateEmailAddress: (email, _) => { isValidateEmailAddressCalled = true; return undefined; }, - validatePhoneNumber: (phoneNumber) => { + validatePhoneNumber: (phoneNumber, _) => { isValidatePhoneNumberCalled = true; return undefined; }, - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -200,12 +208,19 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - isCreateAndSendCustomEmailCalled = true; - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + isCreateAndSendCustomEmailCalled = true; + }, + }, }, - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -270,12 +285,20 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "EMAIL_OR_PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (input) => { + return; + }, + }, }, - createAndSendCustomTextMessage: (input) => { - isCreateAndSendCustomTextMessageCalled = true; - return; + smsDelivery: { + service: { + sendSms: async (input) => { + isCreateAndSendCustomTextMessageCalled = true; + return; + }, + }, }, }), ], @@ -377,10 +400,14 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, - validatePhoneNumber: (phoneNumber) => { + validatePhoneNumber: (phoneNumber, _) => { isValidatePhoneNumberCalled = true; return undefined; }, @@ -503,18 +530,22 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE", - createAndSendCustomTextMessage: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } - - if ( - typeof input.codeLifetime === "number" && - typeof input.phoneNumber === "string" && - typeof input.preAuthSessionId === "string" - ) { - isOtherInputValid = true; - } + smsDelivery: { + service: { + sendSms: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + + if ( + typeof input.codeLifetime === "number" && + typeof input.phoneNumber === "string" && + typeof input.preAuthSessionId === "string" + ) { + isOtherInputValid = true; + } + }, + }, }, }), ], @@ -575,10 +606,14 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "PHONE", flowType: "MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + smsDelivery: { + service: { + sendSms: async (input) => { + if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -637,10 +672,14 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + smsDelivery: { + service: { + sendSms: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -700,9 +739,13 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "PHONE", flowType: "MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - isCreateAndSendCustomTextMessageCalled = true; - throw new Error("test message"); + smsDelivery: { + service: { + sendSms: async (input) => { + isCreateAndSendCustomTextMessageCalled = true; + throw new Error("test message"); + }, + }, }, }), ], @@ -935,18 +978,22 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE", - createAndSendCustomEmail: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } - - if ( - typeof input.codeLifetime === "number" && - typeof input.email === "string" && - typeof input.preAuthSessionId === "string" - ) { - isOtherInputValid = true; - } + emailDelivery: { + service: { + sendEmail: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode === undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + + if ( + typeof input.codeLifetime === "number" && + typeof input.email === "string" && + typeof input.preAuthSessionId === "string" + ) { + isOtherInputValid = true; + } + }, + }, }, }), ], @@ -1007,10 +1054,14 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "EMAIL", flowType: "MAGIC_LINK", - createAndSendCustomEmail: (input) => { - if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + emailDelivery: { + service: { + sendEmail: async (input) => { + if (input.userInputCode === undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -1069,10 +1120,14 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { - isUserInputCodeAndUrlWithLinkCodeValid = true; - } + emailDelivery: { + service: { + sendEmail: async (input) => { + if (input.userInputCode !== undefined && input.urlWithLinkCode !== undefined) { + isUserInputCodeAndUrlWithLinkCodeValid = true; + } + }, + }, }, }), ], @@ -1132,9 +1187,13 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js ThirdPartyPasswordless.init({ contactMethod: "EMAIL", flowType: "MAGIC_LINK", - createAndSendCustomEmail: (input) => { - isCreateAndSendCustomEmailCalled = true; - throw new Error("test message"); + emailDelivery: { + service: { + sendEmail: async (input) => { + isCreateAndSendCustomEmailCalled = true; + throw new Error("test message"); + }, + }, }, }), ], @@ -1274,8 +1333,12 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js customCode = generateRandomCode(5); return customCode; }, - createAndSendCustomEmail: (input) => { - userCodeSent = input.userInputCode; + emailDelivery: { + service: { + sendEmail: async (input) => { + userCodeSent = input.userInputCode; + }, + }, }, }), ], @@ -1359,8 +1422,12 @@ describe(`config tests: ${printPath("[test/thirdpartypasswordless/config.test.js getCustomUserInputCode: (input) => { return customCode; }, - createAndSendCustomEmail: (input) => { - userCodeSent = input.userInputCode; + emailDelivery: { + service: { + sendEmail: async (input) => { + userCodeSent = input.userInputCode; + }, + }, }, }), ], diff --git a/test/thirdpartypasswordless/emailDelivery.test.js b/test/thirdpartypasswordless/emailDelivery.test.js index 1fe451b93..34c037ba8 100644 --- a/test/thirdpartypasswordless/emailDelivery.test.js +++ b/test/thirdpartypasswordless/emailDelivery.test.js @@ -209,135 +209,6 @@ describe(`emailDelivery: ${printPath("[test/thirdpartypasswordless/emailDelivery assert.strictEqual(result.body.status, "OK"); }); - it("test backward compatibility: email verify (thirdparty user)", async function () { - await startST(); - let idInCallback = undefined; - let email = undefined; - let emailVerifyURL = undefined; - STExpress.init({ - supertokens: { - connectionURI: "http://localhost:8080", - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - EmailVerification.init({ - mode: "OPTIONAL", - createAndSendCustomEmail: async (input, emailVerificationURLWithToken) => { - idInCallback = input.id; - email = input.email; - emailVerifyURL = emailVerificationURLWithToken; - tj = input.timeJoined; - }, - }), - ThirdpartyPasswordless.init({ - providers: [this.customProvider], - contactMethod: "EMAIL", - flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - }), - Session.init({ getTokenTransferMethod: () => "cookie" }), - ], - telemetry: false, - }); - - // run test if current CDI version >= 2.11 - if (!(await isCDIVersionCompatible("2.11"))) { - return; - } - - const app = express(); - app.use(express.json()); - app.use(middleware()); - app.post("/create", async (req, res) => { - await Session.createNewSession(req, res, req.body.id, {}, {}); - res.status(200).send(""); - }); - app.use(errorHandler()); - - let user = await ThirdpartyPasswordless.thirdPartyManuallyCreateOrUpdateUser( - "supertokens", - "test-user-id", - "test@example.com" - ); - let res = extractInfoFromResponse(await supertest(app).post("/create").send({ id: user.user.id }).expect(200)); - - await supertest(app) - .post("/auth/user/email/verify/token") - .set("rid", "emailverification") - .set("Cookie", ["sAccessToken=" + res.accessToken]) - .expect(200); - await delay(2); - assert.strictEqual(email, "test@example.com"); - assert.strictEqual(idInCallback, user.user.id); - assert.notStrictEqual(emailVerifyURL, undefined); - }); - - it("test backward compatibility: email verify (passwordless user)", async function () { - await startST(); - let functionCalled = false; - let email = undefined; - let emailVerifyURL = undefined; - STExpress.init({ - supertokens: { - connectionURI: "http://localhost:8080", - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - EmailVerification.init({ mode: "OPTIONAL" }), - ThirdpartyPasswordless.init({ - providers: [this.customProvider], - contactMethod: "EMAIL", - flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - emailVerificationFeature: { - createAndSendCustomEmail: async (input, emailVerificationURLWithToken) => { - functionCalled = true; - email = input.email; - emailVerifyURL = emailVerificationURLWithToken; - }, - }, - }), - Session.init({ getTokenTransferMethod: () => "cookie" }), - ], - telemetry: false, - }); - - // run test if current CDI version >= 2.11 - if (!(await isCDIVersionCompatible("2.11"))) { - return; - } - - const app = express(); - app.use(express.json()); - app.use(middleware()); - app.post("/create", async (req, res) => { - await Session.createNewSession(req, res, req.body.id, {}, {}); - res.status(200).send(""); - }); - app.use(errorHandler()); - - let user = await ThirdpartyPasswordless.passwordlessSignInUp({ - email: "test@example.com", - }); - let res = extractInfoFromResponse(await supertest(app).post("/create").send({ id: user.user.id }).expect(200)); - - await supertest(app) - .post("/auth/user/email/verify/token") - .set("rid", "emailverification") - .set("Cookie", ["sAccessToken=" + res.accessToken]) - .expect(200); - await delay(2); - assert.strictEqual(functionCalled, false); - assert.strictEqual(email, undefined); - assert.strictEqual(emailVerifyURL, undefined); - }); - it("test custom override: email verify", async function () { await startST(); let email = undefined; @@ -619,11 +490,15 @@ describe(`emailDelivery: ${printPath("[test/thirdpartypasswordless/emailDelivery ThirdpartyPasswordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: async (input) => { - email = input.email; - codeLifetime = input.codeLifetime; - urlWithLinkCode = input.urlWithLinkCode; - userInputCode = input.userInputCode; + emailDelivery: { + service: { + sendEmail: async (input) => { + email = input.email; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + }, + }, }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), @@ -1018,18 +893,18 @@ describe(`emailDelivery: ${printPath("[test/thirdpartypasswordless/emailDelivery ThirdpartyPasswordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: async (input) => { - /** - * when the function is called for the first time, - * it will be for signinup - */ - if (sendCustomEmailCalled) { - email = input.email; - codeLifetime = input.codeLifetime; - urlWithLinkCode = input.urlWithLinkCode; - userInputCode = input.userInputCode; - } - sendCustomEmailCalled = true; + emailDelivery: { + service: { + sendEmail: async (input) => { + if (sendCustomEmailCalled) { + email = input.email; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + } + sendCustomEmailCalled = true; + }, + }, }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), diff --git a/test/thirdpartypasswordless/recipeFunctions.test.js b/test/thirdpartypasswordless/recipeFunctions.test.js index d99116317..823f79d81 100644 --- a/test/thirdpartypasswordless/recipeFunctions.test.js +++ b/test/thirdpartypasswordless/recipeFunctions.test.js @@ -175,8 +175,12 @@ describe(`recipeFunctions: ${printPath("[test/thirdpartypasswordless/recipeFunct ThirdPartyPasswordless.init({ contactMethod: "EMAIL", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomEmail: (input) => { - return; + emailDelivery: { + service: { + sendEmail: async (emailInput) => { + return; + }, + }, }, }), ], @@ -207,7 +211,8 @@ describe(`recipeFunctions: ${printPath("[test/thirdpartypasswordless/recipeFunct assert(result.email !== undefined && user.email === result.email); assert(result.phoneNumber === undefined); assert(typeof result.timeJoined === "number"); - assert(Object.keys(result).length === 3); + assert(result.tenantIds.length === 1); + assert(Object.keys(result).length === 4); } { @@ -233,7 +238,8 @@ describe(`recipeFunctions: ${printPath("[test/thirdpartypasswordless/recipeFunct assert(userInfo.email === user.email); assert(userInfo.phoneNumber === undefined); assert(typeof userInfo.timeJoined === "number"); - assert(Object.keys(userInfo).length === 3); + assert(userInfo.tenantIds.length === 1); + assert(Object.keys(userInfo).length === 4); } { @@ -256,7 +262,8 @@ describe(`recipeFunctions: ${printPath("[test/thirdpartypasswordless/recipeFunct assert(result.phoneNumber !== undefined && user.phoneNumber === result.phoneNumber); assert(result.email === undefined); assert(typeof result.timeJoined === "number"); - assert(Object.keys(result).length === 3); + assert(result.tenantIds.length === 1); + assert(Object.keys(result).length === 4); } }); @@ -469,7 +476,7 @@ describe(`recipeFunctions: ${printPath("[test/thirdpartypasswordless/recipeFunct assert(resp.user.phoneNumber === undefined); assert(typeof resp.user.timeJoined === "number"); assert(Object.keys(resp).length === 3); - assert(Object.keys(resp.user).length === 3); + assert(Object.keys(resp.user).length === 4); } { @@ -1035,8 +1042,12 @@ describe(`recipeFunctions: ${printPath("[test/thirdpartypasswordless/recipeFunct ThirdPartyPasswordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: (input) => { - return; + smsDelivery: { + service: { + sendSms: async (input) => { + return; + }, + }, }, }), ], @@ -1058,6 +1069,7 @@ describe(`recipeFunctions: ${printPath("[test/thirdpartypasswordless/recipeFunct assert(result.user.phoneNumber === "+12345678901"); assert(typeof result.user.id === "string"); assert(typeof result.user.timeJoined === "number"); - assert(Object.keys(result.user).length === 3); + assert(result.user.tenantIds.length === 1); + assert(Object.keys(result.user).length === 4); }); }); diff --git a/test/thirdpartypasswordless/smsDelivery.test.js b/test/thirdpartypasswordless/smsDelivery.test.js index d464794cd..99c036fb1 100644 --- a/test/thirdpartypasswordless/smsDelivery.test.js +++ b/test/thirdpartypasswordless/smsDelivery.test.js @@ -129,11 +129,15 @@ describe(`smsDelivery: ${printPath("[test/thirdpartypasswordless/smsDelivery.tes ThirdpartyPasswordless.init({ contactMethod: "PHONE", flowType: "USER_INPUT_CODE_AND_MAGIC_LINK", - createAndSendCustomTextMessage: async (input) => { - phoneNumber = input.phoneNumber; - codeLifetime = input.codeLifetime; - urlWithLinkCode = input.urlWithLinkCode; - userInputCode = input.userInputCode; + smsDelivery: { + service: { + sendSms: async (input) => { + phoneNumber = input.phoneNumber; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + }, + }, }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), @@ -694,6 +698,19 @@ describe(`smsDelivery: ${printPath("[test/thirdpartypasswordless/smsDelivery.tes } sendCustomSMSCalled = true; }, + smsDelivery: { + service: { + sendSms: async (input) => { + if (sendCustomSMSCalled) { + phoneNumber = input.phoneNumber; + codeLifetime = input.codeLifetime; + urlWithLinkCode = input.urlWithLinkCode; + userInputCode = input.userInputCode; + } + sendCustomSMSCalled = true; + }, + }, + }, }), Session.init({ getTokenTransferMethod: () => "cookie" }), ], diff --git a/test/userContext.test.js b/test/userContext.test.js index f9eb9ba4a..0ba0bd5fd 100644 --- a/test/userContext.test.js +++ b/test/userContext.test.js @@ -154,7 +154,7 @@ describe(`userContext: ${printPath("[test/userContext.test.js]")}`, function () app.use(errorHandler()); - await EmailPassword.signUp("random@gmail.com", "validpass123", { + await EmailPassword.signUp("random@gmail.com", "validpass123", undefined, { manualCall: true, }); @@ -256,7 +256,7 @@ describe(`userContext: ${printPath("[test/userContext.test.js]")}`, function () app.use(errorHandler()); - await EmailPassword.signUp("random@gmail.com", "validpass123", { + await EmailPassword.signUp("random@gmail.com", "validpass123", undefined, { manualCall: true, }); @@ -389,7 +389,7 @@ describe(`userContext: ${printPath("[test/userContext.test.js]")}`, function () app.use(errorHandler()); - await EmailPassword.signUp("random@gmail.com", "validpass123", { + await EmailPassword.signUp("random@gmail.com", "validpass123", undefined, { manualCall: true, }); diff --git a/test/utils.js b/test/utils.js index 099d26d7d..1a0e03c23 100644 --- a/test/utils.js +++ b/test/utils.js @@ -633,7 +633,7 @@ module.exports.createUsers = async (emailpassword = null, passwordless = null, t } if (user.recipe === "thirdparty" && thirdparty !== null) { - await thirdparty.signInUp(user.provider, user.userId, user.email); + await thirdparty.manuallyCreateOrUpdateUser(user.provider, user.userId, user.email); } } };