diff --git a/test/test-server/src/index.ts b/test/test-server/src/index.ts index b2097452f..3fc101557 100644 --- a/test/test-server/src/index.ts +++ b/test/test-server/src/index.ts @@ -33,6 +33,7 @@ import Multitenancy from "../../../recipe/multitenancy"; import Passwordless from "../../../recipe/passwordless"; import Session from "../../../recipe/session"; import { verifySession } from "../../../recipe/session/framework/express"; +import { getResponseHeaderNameForTokenType, getCookieNameFromTokenType } from "../../../lib/build/recipe/session/utils"; import ThirdParty from "../../../recipe/thirdparty"; import TOTP from "../../../recipe/totp"; import OAuth2Provider from "../../../recipe/oauth2provider"; @@ -147,6 +148,16 @@ function initST(config: any) { recipeList.push( Session.init({ ...config, + getResponseHeaderNameForTokenType: callbackWithLog( + "Session.getResponseHeaderNameForTokenType", + config?.getResponseHeaderNameForTokenType, + getResponseHeaderNameForTokenType + ), + getCookieNameFromTokenType: callbackWithLog( + "Session.getCookieNameFromTokenType", + config?.getCookieNameFromTokenType, + getCookieNameFromTokenType + ), override: { apis: overrideBuilderWithLogging("Session.override.apis", config?.override?.apis), functions: overrideBuilderWithLogging( @@ -164,9 +175,9 @@ function initST(config: any) { shouldDoAutomaticAccountLinking: callbackWithLog( "AccountLinking.shouldDoAutomaticAccountLinking", config.shouldDoAutomaticAccountLinking, - { + () => ({ shouldAutomaticallyLink: false, - } + }) ), onAccountLinked: callbackWithLog("AccountLinking.onAccountLinked", config.onAccountLinked), override: { @@ -219,7 +230,9 @@ function initST(config: any) { getEmailForRecipeUserId: callbackWithLog( "EmailVerification.getEmailForRecipeUserId", config?.getEmailForRecipeUserId, - { status: "UNKNOWN_USER_ID_ERROR" } + () => { + status: "UNKNOWN_USER_ID_ERROR"; + } ), override: { apis: overrideBuilderWithLogging("EmailVerification.override.apis", config?.override?.apis), @@ -360,7 +373,7 @@ app.get("/test/overrideparams", async (req, res, next) => { }); app.get("/test/featureflag", async (req, res, next) => { - res.json(["removedOverwriteSessionDuringSignInUp"]); + res.json(["removedOverwriteSessionDuringSignInUp", "configurableCookieAndHeaderNames"]); }); app.post("/test/resetoverrideparams", async (req, res, next) => { @@ -490,8 +503,8 @@ function loggingOverrideFunc(name: string, originalImpl: (...args: any[]) => }; } -function callbackWithLog(name: string, overrideName: string, defaultValue?: T) { - const impl = overrideName ? getFunc(overrideName) : () => defaultValue; +function callbackWithLog(name: string, overrideName: string, defaultImpl?: (...args: any[]) => T) { + const impl = overrideName ? getFunc(overrideName) : defaultImpl ?? (() => undefined); return loggingOverrideFunc(name, impl); } diff --git a/test/test-server/src/testFunctionMapper.ts b/test/test-server/src/testFunctionMapper.ts index c342ac37f..1b48879e2 100644 --- a/test/test-server/src/testFunctionMapper.ts +++ b/test/test-server/src/testFunctionMapper.ts @@ -100,6 +100,14 @@ function getSessionVars() { } export function getFunc(evalStr: string): (...args: any[]) => any { + if (evalStr.startsWith("defaultValues:")) { + const defaultValues = JSON.parse(evalStr.split("defaultValues:")[1]); + if (!Array.isArray(defaultValues)) { + throw new Error("defaultValues must be an array"); + } + return () => defaultValues.pop(); + } + if (evalStr.startsWith("session.fetchAndSetClaim")) { return async (a, c) => { userIdInCallback = a;