From b99c077fe92d910201c48fa0b6de4bc988231ddb Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 26 Jul 2024 16:41:09 +0530 Subject: [PATCH 01/11] fix: test server compatible with 1.17 --- test/test-server/src/emailpassword.ts | 6 ++++-- test/test-server/src/session.ts | 9 ++++++++- test/test-server/src/utils.ts | 21 +++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/test/test-server/src/emailpassword.ts b/test/test-server/src/emailpassword.ts index 633c4bfd6..fad8248fc 100644 --- a/test/test-server/src/emailpassword.ts +++ b/test/test-server/src/emailpassword.ts @@ -9,6 +9,8 @@ const { logDebugMessage } = logger(namespace); const router = Router() .post("/signup", async (req, res, next) => { + const fdiVersion: string = req.headers["fdi-version"] as string; + try { logDebugMessage("EmailPassword:signup %j", req.body); let session = req.body.session && (await convertRequestSessionToSessionObject(req.body.session)); @@ -21,8 +23,8 @@ const router = Router() ); res.json({ ...response, - ...serializeUser(response), - ...serializeRecipeUserId(response), + ...serializeUser(response, fdiVersion), + ...serializeRecipeUserId(response, fdiVersion), }); } catch (e) { next(e); diff --git a/test/test-server/src/session.ts b/test/test-server/src/session.ts index a6f6ac9c3..2d17a47ec 100644 --- a/test/test-server/src/session.ts +++ b/test/test-server/src/session.ts @@ -12,9 +12,16 @@ const { logDebugMessage } = logger(namespace); const router = Router() .post("/createnewsessionwithoutrequestresponse", async (req, res, next) => { + const fdiVersion = req.headers["fdi-version"] as string; + try { logDebugMessage("Session.createNewSessionWithoutRequestResponse %j", req.body); - const recipeUserId = supertokens.convertToRecipeUserId(req.body.recipeUserId); + let recipeUserId; + if (["1.17", "2.0"].includes(fdiVersion)) { + recipeUserId = supertokens.convertToRecipeUserId(req.body.userId); + } else { + recipeUserId = supertokens.convertToRecipeUserId(req.body.recipeUserId); + } const response = await Session.createNewSessionWithoutRequestResponse( req.body.tenantId || "public", recipeUserId, diff --git a/test/test-server/src/utils.ts b/test/test-server/src/utils.ts index 69ecb21ce..2b1b72e5c 100644 --- a/test/test-server/src/utils.ts +++ b/test/test-server/src/utils.ts @@ -137,7 +137,21 @@ export async function convertRequestSessionToSessionObject( return tokens; } -export function serializeUser(response) { +export function serializeUser(response, fdiVersion: string) { + if (["1.17", "2.0"].includes(fdiVersion)) { + return { + ...("user" in response && response.user instanceof supertokens.User + ? { + user: { + id: (response.user as supertokens.User).id, + email: (response.user as supertokens.User).emails[0], + timeJoined: (response.user as supertokens.User).timeJoined, + tenantIds: (response.user as supertokens.User).tenantIds, + }, + } + : {}), + }; + } return { ...("user" in response && response.user instanceof supertokens.User ? { @@ -147,7 +161,10 @@ export function serializeUser(response) { }; } -export function serializeRecipeUserId(response) { +export function serializeRecipeUserId(response, fdiVersion: string) { + if (["1.17", "2.0"].includes(fdiVersion)) { + return {}; + } return { ...("recipeUserId" in response && response.recipeUserId instanceof supertokens.RecipeUserId ? { From 1b76f5cf120e5b8ddca93615c54c7248f9ed19c2 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 26 Jul 2024 17:42:10 +0530 Subject: [PATCH 02/11] fix: pr comments --- test/test-server/src/emailpassword.ts | 16 +++------------- test/test-server/src/utils.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/test-server/src/emailpassword.ts b/test/test-server/src/emailpassword.ts index fad8248fc..7770898f4 100644 --- a/test/test-server/src/emailpassword.ts +++ b/test/test-server/src/emailpassword.ts @@ -1,6 +1,6 @@ import { Router } from "express"; import EmailPassword from "../../../recipe/emailpassword"; -import { convertRequestSessionToSessionObject, serializeRecipeUserId, serializeUser } from "./utils"; +import { convertRequestSessionToSessionObject, serializeRecipeUserId, serializeResponse, serializeUser } from "./utils"; import * as supertokens from "../../../lib/build"; import { logger } from "./logger"; @@ -9,8 +9,6 @@ const { logDebugMessage } = logger(namespace); const router = Router() .post("/signup", async (req, res, next) => { - const fdiVersion: string = req.headers["fdi-version"] as string; - try { logDebugMessage("EmailPassword:signup %j", req.body); let session = req.body.session && (await convertRequestSessionToSessionObject(req.body.session)); @@ -21,11 +19,7 @@ const router = Router() session, req.body.userContext ); - res.json({ - ...response, - ...serializeUser(response, fdiVersion), - ...serializeRecipeUserId(response, fdiVersion), - }); + await serializeResponse(req, res, response); } catch (e) { next(e); } @@ -41,11 +35,7 @@ const router = Router() session, req.body.userContext ); - res.json({ - ...response, - ...serializeUser(response), - ...serializeRecipeUserId(response), - }); + await serializeResponse(req, res, response); } catch (e) { next(e); } diff --git a/test/test-server/src/utils.ts b/test/test-server/src/utils.ts index 2b1b72e5c..c892f0ae3 100644 --- a/test/test-server/src/utils.ts +++ b/test/test-server/src/utils.ts @@ -137,6 +137,16 @@ export async function convertRequestSessionToSessionObject( return tokens; } +export async function serializeResponse(req, res, response) { + const fdiVersion: string = req.headers["fdi-version"] as string; + + await res.json({ + ...response, + ...serializeUser(response, fdiVersion), + ...serializeRecipeUserId(response, fdiVersion), + }); +} + export function serializeUser(response, fdiVersion: string) { if (["1.17", "2.0"].includes(fdiVersion)) { return { From 4ec357d387602e2370b0bed8a416d04aeace55cc Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 12:00:16 +0530 Subject: [PATCH 03/11] fix: mfa claim --- lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts | 6 ++++-- lib/build/recipe/multifactorauth/multiFactorAuthClaim.js | 6 ++---- lib/ts/recipe/multifactorauth/multiFactorAuthClaim.ts | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts b/lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts index 9952b0124..07976ada7 100644 --- a/lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts +++ b/lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts @@ -55,8 +55,10 @@ export declare class MultiFactorAuthClaimClass extends SessionClaim { [x: string]: import("../../types").JSONValue; }; - removeFromPayloadByMerge_internal: () => { - [x: string]: null; + removeFromPayloadByMerge_internal: ( + payload: JSONObject + ) => { + [x: string]: import("../../types").JSONValue; }; getValueFromPayload: (payload: JSONObject) => MFAClaimValue; } diff --git a/lib/build/recipe/multifactorauth/multiFactorAuthClaim.js b/lib/build/recipe/multifactorauth/multiFactorAuthClaim.js index 45fe7885c..da46bd6b1 100644 --- a/lib/build/recipe/multifactorauth/multiFactorAuthClaim.js +++ b/lib/build/recipe/multifactorauth/multiFactorAuthClaim.js @@ -53,10 +53,8 @@ class MultiFactorAuthClaimClass extends claims_1.SessionClaim { delete retVal[this.key]; return retVal; }; - this.removeFromPayloadByMerge_internal = () => { - return { - [this.key]: null, - }; + this.removeFromPayloadByMerge_internal = (payload) => { + return Object.assign(Object.assign({}, payload), { [this.key]: null }); }; this.getValueFromPayload = (payload) => { return payload[this.key]; diff --git a/lib/ts/recipe/multifactorauth/multiFactorAuthClaim.ts b/lib/ts/recipe/multifactorauth/multiFactorAuthClaim.ts index 2d7fd36a0..70dd5ed50 100644 --- a/lib/ts/recipe/multifactorauth/multiFactorAuthClaim.ts +++ b/lib/ts/recipe/multifactorauth/multiFactorAuthClaim.ts @@ -232,8 +232,9 @@ export class MultiFactorAuthClaimClass extends SessionClaim { return retVal; }; - public removeFromPayloadByMerge_internal = () => { + public removeFromPayloadByMerge_internal = (payload: JSONObject) => { return { + ...payload, [this.key]: null, }; }; From b9a15b6e0c72ad2cd27bdff7310d1ca0ea85ee7a Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 12:02:00 +0530 Subject: [PATCH 04/11] fix: version and changelog --- CHANGELOG.md | 5 +++++ lib/build/version.d.ts | 2 +- lib/build/version.js | 2 +- lib/ts/version.ts | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51d786670..54b5c239f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [20.0.1] - 2024-08-05 + +- Fixes an issue with `removeFromPayloadByMerge_internal` for `MultiFactorAuthClaim` where it was not retaining other claims while removing the claim from the payload. +- Updates testing with backend-sdk-testing repo to run against all supported FDI versions. + ## [20.0.0] - 2024-07-24 ### Changes diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index 46c0c5e1a..4ffb12d1e 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1,4 +1,4 @@ // @ts-nocheck -export declare const version = "20.0.0"; +export declare const version = "20.0.1"; export declare const cdiSupported: string[]; export declare const dashboardVersion = "0.13"; diff --git a/lib/build/version.js b/lib/build/version.js index 17148bd6b..6515caf8f 100644 --- a/lib/build/version.js +++ b/lib/build/version.js @@ -15,7 +15,7 @@ exports.dashboardVersion = exports.cdiSupported = exports.version = void 0; * License for the specific language governing permissions and limitations * under the License. */ -exports.version = "20.0.0"; +exports.version = "20.0.1"; exports.cdiSupported = ["5.1"]; // Note: The actual script import for dashboard uses v{DASHBOARD_VERSION} exports.dashboardVersion = "0.13"; diff --git a/lib/ts/version.ts b/lib/ts/version.ts index f7a917b2c..583444944 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const version = "20.0.0"; +export const version = "20.0.1"; export const cdiSupported = ["5.1"]; diff --git a/package-lock.json b/package-lock.json index 967c8fbae..ebdbc0bfc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supertokens-node", - "version": "20.0.0", + "version": "20.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "supertokens-node", - "version": "20.0.0", + "version": "20.0.1", "license": "Apache-2.0", "dependencies": { "content-type": "^1.0.5", diff --git a/package.json b/package.json index ff2178e7e..4b20c99a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supertokens-node", - "version": "20.0.0", + "version": "20.0.1", "description": "NodeJS driver for SuperTokens core", "main": "index.js", "scripts": { From 4036f1191d17c18d4cf13983d3ec57512275d179 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 12:28:23 +0530 Subject: [PATCH 05/11] fix: using version function for comparision --- test/test-server/src/session.ts | 8 ++++++-- test/test-server/src/utils.ts | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/test/test-server/src/session.ts b/test/test-server/src/session.ts index 2d17a47ec..49c2eab59 100644 --- a/test/test-server/src/session.ts +++ b/test/test-server/src/session.ts @@ -4,7 +4,7 @@ import * as supertokens from "../../../lib/build"; import SessionRecipe from "../../../lib/build/recipe/session/recipe"; import { logger } from "./logger"; import { getFunc } from "./testFunctionMapper"; -import { convertRequestSessionToSessionObject, deserializeClaim, deserializeValidator } from "./utils"; +import { convertRequestSessionToSessionObject, deserializeClaim, deserializeValidator, maxVersion } from "./utils"; import { logOverrideEvent } from "./overrideLogging"; const namespace = "com.supertokens:node-test-server:session"; @@ -17,7 +17,11 @@ const router = Router() try { logDebugMessage("Session.createNewSessionWithoutRequestResponse %j", req.body); let recipeUserId; - if (["1.17", "2.0"].includes(fdiVersion)) { + if ( + maxVersion("1.17", fdiVersion) === "1.17" || + (maxVersion("2.0", fdiVersion) === fdiVersion && maxVersion("3.0", fdiVersion) !== fdiVersion) + ) { + // fdiVersion <= "1.17" || (fdiVersion >= "2.0" && fdiVersion < "3.0") recipeUserId = supertokens.convertToRecipeUserId(req.body.userId); } else { recipeUserId = supertokens.convertToRecipeUserId(req.body.recipeUserId); diff --git a/test/test-server/src/utils.ts b/test/test-server/src/utils.ts index c892f0ae3..3830825a5 100644 --- a/test/test-server/src/utils.ts +++ b/test/test-server/src/utils.ts @@ -148,7 +148,11 @@ export async function serializeResponse(req, res, response) { } export function serializeUser(response, fdiVersion: string) { - if (["1.17", "2.0"].includes(fdiVersion)) { + // fdiVersion <= "1.17" || (fdiVersion >= "2.0" && fdiVersion < "3.0") + if ( + maxVersion("1.17", fdiVersion) === "1.17" || + (maxVersion("2.0", fdiVersion) === fdiVersion && maxVersion("3.0", fdiVersion) !== fdiVersion) + ) { return { ...("user" in response && response.user instanceof supertokens.User ? { @@ -162,6 +166,7 @@ export function serializeUser(response, fdiVersion: string) { : {}), }; } + return { ...("user" in response && response.user instanceof supertokens.User ? { @@ -172,7 +177,11 @@ export function serializeUser(response, fdiVersion: string) { } export function serializeRecipeUserId(response, fdiVersion: string) { - if (["1.17", "2.0"].includes(fdiVersion)) { + if ( + maxVersion("1.17", fdiVersion) === "1.17" || + (maxVersion("2.0", fdiVersion) === fdiVersion && maxVersion("3.0", fdiVersion) !== fdiVersion) + ) { + // fdiVersion <= "1.17" || (fdiVersion >= "2.0" && fdiVersion < "3.0") return {}; } return { @@ -193,3 +202,22 @@ function popOrUseVal(arrOrValue: T | T[]): T { } return arrOrValue; } + +export function maxVersion(version1: string, version2: string): string { + let splittedv1 = version1.split("."); + let splittedv2 = version2.split("."); + let minLength = Math.min(splittedv1.length, splittedv2.length); + for (let i = 0; i < minLength; i++) { + let v1 = Number(splittedv1[i]); + let v2 = Number(splittedv2[i]); + if (v1 > v2) { + return version1; + } else if (v2 > v1) { + return version2; + } + } + if (splittedv1.length >= splittedv2.length) { + return version1; + } + return version2; +} From a1273de4ba1b46068fb02d912bcede49eb4ec363 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 13:00:21 +0530 Subject: [PATCH 06/11] fix: circle ci scripts --- .circleci/config_continue.yml | 18 +++++ .circleci/doBackendSDKTests.sh | 38 +++++++++ .../setupAndTestBackendSDKWithFreeCore.sh | 81 +++++++++++++++++++ .circleci/setupAndTestWithFreeCore.sh | 33 -------- 4 files changed, 137 insertions(+), 33 deletions(-) create mode 100755 .circleci/doBackendSDKTests.sh create mode 100755 .circleci/setupAndTestBackendSDKWithFreeCore.sh diff --git a/.circleci/config_continue.yml b/.circleci/config_continue.yml index 49dcb27fd..8b5c73744 100644 --- a/.circleci/config_continue.yml +++ b/.circleci/config_continue.yml @@ -36,6 +36,24 @@ jobs: - run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2 - run: (cd .circleci/ && ./doUnitTests.sh << parameters.cdi-version >>) - slack/status + test-backend-sdk-testing: + docker: + - image: rishabhpoddar/supertokens_node_driver_testing_node_20 + resource_class: large + parameters: + cdi-version: + type: string + fdi-version: + type: string + steps: + - checkout + - run: echo "127.0.0.1 localhost.org" >> /etc/hosts + - run: apt-get install lsof + - run: npm i -d --force + - run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2 + - run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2 + - run: (cd .circleci/ && ./doBackendSDKTests.sh << parameters.cdi-version >> << parameters.fdi-version >>) + - slack/status test-website: docker: - image: rishabhpoddar/supertokens_website_sdk_testing diff --git a/.circleci/doBackendSDKTests.sh b/.circleci/doBackendSDKTests.sh new file mode 100755 index 000000000..984a0b79b --- /dev/null +++ b/.circleci/doBackendSDKTests.sh @@ -0,0 +1,38 @@ +echo "Starting tests for CDI $1"; + +if [ -z "$SUPERTOKENS_API_KEY" ]; then + echo "SUPERTOKENS_API_KEY not set" + exit 1 +fi + +coreDriverVersion=$1 +coreDriverVersion=`echo $coreDriverVersion | tr -d '"'` + +frontendDriverVersion=$2 + +coreFree=`curl -s -X GET \ +"https://api.supertokens.io/0/core-driver-interface/dependency/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$coreDriverVersion&driverName=node" \ +-H 'api-version: 1'` +if [[ `echo $coreFree | jq .core` == "null" ]] +then + echo "fetching latest X.Y version for core given core-driver-interface X.Y version: $coreDriverVersion, planType: FREE gave response: $coreFree. Please make sure all relevant cores have been pushed." + exit 1 +fi +coreFree=$(echo $coreFree | jq .core | tr -d '"') + +cd .. +./test/testExports.sh +if [[ $? -ne 0 ]] +then + echo "export test failed... exiting!" + exit 1 +fi +cd .circleci + +./setupAndTestBackendSDKWithFreeCore.sh $coreFree $coreDriverVersion $frontendDriverVersion +if [[ $? -ne 0 ]] +then + echo "test failed... exiting!" + exit 1 +fi +rm -rf ../../supertokens-root \ No newline at end of file diff --git a/.circleci/setupAndTestBackendSDKWithFreeCore.sh b/.circleci/setupAndTestBackendSDKWithFreeCore.sh new file mode 100755 index 000000000..a4a563b0b --- /dev/null +++ b/.circleci/setupAndTestBackendSDKWithFreeCore.sh @@ -0,0 +1,81 @@ +coreInfo=`curl -s -X GET \ +"https://api.supertokens.io/0/core/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$1" \ +-H 'api-version: 0'` +if [[ `echo $coreInfo | jq .tag` == "null" ]] +then + echo "fetching latest X.Y.Z version for core, X.Y version: $1, planType: FREE gave response: $coreInfo" + exit 1 +fi +coreTag=$(echo $coreInfo | jq .tag | tr -d '"') +coreVersion=$(echo $coreInfo | jq .version | tr -d '"') + +pluginInterfaceVersionXY=`curl -s -X GET \ +"https://api.supertokens.io/0/core/dependency/plugin-interface/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$1" \ +-H 'api-version: 0'` +if [[ `echo $pluginInterfaceVersionXY | jq .pluginInterface` == "null" ]] +then + echo "fetching latest X.Y version for plugin-interface, given core X.Y version: $1, planType: FREE gave response: $pluginInterfaceVersionXY" + exit 1 +fi +pluginInterfaceVersionXY=$(echo $pluginInterfaceVersionXY | jq .pluginInterface | tr -d '"') + +pluginInterfaceInfo=`curl -s -X GET \ +"https://api.supertokens.io/0/plugin-interface/latest?password=$SUPERTOKENS_API_KEY&planType=FREE&mode=DEV&version=$pluginInterfaceVersionXY" \ +-H 'api-version: 0'` +if [[ `echo $pluginInterfaceInfo | jq .tag` == "null" ]] +then + echo "fetching latest X.Y.Z version for plugin-interface, X.Y version: $pluginInterfaceVersionXY, planType: FREE gave response: $pluginInterfaceInfo" + exit 1 +fi +pluginInterfaceTag=$(echo $pluginInterfaceInfo | jq .tag | tr -d '"') +pluginInterfaceVersion=$(echo $pluginInterfaceInfo | jq .version | tr -d '"') + +echo "Testing with FREE core: $coreVersion, plugin-interface: $pluginInterfaceVersion" + +cd ../../ +git clone git@github.com:supertokens/supertokens-root.git +cd supertokens-root +if [[ $2 == "2.0" ]] || [[ $2 == "2.1" ]] || [[ $2 == "2.2" ]] +then + git checkout 36e5af1b9a4e3b07247d0cf333cf82a071a78681 +fi +echo -e "core,$1\nplugin-interface,$pluginInterfaceVersionXY" > modules.txt +./loadModules --ssh +cd supertokens-core +git checkout $coreTag +cd ../supertokens-plugin-interface +git checkout $pluginInterfaceTag +cd ../ +echo $SUPERTOKENS_API_KEY > apiPassword +./utils/setupTestEnvLocal +cd ../project/ + +# Set the script to exit on error +set -e + +API_PORT=3030 +ST_CONNECTION_URI=http://localhost:8081 + +# start test-server +pushd test/test-server +npm install +API_PORT=$API_PORT ST_CONNECTION_URI=$ST_CONNECTION_URI npm start & +popd + +frontendDriverVersion=$3 +# run tests +cd ../ +git clone git@github.com:supertokens/backend-sdk-testing.git +cd backend-sdk-testing +git checkout $frontendDriverVersion +npm install +npm run build + +if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then + API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npx mocha --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --no-config --timeout 500000 $(npx mocha-split-tests -r ./runtime.log -t $CIRCLE_NODE_TOTAL -g $CIRCLE_NODE_INDEX -f 'test/**/*.test.js') +else + API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test +fi + +# kill test-server +kill $(lsof -t -i:$API_PORT) diff --git a/.circleci/setupAndTestWithFreeCore.sh b/.circleci/setupAndTestWithFreeCore.sh index 258b0a6d5..83b0f8201 100755 --- a/.circleci/setupAndTestWithFreeCore.sh +++ b/.circleci/setupAndTestWithFreeCore.sh @@ -58,36 +58,3 @@ if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then else TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test fi - -API_PORT=3030 -ST_CONNECTION_URI=http://localhost:8081 - -# start test-server -pushd test/test-server -npm install -API_PORT=$API_PORT ST_CONNECTION_URI=$ST_CONNECTION_URI npm start & -popd - -# lets read frontendDriverInterfaceSupported -frontendDriverJson=`cat ./frontendDriverInterfaceSupported.json` -# get versions -frontendDriverArray=`echo $frontendDriverJson | jq ".versions"` -# use latest version -frontendDriverVersion=`echo $frontendDriverArray | jq ".[-1]" | tr -d '"'` - -# run tests -cd ../ -git clone git@github.com:supertokens/backend-sdk-testing.git -cd backend-sdk-testing -git checkout $frontendDriverVersion -npm install -npm run build - -if ! [[ -z "${CIRCLE_NODE_TOTAL}" ]]; then - API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npx mocha --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --no-config --timeout 500000 $(npx mocha-split-tests -r ./runtime.log -t $CIRCLE_NODE_TOTAL -g $CIRCLE_NODE_INDEX -f 'test/**/*.test.js') -else - API_PORT=$API_PORT TEST_MODE=testing SUPERTOKENS_CORE_TAG=$coreTag NODE_PORT=8081 INSTALL_PATH=../supertokens-root npm test -fi - -# kill test-server -kill $(lsof -t -i:$API_PORT) \ No newline at end of file From d24a203eb0957dedcb2d5a3607e236860ffa2b56 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 13:04:46 +0530 Subject: [PATCH 07/11] fix: circle ci testing --- .circleci/config.yml | 11 +++-- .circleci/config_continue.yml | 93 ++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 78230c4c8..403efaa77 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,11 +53,12 @@ workflows: branches: ignore: /.*/ - setup: - filters: - tags: - only: /dev-v[0-9]+(\.[0-9]+)*/ - branches: - only: /test-cicd\/.*/ + {} + # filters: + # tags: + # only: /dev-v[0-9]+(\.[0-9]+)*/ + # branches: + # only: /test-cicd\/.*/ - update-docs: context: - slack-notification diff --git a/.circleci/config_continue.yml b/.circleci/config_continue.yml index 8b5c73744..2bb896c61 100644 --- a/.circleci/config_continue.yml +++ b/.circleci/config_continue.yml @@ -119,54 +119,69 @@ workflows: only: /dev-v[0-9]+(\.[0-9]+)*/ branches: only: /test-cicd\/.*/ - - test-unit: + # - test-unit: + # requires: + # - test-dev-tag-as-not-passed + # context: + # - slack-notification + # filters: + # tags: + # only: /dev-v[0-9]+(\.[0-9]+)*/ + # branches: + # only: /test-cicd\/.*/ + # matrix: + # parameters: + # cdi-version: placeholder + - test-backend-sdk-testing: requires: - test-dev-tag-as-not-passed context: - slack-notification - filters: - tags: - only: /dev-v[0-9]+(\.[0-9]+)*/ - branches: - only: /test-cicd\/.*/ + # filters: + # tags: + # only: /dev-v[0-9]+(\.[0-9]+)*/ + # branches: + # only: /test-cicd\/.*/ matrix: parameters: cdi-version: placeholder - - test-website: - requires: - - test-dev-tag-as-not-passed - context: - - slack-notification - filters: - tags: - only: /dev-v[0-9]+(\.[0-9]+)*/ - branches: - only: /test-cicd\/.*/ - matrix: - parameters: - fdi-version: placeholder - - test-authreact: - requires: - - test-dev-tag-as-not-passed - context: - - slack-notification - filters: - tags: - only: /dev-v[0-9]+(\.[0-9]+)*/ - branches: - only: /test-cicd\/.*/ - matrix: - parameters: fdi-version: placeholder + # - test-website: + # requires: + # - test-dev-tag-as-not-passed + # context: + # - slack-notification + # filters: + # tags: + # only: /dev-v[0-9]+(\.[0-9]+)*/ + # branches: + # only: /test-cicd\/.*/ + # matrix: + # parameters: + # fdi-version: placeholder + # - test-authreact: + # requires: + # - test-dev-tag-as-not-passed + # context: + # - slack-notification + # filters: + # tags: + # only: /dev-v[0-9]+(\.[0-9]+)*/ + # branches: + # only: /test-cicd\/.*/ + # matrix: + # parameters: + # fdi-version: placeholder - test-success: requires: - - test-unit - - test-website - - test-authreact + # - test-unit + - test-backend-sdk-testing + # - test-website + # - test-authreact context: - slack-notification - filters: - tags: - only: /dev-v[0-9]+(\.[0-9]+)*/ - branches: - ignore: /.*/ + # filters: + # tags: + # only: /dev-v[0-9]+(\.[0-9]+)*/ + # branches: + # ignore: /.*/ From 821a54b6c34bee6b378ecef58556ad962e478d9a Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 13:06:37 +0530 Subject: [PATCH 08/11] fix: circle ci testing --- .circleci/config_continue.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.circleci/config_continue.yml b/.circleci/config_continue.yml index 2bb896c61..222f5b80d 100644 --- a/.circleci/config_continue.yml +++ b/.circleci/config_continue.yml @@ -114,11 +114,12 @@ workflows: tagged-build: jobs: - test-dev-tag-as-not-passed: - filters: - tags: - only: /dev-v[0-9]+(\.[0-9]+)*/ - branches: - only: /test-cicd\/.*/ + {} + # filters: + # tags: + # only: /dev-v[0-9]+(\.[0-9]+)*/ + # branches: + # only: /test-cicd\/.*/ # - test-unit: # requires: # - test-dev-tag-as-not-passed From b21bef89289db4000b6400a542087d1f073dde1d Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 13:08:21 +0530 Subject: [PATCH 09/11] fix: circle ci testing --- .circleci/config_continue.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config_continue.yml b/.circleci/config_continue.yml index 222f5b80d..0b84142a5 100644 --- a/.circleci/config_continue.yml +++ b/.circleci/config_continue.yml @@ -41,10 +41,10 @@ jobs: - image: rishabhpoddar/supertokens_node_driver_testing_node_20 resource_class: large parameters: - cdi-version: - type: string - fdi-version: - type: string + cdi-version: + type: string + fdi-version: + type: string steps: - checkout - run: echo "127.0.0.1 localhost.org" >> /etc/hosts From d4ef27afa0fa1f3c912a24317218f9d41aae1789 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 17:30:41 +0530 Subject: [PATCH 10/11] fix: test server --- test/test-server/src/accountlinking.ts | 9 +++------ test/test-server/src/passwordless.ts | 20 ++++---------------- test/test-server/src/thirdparty.ts | 8 ++------ 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/test/test-server/src/accountlinking.ts b/test/test-server/src/accountlinking.ts index 280e47ccc..6763deaac 100644 --- a/test/test-server/src/accountlinking.ts +++ b/test/test-server/src/accountlinking.ts @@ -4,7 +4,7 @@ import AccountLinkingRecipe from "../../../lib/build/recipe/accountlinking/recip import AccountLinking from "../../../recipe/accountlinking"; import * as supertokens from "../../../lib/build"; import { logger } from "./logger"; -import { serializeUser } from "./utils"; +import { serializeResponse, serializeUser } from "./utils"; const namespace = "com.supertokens:node-test-server:accountlinking"; const { logDebugMessage } = logger(namespace); @@ -15,7 +15,7 @@ const router = Router() logDebugMessage("AccountLinking:createPrimaryUser %j", req.body); const recipeUserId = supertokens.convertToRecipeUserId(req.body.recipeUserId); const response = await AccountLinking.createPrimaryUser(recipeUserId, req.body.userContext); - res.json({ ...response, ...serializeUser(response) }); + await serializeResponse(req, res, response); } catch (e) { next(e); } @@ -29,10 +29,7 @@ const router = Router() req.body.primaryUserId, req.body.userContext ); - res.json({ - ...response, - ...serializeUser(response), - }); + await serializeResponse(req, res, response); } catch (e) { next(e); } diff --git a/test/test-server/src/passwordless.ts b/test/test-server/src/passwordless.ts index cc8c7fd99..6815eb2b9 100644 --- a/test/test-server/src/passwordless.ts +++ b/test/test-server/src/passwordless.ts @@ -1,7 +1,7 @@ import { Router } from "express"; import SuperTokens from "../../.."; import Passwordless from "../../../recipe/passwordless"; -import { convertRequestSessionToSessionObject, serializeRecipeUserId, serializeUser } from "./utils"; +import { convertRequestSessionToSessionObject, serializeRecipeUserId, serializeResponse, serializeUser } from "./utils"; import { logger } from "./logger"; const namespace = "com.supertokens:node-test-server:passwordless"; @@ -23,11 +23,7 @@ const router = Router() session: req.body.session && (await convertRequestSessionToSessionObject(req.body.session)), userContext: req.body.userContext, }); - res.json({ - ...response, - ...serializeUser(response), - ...serializeRecipeUserId(response), - }); + await serializeResponse(req, res, response); } catch (e) { next(e); } @@ -60,11 +56,7 @@ const router = Router() session: req.body.session && (await convertRequestSessionToSessionObject(req.body.session)), userContext: req.body.userContext, }); - res.json({ - ...response, - ...serializeUser(response), - ...serializeRecipeUserId(response), - }); + await serializeResponse(req, res, response); } catch (e) { next(e); } @@ -78,11 +70,7 @@ const router = Router() phoneNumber: req.body.phoneNumber, userContext: req.body.userContext, }); - res.json({ - ...response, - ...serializeUser(response), - ...serializeRecipeUserId(response), - }); + await serializeResponse(req, res, response); } catch (e) { next(e); } diff --git a/test/test-server/src/thirdparty.ts b/test/test-server/src/thirdparty.ts index a1e574356..53fcdfbaa 100644 --- a/test/test-server/src/thirdparty.ts +++ b/test/test-server/src/thirdparty.ts @@ -1,6 +1,6 @@ import { Router } from "express"; import ThirdParty from "../../../recipe/thirdparty"; -import { convertRequestSessionToSessionObject, serializeRecipeUserId, serializeUser } from "./utils"; +import { convertRequestSessionToSessionObject, serializeRecipeUserId, serializeResponse, serializeUser } from "./utils"; import { logger } from "./logger"; const namespace = "com.supertokens:node-test-server:thirdparty"; @@ -19,11 +19,7 @@ const router = Router().post("/manuallycreateorupdateuser", async (req, res, nex session, req.body.userContext ); - res.json({ - ...response, - ...serializeUser(response), - ...serializeRecipeUserId(response), - }); + await serializeResponse(req, res, response); } catch (e) { next(e); } From a2317863ffd3b948986e491bd93ba3e8ca7d39d3 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Mon, 5 Aug 2024 17:47:31 +0530 Subject: [PATCH 11/11] fix: circle ci restore --- .circleci/config.yml | 11 ++-- .circleci/config_continue.yml | 110 ++++++++++++++++------------------ 2 files changed, 57 insertions(+), 64 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 403efaa77..78230c4c8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -53,12 +53,11 @@ workflows: branches: ignore: /.*/ - setup: - {} - # filters: - # tags: - # only: /dev-v[0-9]+(\.[0-9]+)*/ - # branches: - # only: /test-cicd\/.*/ + filters: + tags: + only: /dev-v[0-9]+(\.[0-9]+)*/ + branches: + only: /test-cicd\/.*/ - update-docs: context: - slack-notification diff --git a/.circleci/config_continue.yml b/.circleci/config_continue.yml index 0b84142a5..08b69e726 100644 --- a/.circleci/config_continue.yml +++ b/.circleci/config_continue.yml @@ -114,75 +114,69 @@ workflows: tagged-build: jobs: - test-dev-tag-as-not-passed: - {} - # filters: - # tags: - # only: /dev-v[0-9]+(\.[0-9]+)*/ - # branches: - # only: /test-cicd\/.*/ - # - test-unit: - # requires: - # - test-dev-tag-as-not-passed - # context: - # - slack-notification - # filters: - # tags: - # only: /dev-v[0-9]+(\.[0-9]+)*/ - # branches: - # only: /test-cicd\/.*/ - # matrix: - # parameters: - # cdi-version: placeholder + - test-unit: + requires: + - test-dev-tag-as-not-passed + context: + - slack-notification + filters: + tags: + only: /dev-v[0-9]+(\.[0-9]+)*/ + branches: + only: /test-cicd\/.*/ + matrix: + parameters: + cdi-version: placeholder - test-backend-sdk-testing: requires: - test-dev-tag-as-not-passed context: - slack-notification - # filters: - # tags: - # only: /dev-v[0-9]+(\.[0-9]+)*/ - # branches: - # only: /test-cicd\/.*/ + filters: + tags: + only: /dev-v[0-9]+(\.[0-9]+)*/ + branches: + only: /test-cicd\/.*/ matrix: parameters: cdi-version: placeholder fdi-version: placeholder - # - test-website: - # requires: - # - test-dev-tag-as-not-passed - # context: - # - slack-notification - # filters: - # tags: - # only: /dev-v[0-9]+(\.[0-9]+)*/ - # branches: - # only: /test-cicd\/.*/ - # matrix: - # parameters: - # fdi-version: placeholder - # - test-authreact: - # requires: - # - test-dev-tag-as-not-passed - # context: - # - slack-notification - # filters: - # tags: - # only: /dev-v[0-9]+(\.[0-9]+)*/ - # branches: - # only: /test-cicd\/.*/ - # matrix: - # parameters: - # fdi-version: placeholder + - test-website: + requires: + - test-dev-tag-as-not-passed + context: + - slack-notification + filters: + tags: + only: /dev-v[0-9]+(\.[0-9]+)*/ + branches: + only: /test-cicd\/.*/ + matrix: + parameters: + fdi-version: placeholder + - test-authreact: + requires: + - test-dev-tag-as-not-passed + context: + - slack-notification + filters: + tags: + only: /dev-v[0-9]+(\.[0-9]+)*/ + branches: + only: /test-cicd\/.*/ + matrix: + parameters: + fdi-version: placeholder - test-success: requires: - # - test-unit + - test-unit - test-backend-sdk-testing - # - test-website - # - test-authreact + - test-website + - test-authreact context: - slack-notification - # filters: - # tags: - # only: /dev-v[0-9]+(\.[0-9]+)*/ - # branches: - # ignore: /.*/ + filters: + tags: + only: /dev-v[0-9]+(\.[0-9]+)*/ + branches: + ignore: /.*/