Skip to content

Commit

Permalink
fix: test server compatible with 1.17/2.0 (#897)
Browse files Browse the repository at this point in the history
* fix: test server compatible with 1.17

* fix: pr comments

* fix: mfa claim

* fix: version and changelog

* fix: using version function for comparision

* fix: circle ci scripts

* fix: circle ci testing

* fix: circle ci testing

* fix: circle ci testing

* fix: test server

* fix: circle ci restore
  • Loading branch information
sattvikc authored Aug 5, 2024
1 parent cbf5e02 commit 7fc633c
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 90 deletions.
30 changes: 29 additions & 1 deletion .circleci/config_continue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,12 +114,20 @@ workflows:
tagged-build:
jobs:
- test-dev-tag-as-not-passed:
- 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\/.*/
- test-unit:
matrix:
parameters:
cdi-version: placeholder
- test-backend-sdk-testing:
requires:
- test-dev-tag-as-not-passed
context:
Expand All @@ -114,6 +140,7 @@ workflows:
matrix:
parameters:
cdi-version: placeholder
fdi-version: placeholder
- test-website:
requires:
- test-dev-tag-as-not-passed
Expand Down Expand Up @@ -143,6 +170,7 @@ workflows:
- test-success:
requires:
- test-unit
- test-backend-sdk-testing
- test-website
- test-authreact
context:
Expand Down
38 changes: 38 additions & 0 deletions .circleci/doBackendSDKTests.sh
Original file line number Diff line number Diff line change
@@ -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
81 changes: 81 additions & 0 deletions .circleci/setupAndTestBackendSDKWithFreeCore.sh
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 0 additions & 33 deletions .circleci/setupAndTestWithFreeCore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ export declare class MultiFactorAuthClaimClass extends SessionClaim<MFAClaimValu
) => {
[x: string]: import("../../types").JSONValue;
};
removeFromPayloadByMerge_internal: () => {
[x: string]: null;
removeFromPayloadByMerge_internal: (
payload: JSONObject
) => {
[x: string]: import("../../types").JSONValue;
};
getValueFromPayload: (payload: JSONObject) => MFAClaimValue;
}
Expand Down
6 changes: 2 additions & 4 deletions lib/build/recipe/multifactorauth/multiFactorAuthClaim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/ts/recipe/multifactorauth/multiFactorAuthClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ export class MultiFactorAuthClaimClass extends SessionClaim<MFAClaimValue> {
return retVal;
};

public removeFromPayloadByMerge_internal = () => {
public removeFromPayloadByMerge_internal = (payload: JSONObject) => {
return {
...payload,
[this.key]: null,
};
};
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 3 additions & 6 deletions test/test-server/src/accountlinking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
14 changes: 3 additions & 11 deletions test/test-server/src/emailpassword.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -19,11 +19,7 @@ const router = Router()
session,
req.body.userContext
);
res.json({
...response,
...serializeUser(response),
...serializeRecipeUserId(response),
});
await serializeResponse(req, res, response);
} catch (e) {
next(e);
}
Expand All @@ -39,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);
}
Expand Down
Loading

0 comments on commit 7fc633c

Please sign in to comment.