diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 0000000000..4eadc5406c --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,60 @@ +name: "Unit Tests" + +on: + pull_request: + types: + - opened + - reopened + - synchronize + push: + branches: + - master + - "v[0-9]+.[0-9]+" + tags: + - "(dev-)?v[0-9]+.[0-9]+.[0-9]+" + +jobs: + define-versions: + runs-on: ubuntu-latest + outputs: + fdiVersions: ${{ steps.versions.outputs.fdiVersions }} + cdiVersions: ${{ steps.versions.outputs.cdiVersions }} + nodeVersions: '["18.20", "20.19", "22.14"]' + steps: + - uses: actions/checkout@v4 + - uses: supertokens/get-supported-versions-action@main + id: versions + with: + has-fdi: true + has-cdi: true + + test: + runs-on: ubuntu-latest + needs: define-versions + strategy: + fail-fast: false + matrix: + node-version: ${{ fromJSON(needs.define-versions.outputs.nodeVersions) }} + cdi-version: ${{ fromJSON(needs.define-versions.outputs.cdiVersions) }} + steps: + - uses: actions/checkout@v4 + - uses: supertokens/get-versions-action@main + id: versions + with: + driver-name: node + cdi-version: ${{ matrix.cdi-version }} + env: + SUPERTOKENS_API_KEY: ${{ secrets.SUPERTOKENS_API_KEY }} + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: | + npm install + - name: Run unit tests + run: | + docker compose up --wait + npm run test + docker compose down + env: + SUPERTOKENS_CORE_VERSION: ${{ steps.versions.outputs.coreVersionXy }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index cfbfc38b10..3cca9c4c01 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ releasePassword /temp_* /.nyc_output .circleci/.pat +test-results* diff --git a/.mocharc.yml b/.mocharc.yml index 689f11545e..a5629d6b91 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -2,5 +2,8 @@ spec: test/**/*.test.* extension: [ts, js] exit: true slow: 10000 -timeout: 20000 -reporter: spec +timeout: 40000 +reporter: mocha-multi-reporters +require: test/hooks.js +reporter-option: + - configFile=mocha-multi-reporters.json \ No newline at end of file diff --git a/mocha-multi-reporters.json b/mocha-multi-reporters.json new file mode 100644 index 0000000000..d25ee0b78f --- /dev/null +++ b/mocha-multi-reporters.json @@ -0,0 +1,9 @@ +{ + "reporterEnabled": "spec, mocha-junit-reporter, mocha-json-output-reporter", + "mochaJunitReporterReporterOptions": { + "mochaFile": "test-results.xml" + }, + "mochaJsonOutputReporterReporterOptions": { + "output": "test-results.json" + } +} \ No newline at end of file diff --git a/package.json b/package.json index 23a15c5303..ff8a68b01c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "NodeJS driver for SuperTokens core", "main": "index.js", "scripts": { - "test": "TEST_MODE=testing npx ts-mocha -p lib/tsconfig.json -n loader=ts-node/esm --node-option no-experimental-fetch -r test/fetch-polyfill.mjs --timeout 500000", + "test": "TEST_MODE=testing npx ts-mocha -p lib/tsconfig.json -n loader=ts-node/esm --node-option no-experimental-fetch -r test/fetch-polyfill.mjs", "test-exports": "./test/testExports.sh", "build-check": "cd lib && npx tsc -p tsconfig.json --noEmit && cd ../test/with-typescript && npm run build", "build": "cd lib && rm -rf build && npx tsc -p tsconfig.json && cd ../test/with-typescript && npm run build && cd ../.. && npm run post-build", @@ -137,7 +137,7 @@ "pako": "^2.1.0", "pkce-challenge": "^3.0.0", "process": "^0.11.10", - "set-cookie-parser": "^2.6.0", + "set-cookie-parser": "^2.7.1", "supertokens-js-override": "^0.0.4", "tldts": "^6.1.48", "twilio": "^4.19.3" @@ -173,8 +173,11 @@ "loopback-datasource-juggler": "^4.26.0", "mocha": "^10.2.0", "mocha-split-tests": "github:rishabhpoddar/mocha-split-tests", + "mocha-json-output-reporter": "^2.1.0", + "mocha-junit-reporter": "^2.2.1", + "mocha-multi-reporters": "^1.5.1", "next": "^14.0.4", - "next-test-api-route-handler": "^3.1.10", + "next-test-api-route-handler": "^4.0.16", "nock": "11.7.0", "node-fetch": "^3.3.2", "nyc": "^15.1.0", @@ -193,4 +196,4 @@ "browser": { "fs": false } -} +} \ No newline at end of file diff --git a/test/auth-modes.test.js b/test/auth-modes.test.js index 0ed01e5808..9370818c98 100644 --- a/test/auth-modes.test.js +++ b/test/auth-modes.test.js @@ -14,12 +14,11 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, - setKeyValueInConfig, + delay, } = require("./utils"); const assert = require("assert"); @@ -37,8 +36,6 @@ const exampleJWT = describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); @@ -46,16 +43,12 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { sinon.restore(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("with default getTokenTransferMethod", () => { describe("createNewSession", () => { describe("with default getTokenTransferMethod", () => { it("should default to header based session w/ no auth-mode header", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); + SuperTokens.init({ supertokens: { connectionURI, @@ -79,7 +72,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should default to header based session w/ bad auth-mode header", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -103,7 +96,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use headers if auth-mode specifies it", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -127,7 +120,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use cookies if auth-mode specifies it", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -157,7 +150,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { describe("with user provided getTokenTransferMethod", () => { it("should use headers if getTokenTransferMethod returns any and there is no st-auth-mode header", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -181,7 +174,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use cookies if getTokenTransferMethod returns any and st-auth-mode is set to cookie", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -205,7 +198,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use headers if getTokenTransferMethod returns any and st-auth-mode is set to header", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -229,7 +222,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use headers if getTokenTransferMethod returns header", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -253,7 +246,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use clear cookies (if present) if getTokenTransferMethod returns header", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -293,7 +286,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use cookies if getTokenTransferMethod returns cookie", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -321,7 +314,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should clear headers (if present) if getTokenTransferMethod returns cookie", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -393,7 +386,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { for (let i = 0; i < behaviourTable.length; ++i) { const conf = behaviourTable[i]; it(`should match line ${i + 1} with a valid token`, async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -445,7 +438,8 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it(`should match line ${i + 1} with a expired token`, async () => { - const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } }); + SuperTokens.init({ supertokens: { connectionURI, @@ -500,7 +494,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { describe("with access tokens in both headers and cookies", () => { it("should use the value from headers if getTokenTransferMethod returns any", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -547,7 +541,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use the value from headers if getTokenTransferMethod returns header", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -595,7 +589,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should use the value from cookies if getTokenTransferMethod returns cookie", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -644,7 +638,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should reject requests with sIdRefreshToken", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -687,7 +681,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { describe("with non ST in Authorize header", () => { it("should use the value from cookies if present and getTokenTransferMethod returns any", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -730,7 +724,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should reject with UNAUTHORISED if getTokenTransferMethod returns header", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -774,7 +768,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should reject with UNAUTHORISED if cookies are not present", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -815,7 +809,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { describe("mergeIntoAccessTokenPayload", () => { it("should update cookies if the session was cookie based", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -852,7 +846,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { }); it("should allow headers if the session was header based", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -910,7 +904,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { for (let i = 0; i < behaviourTable.length; ++i) { const conf = behaviourTable[i]; it(`should match line ${i + 1} with a valid token`, async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1011,7 +1005,7 @@ describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () { const conf = behaviourTable[i]; it(`should match line ${i + 1} with a invalid token`, async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/config.test.js b/test/config.test.js index ba089e73d1..e05c0e4703 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, extractInfoFromResponse, mockResponse, @@ -48,20 +46,13 @@ const { logDebugMessage } = require("../lib/build/logger"); describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // test various inputs for appInfo // Failure condition: passing data of invalid type/ syntax to appInfo it("test values for optional inputs for appInfo", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { STExpress.init({ @@ -118,7 +109,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("test values for compulsory inputs for appInfo", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { try { @@ -199,7 +190,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { // test using zero, one and two recipe modules // Failure condition: initial supertokens with the incorrect number of modules as specified in the checks it("test using zero, one and two recipe modules", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { try { @@ -262,7 +253,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { // test config for session module // Failure condition: passing data of invalid type/ syntax to the modules config it("test config for session module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -287,7 +278,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("various sameSite values", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { STExpress.init({ @@ -463,7 +454,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("sameSite none invalid domain values", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const domainCombinations = [ ["http://localhost:3000", "http://supertokensapi.io"], ["http://127.0.0.1:3000", "http://supertokensapi.io"], @@ -700,7 +691,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("various config values", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { STExpress.init({ @@ -842,7 +833,9 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { let hosts = Querier.hosts; assert(hosts.length === 4); - assert(hosts[0].domain.getAsStringDangerous() === "http://localhost:8080"); + assert( + hosts[0].domain.getAsStringDangerous() === new NormalisedURLDomain(connectionURI).getAsStringDangerous() + ); assert(hosts[1].domain.getAsStringDangerous() === "https://try.supertokens.io"); assert(hosts[2].domain.getAsStringDangerous() === "https://try.supertokens.io:8080"); assert(hosts[3].domain.getAsStringDangerous() === "http://localhost:90"); @@ -1209,7 +1202,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("testing that the debug mode is set", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let logs = []; // Used to capture the log strings debug.log = function (...args) { logs.push(args); @@ -1275,7 +1268,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { it("testing that the debug mode is set via env var", async function () { let oldEnv = process.env; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let logs = []; // Used to capture the log strings debug.log = function (...args) { logs.push(args); @@ -1327,7 +1320,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("checking for default cookie config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1350,7 +1343,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Test that the JWKS and OpenId endpoints are exposed by default", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1393,7 +1386,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("should work well with ec2 public urls", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { STExpress.init({ @@ -1460,7 +1453,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("apiGatewayPath test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { STExpress.init({ supertokens: { @@ -1641,7 +1634,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("checking for empty item in recipeList config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let errorCaught = true; try { STExpress.init({ @@ -1663,7 +1656,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Check that telemetry is set to true properly", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1681,7 +1674,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Check that telemetry is set to false by default", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1698,7 +1691,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Check that telemetry is set to false properly", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1716,7 +1709,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Test that init throws if both website domain and origin is undefined", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); try { STExpress.init({ supertokens: { @@ -1741,7 +1734,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Test that init works fine when using origin", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1760,7 +1753,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Test that init works fine when using a function for origin", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1779,7 +1772,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Test that origin function returns correctly", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1803,7 +1796,7 @@ describe(`configTest: ${printPath("[test/config.test.js]")}`, function () { }); it("Test that if both website domain and origin are provided, origin is used", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/customFramework.test.js b/test/customFramework.test.js index b78966e993..ceffc076d8 100644 --- a/test/customFramework.test.js +++ b/test/customFramework.test.js @@ -7,10 +7,11 @@ const { } = require("../lib/build/customFramework"); let { ProcessState } = require("../lib/build/processState"); let SuperTokens = require("../lib/build/").default; +let SuperTokensWrapper = require("../lib/build/supertokens").default; const Session = require("../lib/build/recipe/session"); const EmailPassword = require("../lib/build/recipe/emailpassword"); const { PreParsedRequest } = require("../lib/build/framework/custom"); -const { printPath, setupST, startST, killAllST, cleanST } = require("./utils"); +const { printPath, createCoreApplication, getCoreUrlFromConnectionURI } = require("./utils"); const { generateKeyPair, SignJWT, exportJWK, importJWK, decodeJwt } = require("jose"); // Helper function to create a JWKS @@ -66,16 +67,14 @@ async function signJWT(privateKey, jwks, payload, expiresIn = "2h") { } describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, () => { - let connectionURI; - let accessToken, accessTokenPayload; let privateKey, jwks; - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - connectionURI = await startST(); + ProcessState.getInstance().reset(); + const connectionURI = await createCoreApplication(); + SuperTokens.init({ supertokens: { connectionURI, @@ -110,16 +109,15 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, jwks = jwksGenerated; }); - after(async function () { - await killAllST(); - await cleanST(); - }); - const CustomResponse = class extends Response {}; it("should sign-up successfully", async () => { const handleCall = handleAuthAPIRequest(CustomResponse); + const connectionURI = getCoreUrlFromConnectionURI( + SuperTokensWrapper.getInstanceOrThrowError().supertokens.connectionURI + ); + const mockRequest = new Request(`${connectionURI}/api/auth/signup/`, { method: "POST", headers: { @@ -154,7 +152,31 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, it("should sign-in successfully", async () => { const handleCall = handleAuthAPIRequest(CustomResponse); - const mockRequest = new Request(`${connectionURI}/api/auth/signin/`, { + const connectionURI = getCoreUrlFromConnectionURI( + SuperTokensWrapper.getInstanceOrThrowError().supertokens.connectionURI + ); + + const mockSignUpRequest = new Request(`${connectionURI}/api/auth/signup/`, { + method: "POST", + headers: { + rid: "emailpassword", + }, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + await handleCall(mockSignUpRequest); + + const mockSignInRequest = new Request(`${connectionURI}/api/auth/signin/`, { method: "POST", headers: { rid: "emailpassword", @@ -174,7 +196,7 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, }); // Call handleCall - const response = await handleCall(mockRequest); + const response = await handleCall(mockSignInRequest); // Assertions for response assert.strictEqual(response.status, 200, "Should return status 200"); @@ -186,8 +208,7 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, "User email should be returned correctly" ); - accessToken = response.headers.get("st-access-token"); - accessTokenPayload = decodeJwt(accessToken); + const accessToken = response.headers.get("st-access-token"); assert.ok(accessToken, "st-access-token header should be set"); assert.ok(response.headers.get("st-refresh-token"), "st-refresh-token header should be set"); @@ -196,6 +217,54 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, // Case 1: Successful => add session to request object. it("withSession should create a session properly", async () => { + const handleCall = handleAuthAPIRequest(CustomResponse); + + const connectionURI = getCoreUrlFromConnectionURI( + SuperTokensWrapper.getInstanceOrThrowError().supertokens.connectionURI + ); + + const mockSignUpRequest = new Request(`${connectionURI}/api/auth/signup/`, { + method: "POST", + headers: { + rid: "emailpassword", + }, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + await handleCall(mockSignUpRequest); + + const mockSignInRequest = new Request(`${connectionURI}/api/auth/signin/`, { + method: "POST", + headers: { + rid: "emailpassword", + }, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + const signInResponse = await handleCall(mockSignInRequest); + + const accessToken = signInResponse.headers.get("st-access-token"); + const mockSessionRequest = new Request(`${connectionURI}/api/user/`, { method: "POST", headers: { @@ -250,6 +319,52 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, // Case 2: Error => throws error when no access token is passed. it("withSession should pass error when session fails", async () => { + const handleCall = handleAuthAPIRequest(CustomResponse); + + const connectionURI = getCoreUrlFromConnectionURI( + SuperTokensWrapper.getInstanceOrThrowError().supertokens.connectionURI + ); + + const mockSignUpRequest = new Request(`${connectionURI}/api/auth/signup/`, { + method: "POST", + headers: { + rid: "emailpassword", + }, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + await handleCall(mockSignUpRequest); + + const mockSignInRequest = new Request(`${connectionURI}/api/auth/signin/`, { + method: "POST", + headers: { + rid: "emailpassword", + }, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + const signInResponse = await handleCall(mockSignInRequest); + const mockSessionRequest = new Request(`${connectionURI}/api/user/`, { method: "POST", headers: { @@ -281,6 +396,10 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, it("should return 404 for unhandled routes", async () => { const handleCall = handleAuthAPIRequest(CustomResponse); + const connectionURI = getCoreUrlFromConnectionURI( + SuperTokensWrapper.getInstanceOrThrowError().supertokens.connectionURI + ); + const mockRequest = new Request(`${connectionURI}/api/auth/test/`, { method: "GET", headers: { @@ -296,6 +415,55 @@ describe(`handleAuthAPIRequest ${printPath("[test/customFramework.test.js]")}`, }); it("getSessionForSSR should return session for valid token", async () => { + const handleCall = handleAuthAPIRequest(CustomResponse); + + const connectionURI = getCoreUrlFromConnectionURI( + SuperTokensWrapper.getInstanceOrThrowError().supertokens.connectionURI + ); + + const mockSignUpRequest = new Request(`${connectionURI}/api/auth/signup/`, { + method: "POST", + headers: { + rid: "emailpassword", + }, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + await handleCall(mockSignUpRequest); + + const mockSignInRequest = new Request(`${connectionURI}/api/auth/signin/`, { + method: "POST", + headers: { + rid: "emailpassword", + }, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + const signInResponse = await handleCall(mockSignInRequest); + + const accessToken = signInResponse.headers.get("st-access-token"); + const accessTokenPayload = decodeJwt(accessToken); + // Create a mock request containing the valid token as a cookie const mockRequest = new Request("https://example.com", { headers: { Cookie: `sAccessToken=${accessToken}` }, diff --git a/test/dashboard.test.js b/test/dashboard.test.js index 95540b99a0..a7cad1e7f5 100644 --- a/test/dashboard.test.js +++ b/test/dashboard.test.js @@ -1,12 +1,11 @@ const { printPath, - setupST, - startSTWithMultitenancyAndAccountLinki, - startSTWithMultitenancyAndAccountLinkingng, - killAllST, - cleanST, + + createCoreApplicationWithMultitenancyAndAccountLinki, + createCoreApplicationWithMultitenancyAndAccountLinkingng, + resetAll, - startSTWithMultitenancyAndAccountLinking, + createCoreApplicationWithMultitenancyAndAccountLinking, } = require("./utils"); let STExpress = require("../"); let Session = require("../recipe/session"); @@ -26,18 +25,11 @@ let { middleware, errorHandler } = require("../framework/express"); describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that normalised config is generated correctly", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); { STExpress.init({ @@ -82,7 +74,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { describe("with account linking", () => { it("should get user info with first&last names", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -225,7 +217,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { }); it("should reset password of linked user", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -318,7 +310,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { }); it("should link accounts after verification", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -404,7 +396,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { }); it("should delete all linked users if removeAllLinkedAccounts is true", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -478,7 +470,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { }); it("should not delete all linked users if removeAllLinkedAccounts is false when deleting the primary user", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -570,7 +562,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { }); it("should not delete all linked users if removeAllLinkedAccounts is false when deleting the recipe user", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -651,7 +643,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { describe("deleteUser", () => { it("should respond with error if userId is missing", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -711,7 +703,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { }); it("should respond with error if userId is empty", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, @@ -773,7 +765,7 @@ describe(`dashboard: ${printPath("[test/dashboard.test.js]")}`, function () { describe("userPut", () => { it("should respond with error if another user exists with the same email", async function () { - const connectionURI = await startSTWithMultitenancyAndAccountLinking(); + const connectionURI = await createCoreApplicationWithMultitenancyAndAccountLinking(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/dashboard/dashboardGet.test.js b/test/dashboard/dashboardGet.test.js index f3dd5301f0..7ab4fa83ba 100644 --- a/test/dashboard/dashboardGet.test.js +++ b/test/dashboard/dashboardGet.test.js @@ -1,5 +1,5 @@ const { ProcessState } = require("../../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let Dashboard = require("../../recipe/dashboard"); let EmailPassword = require("../../recipe/emailpassword"); @@ -10,21 +10,14 @@ let assert = require("assert"); describe(`User Dashboard get: ${printPath("[test/dashboard/dashboardGet.test.js]")}`, () => { beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - const dashboardURL = "/auth/dashboard/"; describe("Test connectionURI", function () { it("Test connectionURI contains http protocol", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); // removing protocol from the original connectionURI. const connectionURIWithoutProtocol = connectionURI.replace("http://", ""); @@ -69,7 +62,7 @@ describe(`User Dashboard get: ${printPath("[test/dashboard/dashboardGet.test.js] }); it("Test connectionURI contains https protocol", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); // removing protocol from the original connectionURI. const connectionURIWithoutProtocol = connectionURI.replace("https://", "").replace("http://", ""); @@ -113,7 +106,7 @@ describe(`User Dashboard get: ${printPath("[test/dashboard/dashboardGet.test.js] }); it("Test multiple connection URIs", async () => { - const firstConnectionURI = await startST(); + const firstConnectionURI = await createCoreApplication(); const secondConnectionURI = "http://no-core-here.supertokens.com"; const multipleConnectionURIs = `${firstConnectionURI};${secondConnectionURI}`; diff --git a/test/dashboard/userEmailVerifyGet.test.js b/test/dashboard/userEmailVerifyGet.test.js index a1a43722c4..1058a093fc 100644 --- a/test/dashboard/userEmailVerifyGet.test.js +++ b/test/dashboard/userEmailVerifyGet.test.js @@ -1,5 +1,5 @@ const { ProcessState } = require("../../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let Dashboard = require("../../recipe/dashboard"); let EmailVerification = require("../../recipe/emailverification"); @@ -12,18 +12,11 @@ let Session = require("../../recipe/session"); describe(`User Dashboard userEmailVerifyGet: ${printPath("[test/dashboard/userEmailVerifyGet.test.js]")}`, () => { beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that api returns correct value for email verification", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/config.test.js b/test/emailpassword/config.test.js index 5ba442e446..f423b362ac 100644 --- a/test/emailpassword/config.test.js +++ b/test/emailpassword/config.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, stopST, killAllST, cleanST, resetAll } = require("../utils"); +const { printPath, createCoreApplication, resetAll } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); let SessionRecipe = require("../../lib/build/recipe/session/recipe").default; @@ -29,20 +29,13 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`configTest: ${printPath("[test/emailpassword/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // test config for emailpassword module // Failure condition: passing custom data or data of invalid type/ syntax to the module it("test default config for emailpassword module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -83,7 +76,7 @@ describe(`configTest: ${printPath("[test/emailpassword/config.test.js]")}`, func // Failure condition: passing data of invalid type/ syntax to the module it("test config for emailpassword module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -128,7 +121,7 @@ describe(`configTest: ${printPath("[test/emailpassword/config.test.js]")}`, func * - Check that the default password and email validators work fine */ it("test that no email/password validators given should add them", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -160,7 +153,7 @@ describe(`configTest: ${printPath("[test/emailpassword/config.test.js]")}`, func }); it("test that giving optional true in email / password field should be ignored", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -195,7 +188,7 @@ describe(`configTest: ${printPath("[test/emailpassword/config.test.js]")}`, func //Check that the default password and email validators work fine it("test that default password and email validators work fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/deleteUser.test.js b/test/emailpassword/deleteUser.test.js index 2aff22bb3b..d9bf9b978b 100644 --- a/test/emailpassword/deleteUser.test.js +++ b/test/emailpassword/deleteUser.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, signUPRequest, extractInfoFromResponse, @@ -43,18 +41,11 @@ let { maxVersion } = require("../../lib/build/utils"); describe(`deleteUser: ${printPath("[test/emailpassword/deleteUser.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test deleteUser", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/emailpassword/emailDelivery.test.js b/test/emailpassword/emailDelivery.test.js index 89301b5bbe..b4cda9c7ab 100644 --- a/test/emailpassword/emailDelivery.test.js +++ b/test/emailpassword/emailDelivery.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse, delay } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse, delay } = require("../utils"); let STExpress = require("../.."); let Session = require("../../recipe/session"); let assert = require("assert"); @@ -28,19 +28,15 @@ let url = require("url"); describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); after(async function () { process.env.TEST_MODE = "testing"; - await killAllST(); - await cleanST(); }); it("test default backward compatibility api being called: reset password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -96,7 +92,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test default backward compatibility api being called, error message not sent back to user: reset password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -153,7 +149,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test backward compatibility: reset password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let passwordResetURL = undefined; STExpress.init({ @@ -210,7 +206,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test backward compatibility: reset password (non existent user)", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let functionCalled = false; STExpress.init({ supertokens: { @@ -279,7 +275,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test custom override: reset password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let passwordResetURL = undefined; let type = undefined; @@ -351,7 +347,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test smtp service: reset password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let passwordResetURL = undefined; let outerOverrideCalled = false; @@ -445,7 +441,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test default backward compatibility api being called: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -504,7 +500,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test default backward compatibility api being called, error message not sent back to user: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -564,7 +560,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test backward compatibility: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let emailVerifyURL = undefined; let userIdInCb = undefined; @@ -622,7 +618,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test custom override: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let emailVerifyURL = undefined; let type = undefined; @@ -695,7 +691,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test smtp service: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let emailVerifyURL = undefined; let outerOverrideCalled = false; @@ -790,7 +786,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("Test the reset password link", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -824,7 +820,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("Test the reset password link for invalid input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -853,7 +849,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test sendResetPasswordEmail", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let emailPasswordLink = ""; STExpress.init({ supertokens: { @@ -901,7 +897,7 @@ describe(`emailDelivery: ${printPath("[test/emailpassword/emailDelivery.test.js] }); it("test sendResetPasswordEmail: invalid input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/emailExists.test.js b/test/emailpassword/emailExists.test.js index c8ed3b0669..5aaeea6271 100644 --- a/test/emailpassword/emailExists.test.js +++ b/test/emailpassword/emailExists.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, stopST, killAllST, cleanST, resetAll, signUPRequest } = require("../utils"); +const { printPath, createCoreApplication, resetAll, signUPRequest } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); let SessionRecipe = require("../../lib/build/recipe/session/recipe").default; @@ -45,18 +45,11 @@ TODO: describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test good input, email exists with new path", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -75,7 +68,8 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` app.use(errorHandler()); - let signUpResponse = await signUPRequest(app, "random@gmail.com", "validPass123"); + const email = Math.random() + "@gmail.com"; + let signUpResponse = await signUPRequest(app, email, "validPass123"); assert(signUpResponse.status === 200); assert(JSON.parse(signUpResponse.text).status === "OK"); @@ -83,7 +77,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` request(app) .get("/auth/emailpassword/email/exists") .query({ - email: "random@gmail.com", + email, }) .expect(200) .end((err, res) => { @@ -94,15 +88,14 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` } }) ); - + assert(response?.status === "OK"); + assert(response?.exists === true); assert(Object.keys(response).length === 2); - assert(response.status === "OK"); - assert(response.exists === true); }); // disable the email exists API, and check that calling it returns a 404. it("test that if disabling api, the default email exists API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -153,7 +146,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` // email exists it("test good input, email exists", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -199,7 +192,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` //email does not exist it("test good input, email does not exists", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -241,7 +234,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` //pass an invalid (syntactically) email and check that you get exists: false it("test email exists a syntactically invalid email", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -287,7 +280,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` //pass an unnormalised email, and check that you get exists true it("test sending an unnormalised email and you get exists is true", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -333,7 +326,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` //do not pass email it("test bad input, do not pass email", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -370,7 +363,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` // pass an array instead of string in the email it("test passing an array instead of a string in the email", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -413,7 +406,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` // email exists it("test good input, email exists, with bodyParser applied before", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -462,7 +455,7 @@ describe(`emailExists: ${printPath("[test/emailpassword/emailExists.test.js]")}` // email exists it("test good input, email exists, with bodyParser applied after", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/emailverify.test.js b/test/emailpassword/emailverify.test.js index 65446ede4c..055d66c5e8 100644 --- a/test/emailpassword/emailverify.test.js +++ b/test/emailpassword/emailverify.test.js @@ -15,15 +15,13 @@ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, signUPRequest, extractInfoFromResponse, - setKeyValueInConfig, + emailVerifyTokenRequest, } = require("../utils"); let STExpress = require("../.."); @@ -40,16 +38,9 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - /* generate token API: - Call the API with valid input, email not verified @@ -61,7 +52,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Call the API with valid input, email not verified it("test the generate token api with valid input, email not verified", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -99,7 +90,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` //Call the API with valid input, email verified and test error it("test the generate token api with valid input, email verified and test error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -146,7 +137,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Call the API with no session and see the output it("test the generate token api with valid input, no session and check output", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -188,7 +179,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Call the API with an expired access token and see that try refresh token is returned it("test the generate token api with an expired access token and see that try refresh token is returned", async function () { - const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } }); STExpress.init({ supertokens: { @@ -264,7 +255,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Provide your own email callback and make sure that is called it("test that providing your own email callback and make sure it is called", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let userInfo = null; let emailToken = null; @@ -338,7 +329,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` - Call the API with an expired access token and see that try refresh token is returned */ it("test the email verify API with valid input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let token = null; STExpress.init({ @@ -407,7 +398,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Call the API with an invalid token and see the error it("test the email verify API with invalid token and check error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -455,7 +446,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // token is not of type string from input it("test the email verify API with token of not type string", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -503,7 +494,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // provide a handlePostEmailVerification callback and make sure it's called on success verification it("test that the handlePostEmailVerification callback is called on successfull verification, if given", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let userInfoFromCallback = null; let token = null; @@ -593,7 +584,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Call the API with valid input it("test the email verify with valid input, using the get method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let token = null; let rid = undefined; @@ -682,7 +673,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Call the API with no session and see the error it("test the email verify with no session, using the get method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -727,7 +718,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` // Call the API with an expired access token and see that try refresh token is returned it("test the email verify with an expired access token, using the get method", async function () { - const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } }); let token = null; @@ -849,7 +840,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test the email verify API with valid input, overriding apis", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let token = null; @@ -932,7 +923,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test the email verify API with valid input, overriding functions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let token = null; @@ -1015,7 +1006,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test the email verify API with valid input, overriding apis throws error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let token = null; @@ -1106,7 +1097,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test the email verify API with valid input, overriding functions throws error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let token = null; @@ -1197,7 +1188,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test the generate token api with valid input, and then remove token", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1243,7 +1234,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test the generate token api with valid input, verify and then unverify email", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1291,7 +1282,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test the email verify API with deleted user", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let token = null; STExpress.init({ @@ -1347,7 +1338,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test that generate email verification token API updates session claims", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1431,7 +1422,7 @@ describe(`emailverify: ${printPath("[test/emailpassword/emailverify.test.js]")}` }); it("test that generate email verification token API updates session claims", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let emailVerifyLink = ""; STExpress.init({ diff --git a/test/emailpassword/multitenancy.test.js b/test/emailpassword/multitenancy.test.js index ececea1c92..c39a885b50 100644 --- a/test/emailpassword/multitenancy.test.js +++ b/test/emailpassword/multitenancy.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, stopST, killAllST, cleanST, resetAll } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy, resetAll } = require("../utils"); let SuperTokens = require("../../"); let Session = require("../../recipe/session"); let SessionRecipe = require("../../lib/build/recipe/session/recipe").default; @@ -29,20 +29,13 @@ let Multitenancy = require("../../recipe/multitenancy"); describe(`multitenancy: ${printPath("[test/emailpassword/multitenancy.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // test config for emailpassword module // Failure condition: passing custom data or data of invalid type/ syntax to the module it("test recipe functions", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/override.test.js b/test/emailpassword/override.test.js index 44823dd604..2305584140 100644 --- a/test/emailpassword/override.test.js +++ b/test/emailpassword/override.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, signUPRequest, assertJSONEquals, @@ -42,18 +40,11 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`overrideTest: ${printPath("[test/emailpassword/override.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("overriding functions tests", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; STExpress.init({ supertokens: { @@ -217,7 +208,7 @@ describe(`overrideTest: ${printPath("[test/emailpassword/override.test.js]")}`, }); it("overriding api tests", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let emailExists = undefined; STExpress.init({ @@ -365,7 +356,7 @@ describe(`overrideTest: ${printPath("[test/emailpassword/override.test.js]")}`, }); it("overriding functions tests, throws error", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; STExpress.init({ supertokens: { @@ -495,7 +486,7 @@ describe(`overrideTest: ${printPath("[test/emailpassword/override.test.js]")}`, }); it("overriding api tests, throws error", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let emailExists = undefined; STExpress.init({ diff --git a/test/emailpassword/passwordreset.test.js b/test/emailpassword/passwordreset.test.js index e8a579f6f1..d1e484ae6d 100644 --- a/test/emailpassword/passwordreset.test.js +++ b/test/emailpassword/passwordreset.test.js @@ -13,7 +13,7 @@ * under the License. */ -const { printPath, setupST, startST, stopST, killAllST, cleanST, resetAll, signUPRequest } = require("../utils"); +const { printPath, createCoreApplication, resetAll, signUPRequest } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); let SessionRecipe = require("../../lib/build/recipe/session/recipe").default; @@ -50,16 +50,9 @@ let { maxVersion } = require("../../lib/build/utils"); describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - /* * generate token API: * - email validation checks @@ -67,7 +60,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] * - check that the generated password reset link is correct */ it("test email validation checks in generate token API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -112,7 +105,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test invalid email type in generate token API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -154,7 +147,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test that generated password link is correct", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let resetURL = ""; let tokenInfo = ""; @@ -230,7 +223,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] * - input is valid, check that password has changed (call sign in) */ it("test password validation", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -298,7 +291,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test invalid type of password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -341,7 +334,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test token missing from input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -383,7 +376,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test invalid token input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -426,7 +419,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test valid token input and passoword has changed with email verification", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let passwordResetUserId = undefined; let token = ""; @@ -591,7 +584,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test valid token input and passoword has changed without email verification", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let passwordResetUserId = undefined; let token = ""; @@ -756,7 +749,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] describe("createPasswordResetToken tests", function () { it("createPasswordResetToken with random user ID fails", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -775,7 +768,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("createPasswordResetToken with primary user, non email password succeeds", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -823,7 +816,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] describe("consumePasswordResetToken tests", function () { it("consumePasswordResetToken works when token is valid", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -852,7 +845,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("consumePasswordResetToken returns RESET_PASSWORD_INVALID_TOKEN_ERROR error if the token does not exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -871,7 +864,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("consumePasswordResetToken with primary user, non email password succeeds", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -928,7 +921,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("Test that reset password link uses the correct origin", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let emailPasswordLink = ""; STExpress.init({ supertokens: { @@ -1021,7 +1014,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test the reset password link", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1055,7 +1048,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test the reset password link for invalid input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1084,7 +1077,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test sendResetPasswordEmail", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let emailPasswordLink = ""; STExpress.init({ supertokens: { @@ -1132,7 +1125,7 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js] }); it("test sendResetPasswordEmail: invalid input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/signinFeature.test.js b/test/emailpassword/signinFeature.test.js index d617c5bb49..66c9b42e72 100644 --- a/test/emailpassword/signinFeature.test.js +++ b/test/emailpassword/signinFeature.test.js @@ -15,11 +15,9 @@ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, signUPRequest, extractInfoFromResponse, @@ -72,18 +70,11 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }; }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test singinAPI works when rid is thirdpartyemailpassword", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -180,7 +171,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] /* */ it("test that disabling api, the default signin API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -248,7 +239,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] Setting invalid email or password values in the request body when sending a request to /signin */ it("test singinAPI works when input is fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -302,7 +293,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test password must be of type string in input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -355,7 +346,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test email must be of type string in input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -411,7 +402,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] Setting the email value in form field as random@gmail.com causes the test to fail */ it("test singinAPI throws an error when email does not match", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -466,7 +457,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] passing the correct password "validpass123" causes the test to fail */ it("test singinAPI throws an error if password is incorrect", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -527,7 +518,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] setting valid JSON body to /singin API */ it("test bad input, not a JSON to /signin API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -574,7 +565,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] setting valid formFields JSON body to /singin API */ it("test bad input, no POST body to /signin API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -617,7 +608,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] setting valid JSON body to /singin API */ it("test bad input, input is Json but incorrect structure to /signin API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -662,7 +653,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] Passing invalid credentials to the /signin API fails the test */ it("test that a successfull signin yields a session", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -738,7 +729,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] having the email start with "test" (requierment of the custom validator) will cause the test to fail */ it("test custom email validators to sign up and make sure they are applied to sign in", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -813,7 +804,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] sending the correct password "valid" will cause the test to fail */ it("test custom password validators to sign up and make sure they are applied to sign in", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let failsValidatorCtr = 0; let passesValidatorCtr = 0; @@ -895,7 +886,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] sending the correct password to the /signin API will cause the test to fail */ it("test password field validation error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -949,7 +940,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] //sending the correct email to the /signin API will cause the test to fail it("test email field validation error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1004,7 +995,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] // Input formFields has no email field //passing the email field in formFields will cause the test to fail it("test formFields has no email field", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1055,7 +1046,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] // Input formFields has no password field //passing the password field in formFields will cause the test to fail it("test formFields has no password field", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1108,7 +1099,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] passing email with valid syntax and correct password will cause the test to fail */ it("test invalid email and wrong password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1167,7 +1158,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] * - User exists */ it("test getUserByEmail when user does not exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1213,7 +1204,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test the handlePostSignIn function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let customUser = undefined; STExpress.init({ @@ -1318,7 +1309,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI works when input is fine and user has added JSON middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1373,7 +1364,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI works when input is fine and user has added urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1428,7 +1419,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI works when input is fine and user has added both JSON and urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1479,12 +1470,13 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] } }) ); + assert(userInfo.id === signUpUserInfo.id); assert(userInfo.email === signUpUserInfo.email); }); it("test singinAPI works when input is fine and user has added bodyParser JSON middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1539,7 +1531,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI works when input is fine and user has added bodyParser urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1594,7 +1586,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI works when input is fine and user has added both bodyParser JSON and bodyParser urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1650,7 +1642,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI with empty JSON and user has added JSON middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1676,7 +1668,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI with empty JSON and user has added urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1702,7 +1694,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI with empty JSON and user has added both JSON and urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1729,7 +1721,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI with empty JSON and user has added both bodyParser JSON and bodyParser urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1756,7 +1748,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI with empty request body and user has added JSON middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1782,7 +1774,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI with empty request body and user has added urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1808,7 +1800,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] }); it("test singinAPI with empty request body and user has added both JSON and urlencoded middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1839,7 +1831,7 @@ describe(`signinFeature: ${printPath("[test/emailpassword/signinFeature.test.js] */ // testing error gets corectly routed to sub-recipe it("test singinAPI throws an error when email does not match", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/signoutFeature.test.js b/test/emailpassword/signoutFeature.test.js index a248d397a2..96e14bfda2 100644 --- a/test/emailpassword/signoutFeature.test.js +++ b/test/emailpassword/signoutFeature.test.js @@ -15,15 +15,12 @@ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, signUPRequest, extractInfoFromResponse, - setKeyValueInConfig, } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); @@ -44,19 +41,12 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`signoutFeature: ${printPath("[test/emailpassword/signoutFeature.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // Test the default route and it should revoke the session (with clearing the cookies) it("test the default route and it should revoke the session", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -113,7 +103,7 @@ describe(`signoutFeature: ${printPath("[test/emailpassword/signoutFeature.test.j // Disable default route and test that that API returns 404 it("test that disabling default route and calling the API returns 404", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -163,7 +153,7 @@ describe(`signoutFeature: ${printPath("[test/emailpassword/signoutFeature.test.j // Call the API without a session and it should return "401" it("test that calling the API without a session should return 401", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -201,7 +191,7 @@ describe(`signoutFeature: ${printPath("[test/emailpassword/signoutFeature.test.j //Call the API with an expired access token, refresh, and call the API again to get OK and clear cookies it("test that signout API reutrns try refresh token, refresh session and signout should return OK", async function () { - const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } }); STExpress.init({ supertokens: { diff --git a/test/emailpassword/signupFeature.test.js b/test/emailpassword/signupFeature.test.js index c9a5299abd..d5ae35b968 100644 --- a/test/emailpassword/signupFeature.test.js +++ b/test/emailpassword/signupFeature.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, signUPRequest, extractInfoFromResponse, @@ -77,19 +75,12 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }; }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // * check if disable api, the default signup API does not work - you get a 404 it("test that if disable api, the default signup API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -132,7 +123,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] */ it("test signUpAPI works when input is fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -162,7 +153,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test signUpAPI throws an error in case of a duplicate email", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -201,7 +192,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test signUpAPI throws an error for email and password with invalid syntax", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -243,7 +234,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] * - formField elements have no id or no value field * */ it("test bad input, not a JSON to /signup API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -283,7 +274,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test bad input, no POST body to /signup API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -319,7 +310,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test bad input, Input is JSON, but wrong structure to /signup API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -358,7 +349,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test bad input, invalid password type in /signup API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -406,7 +397,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test bad input, invalid email type in /signup API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -454,7 +445,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test bad input, formFields is not an array in /signup API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -495,7 +486,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test bad input, formField elements have no id or no value field in /signup API", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -542,7 +533,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //* Make sure that a successful sign up yields a session it("test that a successful signup yields a session", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -589,7 +580,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //If not provided by the user, it should not result in an error it("test that if not provided by the user, it should not result in an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -655,7 +646,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //- If provided by the user, and custom fields are there, only those should be sent it("test that if provided by the user, and custom fields are there, only those are sent, using handlePostSignUp", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let customFormFields = ""; STExpress.init({ @@ -741,7 +732,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //If provided by the user, and no custom fields are there, then the formFields param must sbe empty it("test that if provided by the user, and no custom fields are there, then formFields must be empty, using handlePostSignUp", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let customFormFields = ""; STExpress.init({ @@ -824,7 +815,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] * - Pass a non string value in the formFields array and make sure it passes through the signUp API and is sent in the handlePostSignup as that type */ it("test formFields added in config but not in input to signup, check error about it being missing", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -863,7 +854,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //- Good test case without optional it("test valid formFields without optional", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -927,7 +918,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test valid boolean formFields with optional", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -992,7 +983,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test valid int formFields with optional", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1058,7 +1049,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //- Bad test case without optional (something is missing, and it's not optional) it("test bad case input to signup without optional", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1123,7 +1114,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //- Good test case with optionals it("test good case input to signup with optional", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1189,7 +1180,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //- Input formFields has no email field (and not in config) it("test input formFields has no email field", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1234,7 +1225,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] // Input formFields has no password field (and not in config it("test inut formFields has no password field", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1279,7 +1270,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] // Input form field has different number of custom fields than in config form fields) it("test input form field has a different number of custom fields than in config form fields", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1347,7 +1338,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] // Input form field has same number of custom fields as in config form field, but some ids mismatch it("test input form field has the same number of custom fields than in config form fields, but ids mismatch", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1421,7 +1412,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] // Custom optional field missing in the payload should not throw an error it("Custom optional field missing in the payload should not throw an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1487,7 +1478,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] // Test custom field validation error (one and two custom fields) it("test custom field validation error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1569,7 +1560,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //Test password field validation error it("test signup password field validation error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1619,7 +1610,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //Test email field validation error it("test signup email field validation error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1669,7 +1660,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] //Make sure that the input email is trimmed it("test that input email is trimmed", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1718,7 +1709,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] // Pass a non string value in the formFields array and make sure it passes through the signUp API and is sent in the handlePostSignUp as that type it("test that non string value in formFields array and it passes through the signup API and it is sent to the handlePostSignUp", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let customFormFields = ""; STExpress.init({ @@ -1798,7 +1789,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test signUpAPI validate function using userContext", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1874,7 +1865,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("test handlePostSignUp gets set correctly", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); process.env.userId = ""; process.env.loginType = ""; @@ -1930,7 +1921,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] }); it("updateEmailOrPassword function test for third party login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -2069,7 +2060,7 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] // test case where more than the configured form fields are passed. it("test bad case when too many formFields are passed", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/updateEmailPass.test.js b/test/emailpassword/updateEmailPass.test.js index 11b3501873..96274f1790 100644 --- a/test/emailpassword/updateEmailPass.test.js +++ b/test/emailpassword/updateEmailPass.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, stopST, killAllST, cleanST, signUPRequest } = require("../utils"); +const { printPath, createCoreApplication, signUPRequest } = require("../utils"); const { updateEmailOrPassword, signIn } = require("../../lib/build/recipe/emailpassword"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -26,18 +26,11 @@ const express = require("express"); describe(`updateEmailPassTest: ${printPath("[test/emailpassword/updateEmailPass.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test updateEmailPass", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -79,7 +72,7 @@ describe(`updateEmailPassTest: ${printPath("[test/emailpassword/updateEmailPass. }); it("test updateEmailPass with failing password validation", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -137,7 +130,7 @@ describe(`updateEmailPassTest: ${printPath("[test/emailpassword/updateEmailPass. }); it("test updateEmailPass with passing password validation", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -194,7 +187,7 @@ describe(`updateEmailPassTest: ${printPath("[test/emailpassword/updateEmailPass. }); it("test updateEmailPass with failing default password validation", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/emailpassword/users.test.js b/test/emailpassword/users.test.js index af53534c23..15d8e340c7 100644 --- a/test/emailpassword/users.test.js +++ b/test/emailpassword/users.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, stopST, killAllST, cleanST, signUPRequest } = require("../utils"); +const { printPath, createCoreApplication, signUPRequest, resetAll } = require("../utils"); const { getUserCount, getUsersNewestFirst, getUsersOldestFirst } = require("../../lib/build"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -26,18 +26,11 @@ const express = require("express"); describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); - ProcessState.getInstance().reset(); - }); - - after(async function () { - await killAllST(); - await cleanST(); + resetAll(); }); it("test getUsersOldestFirst", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -57,11 +50,18 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi app.use(errorHandler()); - await signUPRequest(app, "test@gmail.com", "testPass123"); - await signUPRequest(app, "test1@gmail.com", "testPass123"); - await signUPRequest(app, "test2@gmail.com", "testPass123"); - await signUPRequest(app, "test3@gmail.com", "testPass123"); - await signUPRequest(app, "test4@gmail.com", "testPass123"); + const randomValue = Math.random(); + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signUPRequest(app, email, `testPass-${randomValue}-${i}` + randomValue + i); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } let users = await getUsersOldestFirst({ tenantId: "public" }); assert.strictEqual(users.users.length, 5); @@ -69,12 +69,12 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi users = await getUsersOldestFirst({ tenantId: "public", limit: 1 }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[0]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersOldestFirst({ tenantId: "public", limit: 1, paginationToken: users.nextPaginationToken }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test1@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[1]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersOldestFirst({ tenantId: "public", limit: 5, paginationToken: users.nextPaginationToken }); @@ -101,7 +101,7 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi }); it("test getUsersOldestFirst with search queries", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -126,11 +126,17 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi return; } - await signUPRequest(app, "test@gmail.com", "testPass123"); - await signUPRequest(app, "test1@gmail.com", "testPass123"); - await signUPRequest(app, "test2@gmail.com", "testPass123"); - await signUPRequest(app, "test3@gmail.com", "testPass123"); - await signUPRequest(app, "john@gmail.com", "testPass123"); + const randomValue = Math.random(); + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signUPRequest(app, email, `testPass-${randomValue}-${i}`); + } + await signUPRequest(app, "john@gmail.com", `testPass-${randomValue}-4`); let users = await getUsersOldestFirst({ tenantId: "public", query: { email: "doe" } }); assert.strictEqual(users.users.length, 0); @@ -146,7 +152,7 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi }); it("test getUsersNewestFirst", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -166,11 +172,18 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi app.use(errorHandler()); - await signUPRequest(app, "test@gmail.com", "testPass123"); - await signUPRequest(app, "test1@gmail.com", "testPass123"); - await signUPRequest(app, "test2@gmail.com", "testPass123"); - await signUPRequest(app, "test3@gmail.com", "testPass123"); - await signUPRequest(app, "test4@gmail.com", "testPass123"); + const randomValue = Math.random(); + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signUPRequest(app, email, `testPass-${randomValue}-${i}`); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } let users = await getUsersNewestFirst({ tenantId: "public" }); assert.strictEqual(users.users.length, 5); @@ -178,12 +191,12 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi users = await getUsersNewestFirst({ tenantId: "public", limit: 1 }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test4@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[emails.length - 1]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersNewestFirst({ tenantId: "public", limit: 1, paginationToken: users.nextPaginationToken }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test3@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[emails.length - 2]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersNewestFirst({ tenantId: "public", limit: 5, paginationToken: users.nextPaginationToken }); @@ -210,7 +223,7 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi }); it("test getUsersNewestFirst with search queries", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -235,11 +248,18 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi return; } - await signUPRequest(app, "test@gmail.com", "testPass123"); - await signUPRequest(app, "test1@gmail.com", "testPass123"); - await signUPRequest(app, "test2@gmail.com", "testPass123"); - await signUPRequest(app, "test3@gmail.com", "testPass123"); - await signUPRequest(app, "john@gmail.com", "testPass123"); + const randomValue = Math.random(); + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signUPRequest(app, email, `testPass-${randomValue}-${i}`); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } + await signUPRequest(app, "john3@gmail.com", `testPass-${randomValue}-4`); let users = await getUsersNewestFirst({ tenantId: "public", query: { email: "doe" } }); assert.strictEqual(users.users.length, 0); @@ -249,7 +269,7 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi }); it("test getUserCount", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -272,14 +292,21 @@ describe(`usersTest: ${printPath("[test/emailpassword/users.test.js]")}`, functi app.use(errorHandler()); - await signUPRequest(app, "test@gmail.com", "testPass123"); + await signUPRequest(app, "test@gmail.com", "testPass-${randomValue}-4"); userCount = await getUserCount(); assert.strictEqual(userCount, 1); - await signUPRequest(app, "test1@gmail.com", "testPass123"); - await signUPRequest(app, "test2@gmail.com", "testPass123"); - await signUPRequest(app, "test3@gmail.com", "testPass123"); - await signUPRequest(app, "test4@gmail.com", "testPass123"); + const randomValue = Math.random(); + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signUPRequest(app, email, `testPass-${randomValue}-${i}`); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } userCount = await getUserCount(); assert.strictEqual(userCount, 5); diff --git a/test/framework/awsLambda.test.js b/test/framework/awsLambda.test.js index c5cd986851..4fceaa15ff 100644 --- a/test/framework/awsLambda.test.js +++ b/test/framework/awsLambda.test.js @@ -14,10 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, mockLambdaProxyEvent, mockLambdaProxyEventV2, @@ -40,19 +39,12 @@ const sinon = require("sinon"); describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - //check basic usage of session it("test basic usage of sessions for lambda proxy event v1", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -227,7 +219,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct //check basic usage of session it("test basic usage of sessions for lambda proxy event v2", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -389,7 +381,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("sending custom response awslambda", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -434,7 +426,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct for (const tokenTransferMethod of ["header", "cookie"]) { describe(`Throwing UNATHORISED w/ auth-mode=${tokenTransferMethod}`, () => { it("should clear all response cookies during refresh", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -546,7 +538,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test revoking a session after createNewSession with throwing unauthorised error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -616,7 +608,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct } it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -669,7 +661,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -727,7 +719,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that search results correct output for 'email: t", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -790,7 +782,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -853,7 +845,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that search results correct output for 'email: iresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -915,7 +907,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that search results correct output for 'phone: +1", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -980,7 +972,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that search results correct output for 'phone: 1(", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -1045,7 +1037,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -1151,7 +1143,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.test.js]")}`, funct }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { diff --git a/test/framework/awsLambda.withTenantId.test.js b/test/framework/awsLambda.withTenantId.test.js index c38d174ff1..a5aa2aab8d 100644 --- a/test/framework/awsLambda.withTenantId.test.js +++ b/test/framework/awsLambda.withTenantId.test.js @@ -14,10 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, mockLambdaProxyEvent, mockLambdaProxyEventV2, @@ -38,19 +37,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - //check basic usage of session it("test basic usage of sessions for lambda proxy event v1", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -225,7 +217,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j //check basic usage of session it("test basic usage of sessions for lambda proxy event v2", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -394,7 +386,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("sending custom response awslambda", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -439,7 +431,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j for (const tokenTransferMethod of ["header", "cookie"]) { describe(`Throwing UNATHORISED w/ auth-mode=${tokenTransferMethod}`, () => { it("should clear all response cookies during refresh", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -551,7 +543,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test revoking a session after createNewSession with throwing unauthorised error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -621,7 +613,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j } it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -674,7 +666,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -732,7 +724,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that search results correct output for 'email: t", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -795,7 +787,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -858,7 +850,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that search results correct output for 'email: iresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -920,7 +912,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that search results correct output for 'phone: +1", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -985,7 +977,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that search results correct output for 'phone: 1(", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -1050,7 +1042,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { @@ -1156,7 +1148,7 @@ describe(`AWS Lambda: ${printPath("[test/framework/awsLambda.withTenantId.test.j }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "awsLambda", supertokens: { diff --git a/test/framework/crossFramework.testgen.js b/test/framework/crossFramework.testgen.js index 9bd3c2e0e7..181cca1136 100644 --- a/test/framework/crossFramework.testgen.js +++ b/test/framework/crossFramework.testgen.js @@ -1,6 +1,6 @@ const SuperTokens = require("../../"); const { ProcessState } = require("../../lib/build/processState"); -const { setupST, startST, killAllST, cleanST } = require("../utils"); +const { createCoreApplication } = require("../utils"); const express = require("express"); const request = require("supertest"); @@ -66,20 +66,13 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods describe(`express w/ auth-mode=${tokenTransferMethod}`, () => { let app; beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); app = undefined; }); - after(async function () { - await killAllST(); - await cleanST(); - }); - getTestCases( async ({ stConfig, routes }) => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -145,8 +138,6 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods describe(`fastify w/ auth-mode=${tokenTransferMethod}`, () => { let server; beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); server = undefined; }); @@ -157,14 +148,9 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); - getTestCases( async ({ stConfig, routes }) => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", @@ -225,8 +211,6 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods describe(`hapi w/ auth-mode=${tokenTransferMethod}`, () => { let server; beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); server = undefined; }); @@ -237,14 +221,9 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); - getTestCases( async ({ stConfig, routes }) => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", @@ -302,8 +281,6 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods describe(`koa w/ auth-mode=${tokenTransferMethod}`, () => { let app, server; beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); app = undefined; server = undefined; @@ -315,14 +292,9 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); - getTestCases( async ({ stConfig, routes }) => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", @@ -391,8 +363,6 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods describe(`loopback w/ auth-mode=${tokenTransferMethod}`, () => { let app; beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); @@ -402,11 +372,6 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); - getTestCases( async ({ stConfig, routes }) => { if (withoutMiddleware === true) { @@ -414,7 +379,7 @@ module.exports.addCrossFrameworkTests = (getTestCases, { allTokenTransferMethods } app = require("./loopback-server/index.js"); - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", diff --git a/test/framework/custom.test.js b/test/framework/custom.test.js index 8733fe309b..838daa5695 100644 --- a/test/framework/custom.test.js +++ b/test/framework/custom.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); let assert = require("assert"); let { ProcessState, PROCESS_STATE } = require("../../lib/build/processState"); let SuperTokens = require("../.."); @@ -24,8 +24,6 @@ const sinon = require("sinon"); describe(`Custom framework: ${printPath("[test/framework/custom.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); @@ -34,14 +32,10 @@ describe(`Custom framework: ${printPath("[test/framework/custom.test.js]")}`, fu await this.server.close(); } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); // - check if session verify middleware responds with a nice error even without the global error handler it("test session verify middleware without error handler added", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "custom", supertokens: { @@ -75,7 +69,7 @@ describe(`Custom framework: ${printPath("[test/framework/custom.test.js]")}`, fu // check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "custom", supertokens: { diff --git a/test/framework/fastify.test.js b/test/framework/fastify.test.js index 275ed26237..df062e783e 100644 --- a/test/framework/fastify.test.js +++ b/test/framework/fastify.test.js @@ -14,10 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, extractCookieCountInfo, } = require("../utils"); @@ -41,8 +40,6 @@ const sinon = require("sinon"); describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.server = Fastify(); }); @@ -52,14 +49,10 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( await this.server.close(); } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); // check if disabling api, the default refresh API does not work - you get a 404 it("test that if disabling api, the default refresh API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -113,7 +106,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that if disabling api, the default sign out API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -162,7 +155,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( //- check for token theft detection it("token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -264,7 +257,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( // - check for token theft detection it("token theft detection with auto refresh middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -340,7 +333,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( // - check for token theft detection without error handler it("token theft detection with auto refresh middleware without error handler", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -414,7 +407,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( // - check if session verify middleware responds with a nice error even without the global error handler it("test session verify middleware without error handler added", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -451,7 +444,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( // check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -564,7 +557,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test signout API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -610,7 +603,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( // check basic usage of session it("test basic usage of sessions with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -725,7 +718,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( // check session verify for with / without anti-csrf present it("test session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -786,7 +779,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( // check session verify for with / without anti-csrf present it("test session verify without anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -852,7 +845,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( //check revoking session(s)** it("test revoking sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -948,7 +941,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( //check manipulating session data it("test manipulating session data", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1075,7 +1068,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( //check manipulating jwt payload it("test manipulating jwt payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1260,7 +1253,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("sending custom response fastify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1306,7 +1299,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("generating email verification token without payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1361,7 +1354,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test same cookie is not getting set multiple times", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1393,7 +1386,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1440,7 +1433,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1491,7 +1484,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1544,7 +1537,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that search results correct output for multiple search terms", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1597,7 +1590,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1650,7 +1643,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1706,7 +1699,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1762,7 +1755,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1859,7 +1852,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.test.js]")}`, function ( }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { diff --git a/test/framework/fastify.withTenantId.test.js b/test/framework/fastify.withTenantId.test.js index 0c1792dcaa..83f1a4a676 100644 --- a/test/framework/fastify.withTenantId.test.js +++ b/test/framework/fastify.withTenantId.test.js @@ -14,10 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, extractCookieCountInfo, } = require("../utils"); @@ -39,8 +38,6 @@ const ThirdParty = require("../../recipe/thirdparty"); describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.server = Fastify(); }); @@ -50,14 +47,10 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} await this.server.close(); } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); // check if disabling api, the default refresh API does not work - you get a 404 it("test that if disabling api, the default refresh API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -111,7 +104,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that if disabling api, the default sign out API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -160,7 +153,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} //- check for token theft detection it("token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -262,7 +255,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} // - check for token theft detection it("token theft detection with auto refresh middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -338,7 +331,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} // - check for token theft detection without error handler it("token theft detection with auto refresh middleware without error handler", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -412,7 +405,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} // - check if session verify middleware responds with a nice error even without the global error handler it("test session verify middleware without error handler added", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -449,7 +442,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} // check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -562,7 +555,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test signout API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -608,7 +601,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} // check basic usage of session it("test basic usage of sessions with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -723,7 +716,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} // check session verify for with / without anti-csrf present it("test session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -784,7 +777,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} // check session verify for with / without anti-csrf present it("test session verify without anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -850,7 +843,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} //check revoking session(s)** it("test revoking sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -946,7 +939,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} //check manipulating session data it("test manipulating session data", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1073,7 +1066,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} //check manipulating jwt payload it("test manipulating jwt payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1258,7 +1251,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("sending custom response fastify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1304,7 +1297,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("generating email verification token without payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1359,7 +1352,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test same cookie is not getting set multiple times", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1391,7 +1384,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1438,7 +1431,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1489,7 +1482,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1542,7 +1535,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that search results correct output for multiple search terms", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1595,7 +1588,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1648,7 +1641,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1704,7 +1697,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1760,7 +1753,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { @@ -1857,7 +1850,7 @@ describe(`Fastify: ${printPath("[test/framework/fastify.withTenantId.test.js]")} }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "fastify", supertokens: { diff --git a/test/framework/hapi.test.js b/test/framework/hapi.test.js index 42522eaee6..0532df656a 100644 --- a/test/framework/hapi.test.js +++ b/test/framework/hapi.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); let assert = require("assert"); let { ProcessState, PROCESS_STATE } = require("../../lib/build/processState"); let SuperTokens = require("../../"); @@ -32,8 +32,6 @@ const sinon = require("sinon"); describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.server = Hapi.server({ port: 3000, @@ -46,14 +44,10 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { await this.sever.stop(); } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); // check if disabling api, the default refresh API does not work - you get a 404 it("test that if disabling api, the default refresh API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -113,7 +107,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that if disabling api, the default sign out API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -168,7 +162,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { //- check for token theft detection it("token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -282,7 +276,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { //- check for token theft detection it("token theft detection with auto refresh middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -367,7 +361,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { //check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -494,7 +488,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test signout API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -545,7 +539,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { //check basic usage of session it("test basic usage of sessions with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -673,7 +667,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { // check session verify for with / without anti-csrf present it("test session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -748,7 +742,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { // check session verify for with / without anti-csrf present it("test session verify without anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -829,7 +823,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { //check revoking session(s)** it("test revoking sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -946,7 +940,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { //check manipulating session data it("test manipulating session data", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1088,7 +1082,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { //check manipulating jwt payload it("test manipulating jwt payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1295,7 +1289,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("sending custom response hapi", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1341,7 +1335,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1387,7 +1381,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test verifySession/getSession without accessToken", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1441,7 +1435,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1496,7 +1490,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1551,7 +1545,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1605,7 +1599,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { assert(resp.result.users.length === 0); }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1660,7 +1654,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1718,7 +1712,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1776,7 +1770,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1879,7 +1873,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.test.js]")}`, function () { }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { diff --git a/test/framework/hapi.withTenantId.test.js b/test/framework/hapi.withTenantId.test.js index 7bf96427c1..68fb618ee7 100644 --- a/test/framework/hapi.withTenantId.test.js +++ b/test/framework/hapi.withTenantId.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); let assert = require("assert"); let { ProcessState, PROCESS_STATE } = require("../../lib/build/processState"); let SuperTokens = require("../../"); @@ -30,8 +30,6 @@ const ThirdParty = require("../../recipe/thirdparty"); describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.server = Hapi.server({ port: 3000, @@ -44,14 +42,10 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun await this.sever.stop(); } catch (err) {} }); - after(async function () { - await killAllST(); - await cleanST(); - }); // check if disabling api, the default refresh API does not work - you get a 404 it("test that if disabling api, the default refresh API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -111,7 +105,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that if disabling api, the default sign out API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -166,7 +160,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun //- check for token theft detection it("token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -280,7 +274,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun //- check for token theft detection it("token theft detection with auto refresh middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -365,7 +359,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun //check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -492,7 +486,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test signout API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -543,7 +537,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun //check basic usage of session it("test basic usage of sessions with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -671,7 +665,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun // check session verify for with / without anti-csrf present it("test session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -746,7 +740,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun // check session verify for with / without anti-csrf present it("test session verify without anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -827,7 +821,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun //check revoking session(s)** it("test revoking sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -944,7 +938,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun //check manipulating session data it("test manipulating session data", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1086,7 +1080,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun //check manipulating jwt payload it("test manipulating jwt payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1293,7 +1287,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("sending custom response hapi", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1339,7 +1333,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1385,7 +1379,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test verifySession/getSession without accessToken", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1439,7 +1433,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1494,7 +1488,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1549,7 +1543,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1603,7 +1597,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun assert(resp.result.users.length === 0); }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1658,7 +1652,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1716,7 +1710,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1774,7 +1768,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { @@ -1877,7 +1871,7 @@ describe(`Hapi: ${printPath("[test/framework/hapi.withTenantId.test.js]")}`, fun }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "hapi", supertokens: { diff --git a/test/framework/koa.test.js b/test/framework/koa.test.js index 13c3944f62..5eb6595ec1 100644 --- a/test/framework/koa.test.js +++ b/test/framework/koa.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); let assert = require("assert"); let { ProcessState, PROCESS_STATE } = require("../../lib/build/processState"); let SuperTokens = require("../../"); @@ -34,8 +34,6 @@ const sinon = require("sinon"); describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.server = undefined; }); @@ -46,14 +44,9 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { } }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // check if disabling api, the default refresh API does not work - you get a 404 it("test that if disabling api, the default refresh API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -125,7 +118,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that if disabling api, the default sign out API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", framework: "koa", @@ -195,7 +188,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //- check for token theft detection it("koa token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -318,7 +311,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //- check for token theft detection it("koa token theft detection with auto refresh middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -415,7 +408,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //check basic usage of session it("test basic usage of express sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -570,7 +563,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test signout API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -633,7 +626,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //check basic usage of session it("test basic usage of express sessions with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", @@ -787,7 +780,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //check session verify for with / without anti-csrf present it("test express session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -870,7 +863,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { // check session verify for with / without anti-csrf present it("test session verify without anti-csrf present express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -957,7 +950,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //check revoking session(s)** it("test revoking express sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1100,7 +1093,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //check manipulating session data it("test manipulating session data with express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1250,7 +1243,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { //check manipulating jwt payload it("test manipulating jwt payload with express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1465,7 +1458,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("sending custom response koa", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1517,7 +1510,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1572,7 +1565,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1630,7 +1623,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1694,7 +1687,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1758,7 +1751,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1822,7 +1815,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1889,7 +1882,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1956,7 +1949,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -2064,7 +2057,7 @@ describe(`Koa: ${printPath("[test/framework/koa.test.js]")}`, function () { }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { diff --git a/test/framework/koa.withTenantId.test.js b/test/framework/koa.withTenantId.test.js index bcddd77d62..3d12ba25ef 100644 --- a/test/framework/koa.withTenantId.test.js +++ b/test/framework/koa.withTenantId.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); let assert = require("assert"); let { ProcessState, PROCESS_STATE } = require("../../lib/build/processState"); let SuperTokens = require("../../"); @@ -32,8 +32,6 @@ const ThirdParty = require("../../recipe/thirdparty"); describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.server = undefined; }); @@ -44,14 +42,9 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct } }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // check if disabling api, the default refresh API does not work - you get a 404 it("test that if disabling api, the default refresh API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -123,7 +116,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that if disabling api, the default sign out API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", framework: "koa", @@ -193,7 +186,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //- check for token theft detection it("koa token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -316,7 +309,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //- check for token theft detection it("koa token theft detection with auto refresh middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -413,7 +406,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //check basic usage of session it("test basic usage of express sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -568,7 +561,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test signout API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -631,7 +624,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //check basic usage of session it("test basic usage of express sessions with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", @@ -785,7 +778,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //check session verify for with / without anti-csrf present it("test express session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -868,7 +861,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct // check session verify for with / without anti-csrf present it("test session verify without anti-csrf present express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -955,7 +948,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //check revoking session(s)** it("test revoking express sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1098,7 +1091,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //check manipulating session data it("test manipulating session data with express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1248,7 +1241,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct //check manipulating jwt payload it("test manipulating jwt payload with express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1463,7 +1456,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("sending custom response koa", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1515,7 +1508,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1570,7 +1563,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1628,7 +1621,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1692,7 +1685,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1756,7 +1749,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1820,7 +1813,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1887,7 +1880,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -1954,7 +1947,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { @@ -2062,7 +2055,7 @@ describe(`Koa: ${printPath("[test/framework/koa.withTenantId.test.js]")}`, funct }); it("test that search results correct output for 'provider: google, phone: 1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "koa", supertokens: { diff --git a/test/framework/loopback.test.js b/test/framework/loopback.test.js index 17d68fede4..4a81fcd0cf 100644 --- a/test/framework/loopback.test.js +++ b/test/framework/loopback.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); let assert = require("assert"); let { ProcessState, PROCESS_STATE } = require("../../lib/build/processState"); let SuperTokens = require("../.."); @@ -32,8 +32,6 @@ const sinon = require("sinon"); describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.app = require("./loopback-server/index.js"); }); @@ -44,14 +42,9 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function } }); - after(async function () { - await killAllST(); - await cleanST(); - }); - //check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -194,7 +187,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("sending custom response", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -239,7 +232,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -288,7 +281,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -340,7 +333,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -398,7 +391,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -457,7 +450,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -516,7 +509,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -578,7 +571,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -640,7 +633,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that search results correct output for 'provider: google', phone: 1", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -748,7 +741,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.test.js]")}`, function }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { diff --git a/test/framework/loopback.withTenantId.test.js b/test/framework/loopback.withTenantId.test.js index 997fc66c0d..9874863ac5 100644 --- a/test/framework/loopback.withTenantId.test.js +++ b/test/framework/loopback.withTenantId.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); let assert = require("assert"); let { ProcessState, PROCESS_STATE } = require("../../lib/build/processState"); let SuperTokens = require("../.."); @@ -30,8 +30,6 @@ const { default: fetch } = require("cross-fetch"); describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); this.app = require("./loopback-server/index.js"); }); @@ -42,14 +40,9 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" } }); - after(async function () { - await killAllST(); - await cleanST(); - }); - //check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -192,7 +185,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("sending custom response", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -237,7 +230,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that authorization header is read correctly in dashboard recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -286,7 +279,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that tags request respond with correct tags", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -338,7 +331,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that search results correct output for 'email: t'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -396,7 +389,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that search results correct output for multiple search items", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -455,7 +448,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that search results correct output for 'email: iresh'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -514,7 +507,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that search results correct output for 'phone: +1'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -576,7 +569,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that search results correct output for 'phone: 1('", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -638,7 +631,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that search results correct output for 'provider: google', phone: 1", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { @@ -746,7 +739,7 @@ describe(`Loopback: ${printPath("[test/framework/loopback.withTenantId.test.js]" }); it("test that search results correct output for 'provider: google'", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ framework: "loopback", supertokens: { diff --git a/test/hooks.js b/test/hooks.js new file mode 100644 index 0000000000..045808bbb5 --- /dev/null +++ b/test/hooks.js @@ -0,0 +1,10 @@ +const { resetAll } = require("./utils"); + +exports.mochaHooks = { + beforeEach() { + resetAll(); + }, + afterEach() { + resetAll(); + }, +}; diff --git a/test/import.test.js b/test/import.test.js index da2abc7d88..7c19ad07f4 100644 --- a/test/import.test.js +++ b/test/import.test.js @@ -28,6 +28,9 @@ describe(`importTests: ${printPath("[test/import.test.js]")}`, function () { * (Refer to: https://github.com/supertokens/supertokens-node/issues/513) */ it("Test that importing all build files independently does not cause errors", function () { + // This test is known to take a long time to run + this.timeout(80000); + const fileNames = getAllFilesInDirectory(resolve(process.cwd(), "./lib/build")).filter( (i) => !i.endsWith(".d.ts") && !i.endsWith(".map") ); diff --git a/test/interceptor.test.js b/test/interceptor.test.js index f6f505c20a..f2727055ae 100644 --- a/test/interceptor.test.js +++ b/test/interceptor.test.js @@ -1,12 +1,10 @@ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, - setKeyValueInConfig, - killAllSTCoresOnly, + mockResponse, mockRequest, signUPRequest, @@ -25,19 +23,12 @@ let { middleware, errorHandler } = require("../framework/express"); describe(`interceptor: ${printPath("[test/interceptor.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("network interceptor sanity", async function () { let isNetworkIntercepted = false; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -72,7 +63,7 @@ describe(`interceptor: ${printPath("[test/interceptor.test.js]")}`, function () it("network interceptor - incorrect core url", async function () { let isNetworkIntercepted = false; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -108,7 +99,7 @@ describe(`interceptor: ${printPath("[test/interceptor.test.js]")}`, function () it("network interceptor - incorrect query params", async function () { let isNetworkIntercepted = false; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -151,7 +142,7 @@ describe(`interceptor: ${printPath("[test/interceptor.test.js]")}`, function () it("network interceptor - incorrect request body", async function () { let isNetworkIntercepted = false; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/jwt/config.test.js b/test/jwt/config.test.js index 8d31942212..b11637a3f8 100644 --- a/test/jwt/config.test.js +++ b/test/jwt/config.test.js @@ -1,6 +1,6 @@ let assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let { ProcessState } = require("../../lib/build/processState"); let STExpress = require("../../"); const JWTRecipe = require("../../lib/build/recipe/jwt/recipe").default; @@ -9,18 +9,11 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`configTest: ${printPath("[test/jwt/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that the default config sets values correctly for JWT recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -45,7 +38,7 @@ describe(`configTest: ${printPath("[test/jwt/config.test.js]")}`, function () { }); it("Test that the config sets values correctly for JWT recipe when jwt validity is set", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/jwt/createJWTFeature.test.js b/test/jwt/createJWTFeature.test.js index 96024c5d15..492c8a1a62 100644 --- a/test/jwt/createJWTFeature.test.js +++ b/test/jwt/createJWTFeature.test.js @@ -1,7 +1,7 @@ let assert = require("assert"); const e = require("cors"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let JWTRecipe = require("../../lib/build/recipe/jwt"); let { ProcessState } = require("../../lib/build/processState"); @@ -10,18 +10,11 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`createJWTFeature: ${printPath("[test/jwt/createJWTFeature.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that sending 0 validity throws an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -50,7 +43,7 @@ describe(`createJWTFeature: ${printPath("[test/jwt/createJWTFeature.test.js]")}` }); it("Test that sending a invalid json throws an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -82,7 +75,7 @@ describe(`createJWTFeature: ${printPath("[test/jwt/createJWTFeature.test.js]")}` }); it("Test that returned JWT uses 100 years for expiry for default config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -117,7 +110,7 @@ describe(`createJWTFeature: ${printPath("[test/jwt/createJWTFeature.test.js]")}` }); it("Test that jwt validity is same as validity set in config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -156,7 +149,7 @@ describe(`createJWTFeature: ${printPath("[test/jwt/createJWTFeature.test.js]")}` }); it("Test that jwt validity is same as validity passed in createJWT function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/jwt/getJWKS.test.js b/test/jwt/getJWKS.test.js index e9593cc12f..bdf7c513f2 100644 --- a/test/jwt/getJWKS.test.js +++ b/test/jwt/getJWKS.test.js @@ -2,7 +2,7 @@ let assert = require("assert"); const express = require("express"); const request = require("supertest"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let { ProcessState } = require("../../lib/build/processState"); let JWTRecipe = require("../../lib/build/recipe/jwt"); @@ -12,18 +12,11 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`getJWKS: ${printPath("[test/jwt/getJWKS.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that default getJWKS api does not work when disabled", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -76,7 +69,7 @@ describe(`getJWKS: ${printPath("[test/jwt/getJWKS.test.js]")}`, function () { }); it("Test that default getJWKS works fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -127,7 +120,7 @@ describe(`getJWKS: ${printPath("[test/jwt/getJWKS.test.js]")}`, function () { }); it("Test that we can override the Cache-Control header through the function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -187,7 +180,7 @@ describe(`getJWKS: ${printPath("[test/jwt/getJWKS.test.js]")}`, function () { }); it("Test that we can remove the Cache-Control header through the function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -247,7 +240,7 @@ describe(`getJWKS: ${printPath("[test/jwt/getJWKS.test.js]")}`, function () { }); it("Test that we can override the Cache-Control header through the api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/jwt/override.test.js b/test/jwt/override.test.js index f7585c68bc..cb921dddfb 100644 --- a/test/jwt/override.test.js +++ b/test/jwt/override.test.js @@ -2,7 +2,7 @@ let assert = require("assert"); const express = require("express"); const request = require("supertest"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let { ProcessState } = require("../../lib/build/processState"); let JWTRecipe = require("../../lib/build/recipe/jwt"); @@ -12,18 +12,11 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`overrideTest: ${printPath("[test/jwt/override.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test overriding functions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let jwtCreated = undefined; let jwksKeys = undefined; @@ -120,7 +113,7 @@ describe(`overrideTest: ${printPath("[test/jwt/override.test.js]")}`, function ( }); it("Test overriding APIs", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let jwksKeys = undefined; diff --git a/test/middleware.test.js b/test/middleware.test.js index 04f297eb7d..a706e95145 100644 --- a/test/middleware.test.js +++ b/test/middleware.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, - setKeyValueInConfig, + + createCoreApplication, + extractInfoFromResponse, delay, } = require("./utils"); @@ -39,19 +37,12 @@ let { verifySession } = require("../recipe/session/framework/express"); describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // check that disabling default API actually disables it (for session) it("test disabling default API actually disables it", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -97,7 +88,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { }); it("test session verify middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -381,7 +372,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { }); it("test session verify middleware with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -670,7 +661,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { }); it("test session verify middleware with driver config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -964,7 +955,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { }); it("test session verify middleware with driver config with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -1264,7 +1255,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { // https://github.com/supertokens/supertokens-node/pull/108 // An expired access token is used and we see that try refresh token error is thrown it("test session verify middleware with expired access token and session required false", async function () { - const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } }); SuperTokens.init({ supertokens: { @@ -1404,7 +1395,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { // https://github.com/supertokens/supertokens-node/pull/108 // A session exists, is refreshed, then is revoked, and then we try and use the access token (after first refresh), and we see that unauthorised error is called. it("test session verify middleware with old access token and session required false", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -1625,7 +1616,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { // https://github.com/supertokens/supertokens-node/pull/108 // A session doesn't exist, and we call verifySession, and it let's go through it("test session verify middleware with no session and session required false", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -1688,7 +1679,7 @@ describe(`middleware: ${printPath("[test/middleware.test.js]")}`, function () { }); it("test session verify middleware without error handler added", async function () { - const connectionURI = await startST({ coreConfig: { access_token_validity: 5 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 5 } }); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/middleware2.test.js b/test/middleware2.test.js index 4cded0aec7..c48aaa2b60 100644 --- a/test/middleware2.test.js +++ b/test/middleware2.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, - setKeyValueInConfig, + + createCoreApplication, + extractInfoFromResponse, } = require("./utils"); let assert = require("assert"); @@ -36,18 +34,11 @@ let Passwordless = require("../recipe/passwordless"); describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test rid with session and non existant API in session recipe still works if the other recipe is initialized", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -81,7 +72,7 @@ describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () }); it("test no rid with existent API does not give 404", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -114,7 +105,7 @@ describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () }); it("test wrong rid with existent API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -167,7 +158,7 @@ describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () }); it("test random rid with existent API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -220,7 +211,7 @@ describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () }); it("test wrong rid returns 404 if recipe missing", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -272,7 +263,7 @@ describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () }); it("test rid as anti-csrf with existent API does not give 404", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -306,7 +297,7 @@ describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () }); it("test random rid with existent API still works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -340,7 +331,7 @@ describe(`middleware2: ${printPath("[test/middleware2.test.js]")}`, function () }); it("custom response express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/middleware3.test.js b/test/middleware3.test.js index e34c254044..5fac3e9e73 100644 --- a/test/middleware3.test.js +++ b/test/middleware3.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, - setKeyValueInConfig, + + createCoreApplication, + extractInfoFromResponse, } = require("./utils"); let assert = require("assert"); @@ -36,18 +34,11 @@ let { verifySession } = require("../recipe/session/framework/express"); describe(`middleware3: ${printPath("[test/middleware3.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test APIs work with tenantId in the request", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -94,7 +85,7 @@ describe(`middleware3: ${printPath("[test/middleware3.test.js]")}`, function () }); it("test Dashboard APIs match with tenantId", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/multitenancy/loginMethods.test.js b/test/multitenancy/loginMethods.test.js index f15fa33251..88c01c6ab3 100644 --- a/test/multitenancy/loginMethods.test.js +++ b/test/multitenancy/loginMethods.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy } = require("../utils"); let assert = require("assert"); const express = require("express"); const request = require("supertest"); @@ -29,19 +29,12 @@ let ThirdParty = require("../../recipe/thirdparty"); describe(`loginMethods: ${printPath("[test/multitenancy/loginMethods.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("with mfa not enabled", function () { it("should return firstFactors based on enabled recipes if no other configuration is available", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -75,7 +68,7 @@ describe(`loginMethods: ${printPath("[test/multitenancy/loginMethods.test.js]")} }); it("should return firstFactors based on enabled combination recipes if no other configuration is available", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -110,7 +103,7 @@ describe(`loginMethods: ${printPath("[test/multitenancy/loginMethods.test.js]")} }); it("should return from core config when configured in core", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -147,7 +140,7 @@ describe(`loginMethods: ${printPath("[test/multitenancy/loginMethods.test.js]")} describe("with mfa enabled", function () { it("static config is filtered with enabled recipes", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -181,7 +174,7 @@ describe(`loginMethods: ${printPath("[test/multitenancy/loginMethods.test.js]")} }); it("core config is prioritised over static config and is filtered with enabled recipes in SDK", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -219,7 +212,7 @@ describe(`loginMethods: ${printPath("[test/multitenancy/loginMethods.test.js]")} }); it("static config is filtered with enabled recipes in core", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -258,7 +251,7 @@ describe(`loginMethods: ${printPath("[test/multitenancy/loginMethods.test.js]")} }); it("static config is filtered with enabled recipes, but custom is allowed", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/multitenancy/tenants-crud.test.js b/test/multitenancy/tenants-crud.test.js index 221cda93b6..a0f3387002 100644 --- a/test/multitenancy/tenants-crud.test.js +++ b/test/multitenancy/tenants-crud.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy } = require("../utils"); let assert = require("assert"); const express = require("express"); const request = require("supertest"); @@ -25,18 +25,11 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test creation of tenants", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -65,7 +58,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test get tenant", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -109,7 +102,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test update tenant", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -150,7 +143,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test delete tenant", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -188,7 +181,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test creation of thirdParty config", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -222,7 +215,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test creation of thirdParty config with nulls", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -290,7 +283,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test deletion of thirdparty id", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -326,7 +319,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test updation of thirdparty provider", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -370,7 +363,7 @@ describe(`tenants-crud: ${printPath("[test/multitenancy/tenants-crud.test.js]")} }); it("test user association and disassociation with tenants", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/nextjs.test.js b/test/nextjs.test.js index ac334555dc..8f032fb807 100644 --- a/test/nextjs.test.js +++ b/test/nextjs.test.js @@ -15,22 +15,14 @@ const { parseJWTWithoutSignatureVerification } = require("../lib/build/recipe/session/jwt"); -const [major, minor, patch] = process.versions.node.split(".").map(Number); +const [major] = process.versions.node.split(".").map(Number); if (major >= 18) { - const { - printPath, - setupST, - startST, - killAllST, - cleanST, - delay, - killAllSTCoresOnly, - extractInfoFromResponse, - } = require("./utils"); + const { printPath, createCoreApplication, removeCoreApplication, delay } = require("./utils"); let assert = require("assert"); let { ProcessState } = require("../lib/build/processState"); let SuperTokens = require("../lib/build/").default; + let SuperTokensWrapper = require("../lib/build/supertokens").default; let { middleware } = require("../framework/express"); const Session = require("../lib/build/recipe/session"); const EmailPassword = require("../lib/build/recipe/emailpassword"); @@ -88,13 +80,42 @@ if (major >= 18) { } } + const createUser = async () => { + await testApiHandler({ + pagesHandler: nextApiHandlerWithMiddleware, + url: "/api/auth/signup/", + test: async ({ fetch }) => { + const res = await fetch({ + method: "POST", + headers: { + rid: "emailpassword", + }, + timeout: 10000, + body: JSON.stringify({ + formFields: [ + { + id: "email", + value: "john.doe@supertokens.io", + }, + { + id: "password", + value: "P@sSW0rd", + }, + ], + }), + }); + const respJson = await res.json(); + assert.deepStrictEqual(respJson.status, "OK"); + }, + }); + }; + describe(`Next.js Pages Router: ${printPath("[test/nextjs.test.js]")}`, function () { describe("with superTokensNextWrapper", function () { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST(); + + const connectionURI = await createCoreApplication(); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -126,14 +147,9 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Sign Up", async function () { await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/signup/", test: async ({ fetch }) => { const res = await fetch({ @@ -141,6 +157,7 @@ if (major >= 18) { headers: { rid: "emailpassword", }, + timeout: 10000, body: JSON.stringify({ formFields: [ { @@ -167,9 +184,12 @@ if (major >= 18) { }); it("Sign In", async function () { + // create user + await createUser(); + let tokens; await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/signin/", test: async ({ fetch }) => { const res = await fetch({ @@ -177,6 +197,7 @@ if (major >= 18) { headers: { rid: "emailpassword", }, + timeout: 10000, body: JSON.stringify({ formFields: [ { @@ -206,7 +227,7 @@ if (major >= 18) { // Case 1: Successful => add session to request object. await testApiHandler({ - handler: nextApiHandlerWithVerifySession, + pagesHandler: nextApiHandlerWithVerifySession, url: "/api/user/", test: async ({ fetch }) => { const res = await fetch({ @@ -217,6 +238,7 @@ if (major >= 18) { headers: { authorization: `Bearer ${tokens.access}`, }, + timeout: 10000, body: JSON.stringify({ formFields: [ { @@ -239,7 +261,7 @@ if (major >= 18) { // Case 2: Unauthenticated => return 401. await testApiHandler({ - handler: nextApiHandlerWithVerifySession, + pagesHandler: nextApiHandlerWithVerifySession, url: "/api/user/", test: async ({ fetch }) => { const res = await fetch({ @@ -247,6 +269,7 @@ if (major >= 18) { headers: { rid: "emailpassword", }, + timeout: 10000, headers: {}, body: JSON.stringify({ formFields: [ @@ -269,8 +292,10 @@ if (major >= 18) { }); it("Reset Password - Send Email", async function () { + await createUser(); + await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/user/password/reset/token", test: async ({ fetch }) => { const res = await fetch({ @@ -278,6 +303,7 @@ if (major >= 18) { headers: { rid: "emailpassword", }, + timeout: 10000, body: JSON.stringify({ formFields: [ { @@ -295,8 +321,10 @@ if (major >= 18) { }); it("Reset Password - Create new password", async function () { + await createUser(); + await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/user/password/reset/", test: async ({ fetch }) => { const res = await fetch({ @@ -304,6 +332,7 @@ if (major >= 18) { headers: { rid: "emailpassword", }, + timeout: 10000, body: JSON.stringify({ formFields: [ { @@ -322,8 +351,10 @@ if (major >= 18) { }); it("does Email Exist with existing email", async function () { + await createUser(); + await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/signup/email/exists", params: { email: "john.doe@supertokens.io", @@ -331,6 +362,7 @@ if (major >= 18) { test: async ({ fetch }) => { const res = await fetch({ method: "GET", + timeout: 10000, headers: { rid: "emailpassword", }, @@ -343,8 +375,10 @@ if (major >= 18) { }); it("does Email Exist with unknown email", async function () { + await createUser(); + await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/signup/email/exists", params: { email: "unknown@supertokens.io", @@ -352,6 +386,7 @@ if (major >= 18) { test: async ({ fetch }) => { const res = await fetch({ method: "GET", + timeout: 10000, headers: { rid: "emailpassword", }, @@ -363,23 +398,24 @@ if (major >= 18) { }); }); - it("Verify session successfully when session is present (check if it continues after)", function (done) { + it("Verify session successfully when session is present (check if it continues after)", async function () { + await createUser(); + testApiHandler({ - handler: async (request, response) => { + pagesHandler: async (request, response) => { await superTokensNextWrapper( async (next) => { await verifySession()(request, response, next); }, request, response - ).then(() => { - return done(new Error("not come here")); - }); + ); }, url: "/api/auth/user/info", test: async ({ fetch }) => { const res = await fetch({ method: "GET", + timeout: 10000, headers: { rid: "emailpassword", }, @@ -388,14 +424,15 @@ if (major >= 18) { }, }); assert.strictEqual(res.status, 401); - done(); }, }); }); it("Create new session", async function () { + await createUser(); + await testApiHandler({ - handler: async (request, response) => { + pagesHandler: async (request, response) => { const session = await superTokensNextWrapper( async () => { return await Session.createNewSession( @@ -419,6 +456,7 @@ if (major >= 18) { test: async ({ fetch }) => { const res = await fetch({ method: "GET", + timeout: 10000, }); assert.strictEqual(res.status, 200); assert.deepStrictEqual(await res.json(), { @@ -431,11 +469,10 @@ if (major >= 18) { }); describe("with superTokensNextWrapper, body parser tests", function () { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST(); + + const connectionURI = await createCoreApplication(); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -487,14 +524,11 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("testing JSON body", async function () { + await createUser(); + await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/user/password/reset", test: async ({ fetch }) => { const res = await fetch({ @@ -502,6 +536,7 @@ if (major >= 18) { headers: { rid: "emailpassword", }, + timeout: 10000, body: JSON.stringify({ token: "hello", formFields: [ @@ -520,8 +555,10 @@ if (major >= 18) { }); it("testing apple redirect (form data body)", async () => { + await createUser(); + await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/callback/apple", test: async ({ fetch }) => { let state = Buffer.from( @@ -540,6 +577,7 @@ if (major >= 18) { rid: "thirdparty", "content-type": "application/x-www-form-urlencoded", }, + timeout: 10000, body: encodedData, redirect: "manual", }); @@ -554,11 +592,10 @@ if (major >= 18) { }); describe("with superTokensNextWrapper, overriding throws error", function () { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST(); + + const connectionURI = await createCoreApplication(); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -593,14 +630,9 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Sign Up", async function () { await testApiHandler({ - handler: nextApiHandlerWithMiddleware, + pagesHandler: nextApiHandlerWithMiddleware, url: "/api/auth/signup/", test: async ({ fetch }) => { const res = await fetch({ @@ -608,6 +640,7 @@ if (major >= 18) { headers: { rid: "emailpassword", }, + timeout: 10000, body: JSON.stringify({ formFields: [ { @@ -632,11 +665,10 @@ if (major >= 18) { }); describe(`Next.js App Router: ${printPath("[test/nextjs.test.js]")}`, function () { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } }); + + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } }); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -669,11 +701,6 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Sign Up", async function () { const handleCall = getAppDirRequestHandler(NextResponse); @@ -681,6 +708,7 @@ if (major >= 18) { const signUpRequest = new NextRequest("http://localhost:3000/api/auth/signup", { method: "POST", headers: { rid: "emailpassword" }, + timeout: 10000, body: JSON.stringify({ formFields: [ { id: "email", value: userEmail }, @@ -708,6 +736,7 @@ if (major >= 18) { const requestInfo = { method: "POST", headers: { rid: "emailpassword" }, + timeout: 10000, body: JSON.stringify({ formFields: [ { id: "email", value: userEmail }, @@ -742,6 +771,7 @@ if (major >= 18) { headers: { Cookie: `sAccessToken=${tokens.access}`, }, + timeout: 10000, }); let sessionContainer = await getSSRSession(authenticatedRequest.cookies.getAll()); @@ -749,7 +779,7 @@ if (major >= 18) { assert.equal(sessionContainer.hasToken, true); assert.equal(sessionContainer.accessTokenPayload.sub, process.env.user); - const unAuthenticatedRequest = new NextRequest("http://localhost:3000/api/get-user"); + const unAuthenticatedRequest = new NextRequest("http://localhost:3000/api/get-user", { timeout: 10000 }); sessionContainer = await getSSRSession(unAuthenticatedRequest.cookies.getAll()); @@ -761,6 +791,7 @@ if (major >= 18) { headers: { Cookie: `sAccessToken=${tokens.access}`, }, + timeout: 10000, }); sessionContainer = await getSSRSession(requestWithExpiredToken.cookies.getAll()); @@ -775,6 +806,7 @@ if (major >= 18) { headers: { Authorization: `Bearer ${tokens.access}`, }, + timeout: 10000, }); const authenticatedResponse = await withSession(authenticatedRequest, async (err, session) => { @@ -810,7 +842,7 @@ if (major >= 18) { assert.strictEqual(error, unknownError); } - const unAuthenticatedRequest = new NextRequest("http://localhost:3000/api/get-user"); + const unAuthenticatedRequest = new NextRequest("http://localhost:3000/api/get-user", { timeout: 10000 }); const unAuthenticatedResponse = await withSession(unAuthenticatedRequest, async (err, session) => { if (err) return NextResponse.json(err, { status: 500 }); @@ -826,6 +858,7 @@ if (major >= 18) { headers: { Cookie: `sAccessToken=${tokens.access}`, }, + timeout: 10000, }); const responseWithFailedClaim = await withSession( @@ -853,6 +886,7 @@ if (major >= 18) { headers: { Authorization: `Bearer ${tokens.access}`, }, + timeout: 10000, }); const responseWithExpiredToken = await withSession(requestWithExpiredToken, async (err, session) => { @@ -883,6 +917,7 @@ if (major >= 18) { headers: { Authorization: `Bearer ${tokens.access}`, }, + timeout: 10000, }); const authenticatedResponse = await withSession(authenticatedRequest, async (err, session) => { @@ -919,6 +954,7 @@ if (major >= 18) { headers: { Authorization: `Bearer ${tokens.access}`, }, + timeout: 10000, }); const authenticatedResponse = await withPreParsedRequestResponse( @@ -958,17 +994,20 @@ if (major >= 18) { } }); - it("should go to next error handler when withSession is called without core", async function () { + // skipping this test because it requires killing the core and starting it again, which is not supported anymore + it.skip("should go to next error handler when withSession is called without core", async function () { const tokens = await getValidTokensAfterSignup({ tokenTransferMethod: "header" }); const authenticatedRequest = new NextRequest("http://localhost:3000/api/get-user", { headers: { Cookie: `sAccessToken=${tokens.access}`, }, + timeout: 10000, }); - // Manually kill to get error when withSession is called - await killAllSTCoresOnly(); + await removeCoreApplication({ + connectionURI: SuperTokensWrapper.getInstanceOrThrowError().supertokens.connectionURI, + }); const authenticatedResponse = await withSession( authenticatedRequest, @@ -992,11 +1031,10 @@ if (major >= 18) { }); describe("session refresh test", async () => { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST(); + + const connectionURI = await createCoreApplication(); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -1017,11 +1055,6 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("should successfully refresh session", async () => { const tokens = await getValidTokensAfterSignup({ tokenTransferMethod: "cookie" }); @@ -1030,6 +1063,7 @@ if (major >= 18) { Cookie: `sAccessToken=${tokens.access};sRefreshToken=${tokens.refresh}`, "st-auth-mode": "cookie", }, + timeout: 10000, }); const authenticatedResponse = await withPreParsedRequestResponse( @@ -1047,11 +1081,10 @@ if (major >= 18) { describe(`getSSRSession:hasToken`, function () { describe("tokenTransferMethod = any", function () { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST(); + + const connectionURI = await createCoreApplication(); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -1072,15 +1105,10 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("should return hasToken value correctly", async function () { const tokens = await getValidTokensAfterSignup({ tokenTransferMethod: "header" }); - const requestWithNoToken = new NextRequest("http://localhost:3000/api/get-user"); + const requestWithNoToken = new NextRequest("http://localhost:3000/api/get-user", { timeout: 10000 }); sessionContainer = await getSSRSession(requestWithNoToken.cookies.getAll()); @@ -1090,6 +1118,7 @@ if (major >= 18) { headers: { Cookie: `sAccessToken=some-random-token`, }, + timeout: 10000, }); sessionContainer = await getSSRSession(requestWithInvalidToken.cookies.getAll()); @@ -1099,6 +1128,7 @@ if (major >= 18) { headers: { Cookie: `sAccessToken=${tokens.access}`, }, + timeout: 10000, }); sessionContainer = await getSSRSession(requestWithTokenInCookie.cookies.getAll()); @@ -1107,11 +1137,10 @@ if (major >= 18) { }); describe("tokenTransferMethod = cookie", function () { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST(); + + const connectionURI = await createCoreApplication(); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -1132,15 +1161,10 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("should return hasToken value correctly", async function () { const tokens = await getValidTokensAfterSignup({ tokenTransferMethod: "cookie" }); - const requestWithNoToken = new NextRequest("http://localhost:3000/api/get-user"); + const requestWithNoToken = new NextRequest("http://localhost:3000/api/get-user", { timeout: 10000 }); sessionContainer = await getSSRSession(requestWithNoToken.cookies.getAll()); @@ -1150,6 +1174,7 @@ if (major >= 18) { headers: { Cookie: `sAccessToken=some-random-token`, }, + timeout: 10000, }); sessionContainer = await getSSRSession(requestWithInvalidToken.cookies.getAll()); @@ -1159,6 +1184,7 @@ if (major >= 18) { headers: { Authorization: `Bearer ${tokens.access}`, }, + timeout: 10000, }); sessionContainer = await getSSRSession(requestWithTokenInHeader.cookies.getAll()); @@ -1168,6 +1194,7 @@ if (major >= 18) { headers: { Cookie: `sAccessToken=${tokens.access}`, }, + timeout: 10000, }); sessionContainer = await getSSRSession(requestWithTokenInCookie.cookies.getAll()); @@ -1177,11 +1204,10 @@ if (major >= 18) { }); describe("with email verification should throw st-ev claim has expired", async () => { - before(async function () { + beforeEach(async function () { process.env.user = undefined; - await killAllST(); - await setupST(); - const connectionURI = await startST(); + + const connectionURI = await createCoreApplication(); ProcessState.getInstance().reset(); SuperTokens.init({ supertokens: { @@ -1205,17 +1231,13 @@ if (major >= 18) { }); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("should throw st-ev claim has expired for unverified email", async () => { const tokens = await getValidTokensAfterSignup(); const authenticatedRequest = new NextRequest("http://localhost:3000/api/get-user", { headers: { Cookie: `sAccessToken=${tokens.access}`, }, + timeout: 10000, }); const authenticatedResponse = await withSession(authenticatedRequest, async (err, session) => { @@ -1254,6 +1276,7 @@ if (major >= 18) { { id: "password", value: "P@sSW0rd" }, ], }), + timeout: 10000, }; const signUpRequest = new NextRequest("http://localhost:3000/api/auth/signup", requestInfo); diff --git a/test/oauth2/config.test.js b/test/oauth2/config.test.js index 5d28589251..7283c26e32 100644 --- a/test/oauth2/config.test.js +++ b/test/oauth2/config.test.js @@ -1,6 +1,6 @@ let assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let { ProcessState } = require("../../lib/build/processState"); let STExpress = require("../../"); const OAuth2ProviderRecipe = require("../../lib/build/recipe/oauth2provider/recipe").default; @@ -9,18 +9,11 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`configTest: ${printPath("[test/oauth2/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that the recipe initializes without a config obj", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/oauth2/oauth2client.test.js b/test/oauth2/oauth2client.test.js index a95af4fe8b..1e6c7695bd 100644 --- a/test/oauth2/oauth2client.test.js +++ b/test/oauth2/oauth2client.test.js @@ -1,24 +1,17 @@ let assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let { ProcessState } = require("../../lib/build/processState"); let STExpress = require("../../"); let OAuth2Recipe = require("../../recipe/oauth2provider"); describe(`OAuth2ClientTests: ${printPath("[test/oauth2/oauth2client.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("should create an OAuth2Client instance with empty input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -39,7 +32,7 @@ describe(`OAuth2ClientTests: ${printPath("[test/oauth2/oauth2client.test.js]")}` }); it("should create an OAuth2Client instance with custom input", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -63,7 +56,7 @@ describe(`OAuth2ClientTests: ${printPath("[test/oauth2/oauth2client.test.js]")}` }); it("should update the OAuth2Client", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -108,7 +101,7 @@ describe(`OAuth2ClientTests: ${printPath("[test/oauth2/oauth2client.test.js]")}` }); it("should delete the OAuth2Client", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -138,7 +131,7 @@ describe(`OAuth2ClientTests: ${printPath("[test/oauth2/oauth2client.test.js]")}` }); it("should get OAuth2Clients with pagination", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -180,7 +173,7 @@ describe(`OAuth2ClientTests: ${printPath("[test/oauth2/oauth2client.test.js]")}` }); it("should get OAuth2Clients with filter", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/openid/api.test.js b/test/openid/api.test.js index 724c633df2..9fde99101c 100644 --- a/test/openid/api.test.js +++ b/test/openid/api.test.js @@ -2,7 +2,7 @@ let assert = require("assert"); const express = require("express"); const request = require("supertest"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let { ProcessState } = require("../../lib/build/processState"); let STExpress = require("../../"); const OpenIdRecipe = require("../../lib/build/recipe/openid/recipe").default; @@ -13,18 +13,11 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`apiTest: ${printPath("[test/openid/api.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that with default config calling discovery configuration endpoint works as expected", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -68,7 +61,7 @@ describe(`apiTest: ${printPath("[test/openid/api.test.js]")}`, function () { }); it("Test that with apiBasePath calling discovery configuration endpoint works as expected", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -113,7 +106,7 @@ describe(`apiTest: ${printPath("[test/openid/api.test.js]")}`, function () { }); it("Test that discovery endpoint does not work when disabled", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/openid/config.test.js b/test/openid/config.test.js index 1f7a52438b..c71eff3414 100644 --- a/test/openid/config.test.js +++ b/test/openid/config.test.js @@ -1,6 +1,6 @@ let assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let { ProcessState } = require("../../lib/build/processState"); let STExpress = require("../../"); const OpenIdRecipe = require("../../lib/build/recipe/openid/recipe").default; @@ -9,18 +9,11 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`configTest: ${printPath("[test/openid/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that the default config sets values correctly for OpenID recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -44,7 +37,7 @@ describe(`configTest: ${printPath("[test/openid/config.test.js]")}`, function () }); it("Test that the default config sets values correctly for OpenID recipe with apiBasePath", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -69,7 +62,7 @@ describe(`configTest: ${printPath("[test/openid/config.test.js]")}`, function () }); it("Test that the config sets values correctly for OpenID recipe with issuer", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -109,7 +102,7 @@ describe(`configTest: ${printPath("[test/openid/config.test.js]")}`, function () }); it("Test that issuer with gateway path works fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/openid/openid.test.js b/test/openid/openid.test.js index 909a412f6d..5802b45ac2 100644 --- a/test/openid/openid.test.js +++ b/test/openid/openid.test.js @@ -1,6 +1,6 @@ let assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let { ProcessState } = require("../../lib/build/processState"); let STExpress = require("../../"); const OpenIdRecipe = require("../../lib/build/recipe/openid/recipe").default; @@ -10,18 +10,11 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`openIdTest: ${printPath("[test/openid/openid.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test that with default config discovery configuration is as expected", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -48,7 +41,7 @@ describe(`openIdTest: ${printPath("[test/openid/openid.test.js]")}`, function () }); it("Test that with default config discovery configuration is as expected with api base path", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -76,7 +69,7 @@ describe(`openIdTest: ${printPath("[test/openid/openid.test.js]")}`, function () }); it("Test that with default config discovery configuration is as expected with custom issuer", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/openid/override.test.js b/test/openid/override.test.js index d414d906d8..a30a9daf33 100644 --- a/test/openid/override.test.js +++ b/test/openid/override.test.js @@ -2,7 +2,7 @@ let assert = require("assert"); const express = require("express"); const request = require("supertest"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let { ProcessState } = require("../../lib/build/processState"); let STExpress = require("../../"); const OpenIdRecipe = require("../../lib/build/recipe/openid/recipe").default; @@ -13,18 +13,11 @@ let { middleware, errorHandler } = require("../../framework/express"); describe(`overrideTest: ${printPath("[test/openid/override.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("Test overriding open id functions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -85,7 +78,7 @@ describe(`overrideTest: ${printPath("[test/openid/override.test.js]")}`, functio }); it("Test overriding open id apis", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/passwordless/apis.test.js b/test/passwordless/apis.test.js index d37018cab7..80d97cf16a 100644 --- a/test/passwordless/apis.test.js +++ b/test/passwordless/apis.test.js @@ -14,13 +14,10 @@ */ const { printPath, - setupST, - startST, - startSTWithMultitenancy, - killAllST, - cleanST, - setKeyValueInConfig, - stopST, + + createCoreApplication, + createCoreApplicationWithMultitenancy, + resetAll, } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); @@ -63,18 +60,11 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }; }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test emailExistsAPI on old path with email password conflicting path, but different rid", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let emailPasswordEmailExistsCalled = false; let passwordlessEmailExistsCalled = false; @@ -257,7 +247,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test emailExistsAPI conflicting with email password", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let emailPasswordEmailExistsCalled = false; let passwordlessEmailExistsCalled = false; @@ -417,7 +407,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test APIs still work with thirdpartypasswordless recipe", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let userInputCode = undefined; STExpress.init({ @@ -527,7 +517,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func */ it("test the sign up /in flow with email using the EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let userInputCode = undefined; STExpress.init({ @@ -630,7 +620,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func */ it("test the sign up /in flow with phoneNumber using the EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let userInputCode = undefined; STExpress.init({ @@ -732,7 +722,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func * - create code with email and then resend code and make sure that sending email function is called while resending code */ it("test creating a code with email and then resending the code and check that the sending custom email function is called while using the EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isCreateAndSendCustomEmailCalled = false; @@ -827,7 +817,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func * - create code with phone and then resend code and make sure that sending SMS function is called while resending code */ it("test creating a code with phone and then resending the code and check that the sending custom SMS function is called while using the EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isCreateAndSendCustomTextMessageCalled = false; @@ -923,7 +913,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func * - sending neither email and phone in createCode API throws bad request */ it("test invalid input to createCodeAPI while using the EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1032,7 +1022,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func */ it("test adding phoneNumber to a users info and signing in will sign in the same user, using the EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let userInputCode = undefined; @@ -1171,7 +1161,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func // check that if user has not given linkCode nor (deviceId+userInputCode), it throws a bad request error. it("test not passing any fields to consumeCodeAPI", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1235,7 +1225,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test consumeCodeAPI with magic link", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1312,7 +1302,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test consumeCodeAPI with code", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1408,7 +1398,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test consumeCodeAPI with expired code", async function () { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { passwordless_code_lifetime: 1000, // one second lifetime }, @@ -1491,7 +1481,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test createCodeAPI with email", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1583,7 +1573,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test createCodeAPI with phoneNumber", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1675,7 +1665,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test magicLink format in createCodeAPI", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let magicLinkURL = undefined; STExpress.init({ @@ -1752,7 +1742,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test emailExistsAPI", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1847,7 +1837,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test emailExistsAPI with new path", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1942,7 +1932,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test phoneNumberExistsAPI", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -2037,7 +2027,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test phoneNumberExistsAPI with new path", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -2134,7 +2124,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func //resendCode API it("test resendCodeAPI", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -2223,7 +2213,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func // test that you create a code with PHONE in config, you then change the config to use EMAIL, you call resendCode API, it should return RESTART_FLOW_ERROR it("test resendCodeAPI when changing contact method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -2267,8 +2257,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func phoneNumber: "+1234567890", }); - await killAllST(); - const connectionURI = await startST(); + resetAll(); STExpress.init({ supertokens: { @@ -2320,7 +2309,7 @@ describe(`apisFunctions: ${printPath("[test/passwordless/apis.test.js]")}`, func }); it("test resend code from different tenant throws error", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); let isCreateAndSendCustomEmailCalled = false; diff --git a/test/passwordless/config.test.js b/test/passwordless/config.test.js index 5e8540983d..78185c4c12 100644 --- a/test/passwordless/config.test.js +++ b/test/passwordless/config.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication, resetAll } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); let Passwordless = require("../../recipe/passwordless"); @@ -27,22 +27,15 @@ let PasswordlessRecipe = require("../../lib/build/recipe/passwordless/recipe").d describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - /* contactMethod: EMAIL_OR_PHONE - minimal config */ it("test minimum config with EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -91,7 +84,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun - adding custom validators for phone and email and making sure that they are called */ it("test adding custom validators for phone and email with EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isValidateEmailAddressCalled = false; let isValidatePhoneNumberCalled = false; @@ -198,7 +191,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test custom function to send email with EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isCreateAndSendCustomEmailCalled = false; @@ -276,7 +269,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test custom function to send text SMS with EMAIL_OR_PHONE contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isCreateAndSendCustomTextMessageCalled = false; @@ -352,7 +345,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun - minimal input works */ it("test minimum config with phone contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -396,7 +389,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test if validatePhoneNumber is called with phone contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isValidatePhoneNumberCalled = false; STExpress.init({ @@ -464,8 +457,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun { // If you return a string from the function, the API throws a GENERIC ERROR - await killAllST(); - const connectionURI = await startST(); + resetAll(); isValidatePhoneNumberCalled = false; @@ -529,7 +521,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test createAndSendCustomTextMessage with flowType: USER_INPUT_CODE and phone contact method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isUserInputCodeAndUrlWithLinkCodeValid = false; let isOtherInputValid = false; @@ -606,7 +598,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test createAndSendCustomTextMessage with flowType: MAGIC_LINK and phone contact method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isUserInputCodeAndUrlWithLinkCodeValid = false; STExpress.init({ @@ -672,7 +664,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun - flowType: USER_INPUT_CODE_AND_MAGIC_LINK -> userInputCode !== undefined && urlWithLinkCode !== undefined */ it("test createAndSendCustomTextMessage with flowType: USER_INPUT_CODE_AND_MAGIC_LINK and phone contact method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isUserInputCodeAndUrlWithLinkCodeValid = false; STExpress.init({ @@ -739,7 +731,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test createAndSendCustomTextMessage, if error is thrown, it should contain a general error in the response", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isCreateAndSendCustomTextMessageCalled = false; STExpress.init({ @@ -809,7 +801,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test minimum config with email contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -854,7 +846,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test if validateEmailAddress is called with email contactMethod", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isValidateEmailAddressCalled = false; STExpress.init({ @@ -922,8 +914,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun { // If you return a string from the function, the API throws a GENERIC ERROR - await killAllST(); - const connectionURI = await startST(); + resetAll(); isValidateEmailAddressCalled = false; @@ -986,7 +977,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test createAndSendCustomEmail with flowType: USER_INPUT_CODE and email contact method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isUserInputCodeAndUrlWithLinkCodeValid = false; let isOtherInputValid = false; @@ -1063,7 +1054,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test createAndSendCustomEmail with flowType: MAGIC_LINK and email contact method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isUserInputCodeAndUrlWithLinkCodeValid = false; STExpress.init({ @@ -1129,7 +1120,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun - flowType: USER_INPUT_CODE_AND_MAGIC_LINK -> userInputCode !== undefined && urlWithLinkCode !== undefined */ it("test createAndSendCustomTextMessage with flowType: USER_INPUT_CODE_AND_MAGIC_LINK and email contact method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isUserInputCodeAndUrlWithLinkCodeValid = false; STExpress.init({ @@ -1196,7 +1187,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test createAndSendCustomEmail, if error is thrown, the status in the response should be a general error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let isCreateAndSendCustomEmailCalled = false; STExpress.init({ @@ -1268,7 +1259,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test missing compulsory configs throws an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { // missing flowType @@ -1298,8 +1289,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun } { - await killAllST(); - const connectionURI = await startST(); + resetAll(); // missing contactMethod try { @@ -1336,7 +1326,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun */ it("test passing getCustomUserInputCode using different codes", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let customCode = undefined; let userCodeSent = undefined; @@ -1425,7 +1415,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun }); it("test passing getCustomUserInputCode using the same code", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); // using the same customCode let customCode = "customCode"; @@ -1520,7 +1510,7 @@ describe(`config tests: ${printPath("[test/passwordless/config.test.js]")}`, fun // Check basic override usage it("test basic override usage in passwordless", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let customDeviceId = "customDeviceId"; diff --git a/test/passwordless/emailDelivery.test.js b/test/passwordless/emailDelivery.test.js index a44fbad9f8..23a0b6205c 100644 --- a/test/passwordless/emailDelivery.test.js +++ b/test/passwordless/emailDelivery.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, delay } = require("../utils"); +const { printPath, createCoreApplication, delay } = require("../utils"); let STExpress = require("../.."); let Session = require("../../recipe/session"); let assert = require("assert"); @@ -28,19 +28,15 @@ const request = require("supertest"); describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); after(async function () { process.env.TEST_MODE = "testing"; - await killAllST(); - await cleanST(); }); it("test default backward compatibility api being called: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -108,7 +104,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test backward compatibility: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -168,7 +164,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test custom override: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -251,7 +247,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test smtp service: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let codeLifetime = undefined; let userInputCode = undefined; @@ -352,7 +348,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test default backward compatibility api being called, error message sent back to user: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -427,7 +423,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test default backward compatibility api being called: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -513,7 +509,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test backward compatibility: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -592,7 +588,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test custom override: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -702,7 +698,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test smtp service: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -831,7 +827,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("test default backward compatibility api being called, error message sent back to user: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -930,7 +926,7 @@ describe(`emailDelivery: ${printPath("[test/passwordless/emailDelivery.test.js]" }); it("Test that passwordless email uses correct origin", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let url = ""; STExpress.init({ diff --git a/test/passwordless/multitenancy.test.js b/test/passwordless/multitenancy.test.js index 8dd392b92c..ef1dfe41d8 100644 --- a/test/passwordless/multitenancy.test.js +++ b/test/passwordless/multitenancy.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, stopST, killAllST, cleanST, resetAll } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy, resetAll } = require("../utils"); let SuperTokens = require("../../"); let Session = require("../../recipe/session"); let SessionRecipe = require("../../lib/build/recipe/session/recipe").default; @@ -29,18 +29,11 @@ let Multitenancy = require("../../recipe/multitenancy"); describe(`multitenancy: ${printPath("[test/passwordless/multitenancy.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test recipe functions", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/passwordless/recipeFunctions.test.js b/test/passwordless/recipeFunctions.test.js index 82d1ed5541..6920145c58 100644 --- a/test/passwordless/recipeFunctions.test.js +++ b/test/passwordless/recipeFunctions.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, setKeyValueInConfig } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); let Passwordless = require("../../recipe/passwordless"); @@ -25,18 +25,11 @@ const { default: RecipeUserId } = require("../../lib/build/recipeUserId"); describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("getUser test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -151,7 +144,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. }); it("createCode test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -218,7 +211,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. }); it("createNewCodeForDevice test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -327,7 +320,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. }); it("consumeCode test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -428,7 +421,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. }); it("consumeCode test with EXPIRED_USER_INPUT_CODE_ERROR", async function () { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { passwordless_code_lifetime: 1000, // one second lifetime }, @@ -486,7 +479,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. // updateUser it("updateUser contactMethod email test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -558,7 +551,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. }); it("updateUser contactMethod phone test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -627,7 +620,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. // revokeAllCodes it("revokeAllCodes test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -698,7 +691,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. }); it("revokeCode test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -770,7 +763,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. // listCodesByEmail it("listCodesByEmail test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -826,7 +819,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. //listCodesByPhoneNumber it("listCodesByPhoneNumber test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -882,7 +875,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. // listCodesByDeviceId and listCodesByPreAuthSessionId it("listCodesByDeviceId and listCodesByPreAuthSessionId test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -940,7 +933,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. */ it("createMagicLink test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -986,7 +979,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. // signInUp test it("signInUp test", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1032,7 +1025,7 @@ describe(`recipeFunctions: ${printPath("[test/passwordless/recipeFunctions.test. }); it("Passwordless user that isEmailVerified returns true for both email and phone", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/passwordless/smsDelivery.test.js b/test/passwordless/smsDelivery.test.js index 3658ec5cb9..bb22780077 100644 --- a/test/passwordless/smsDelivery.test.js +++ b/test/passwordless/smsDelivery.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, delay } = require("../utils"); +const { printPath, createCoreApplication, delay } = require("../utils"); let STExpress = require("../.."); let Session = require("../../recipe/session"); let assert = require("assert"); @@ -28,19 +28,16 @@ let { isCDIVersionCompatible } = require("../utils"); describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, function () { beforeEach(async function () { process.env.TEST_MODE = "testing"; - await killAllST(); - await setupST(); + ProcessState.getInstance().reset(); }); after(async function () { process.env.TEST_MODE = "testing"; - await killAllST(); - await cleanST(); }); it("test default backward compatibility api being called: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -111,7 +108,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test backward compatibility: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -171,7 +168,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test custom override: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -254,7 +251,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test twilio service: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let userInputCode = undefined; @@ -356,7 +353,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test default backward compatibility api being called, error message sent back to user: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -431,7 +428,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test supertokens service: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let userInputCode = undefined; @@ -515,7 +512,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test default backward compatibility api being called, error message not sent back to user if response code is 429: passwordless login", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -584,7 +581,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test default backward compatibility api being called: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -673,7 +670,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test backward compatibility: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -752,7 +749,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test custom override: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let urlWithLinkCode = undefined; @@ -862,7 +859,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test twilio service: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let userInputCode = undefined; @@ -1004,7 +1001,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test default backward compatibility api being called, error message sent back to user: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1103,7 +1100,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test supertokens service: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let phoneNumber = undefined; let codeLifetime = undefined; let userInputCode = undefined; @@ -1208,7 +1205,7 @@ describe(`smsDelivery: ${printPath("[test/passwordless/smsDelivery.test.js]")}`, }); it("test default backward compatibility api being called, error message not sent back to user if response code is 429: resend code api", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/querier.test.js b/test/querier.test.js index 64ff734800..839f71319a 100644 --- a/test/querier.test.js +++ b/test/querier.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, setKeyValueInConfig } = require("./utils"); +const { printPath, createCoreApplication } = require("./utils"); let ST = require("../"); let { Querier } = require("../lib/build/querier"); let assert = require("assert"); @@ -28,19 +28,12 @@ const { default: fetch } = require("cross-fetch"); describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // Check that once the API version is there, it doesn't need to query again it("test that if that once API version is there, it doesn't need to query again", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { connectionURI, @@ -73,7 +66,7 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { // Check that rid is added to the header iff it's a "/recipe" || "/recipe/*" request. it("test that rid is added to the header if it's a recipe request", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { connectionURI, @@ -145,10 +138,11 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { } }); - it("three cores and round robin", async function () { - const connectionURI = await startST(); - await startST({ host: "localhost", port: 8081 }); - await startST({ host: "localhost", port: 8082 }); + // can't start/stop multiple cores + it.skip("three cores and round robin", async function () { + const connectionURI = await createCoreApplication(); + await createCoreApplication({ host: "localhost", port: 8081 }); + await createCoreApplication({ host: "localhost", port: 8082 }); ST.init({ supertokens: { @@ -174,9 +168,10 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { assert.equal(hostsAlive.has("http://localhost:8082"), true); }); - it("three cores, one dead and round robin", async function () { - const connectionURI = await startST(); - await startST({ host: "localhost", port: 8082 }); + // can't start/stop multiple cores + it.skip("three cores, one dead and round robin", async function () { + const connectionURI = await createCoreApplication(); + await createCoreApplication({ host: "localhost", port: 8082 }); ST.init({ supertokens: { connectionURI: `${connectionURI};http://localhost:8081/;http://localhost:8082`, @@ -202,7 +197,7 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { }); it("test that no connectionURI given, but recipe used throws an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ appInfo: { apiDomain: "api.supertokens.io", @@ -224,7 +219,7 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { }); it("test that no connectionURI given, recipe override and used doesn't thrown an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ appInfo: { apiDomain: "api.supertokens.io", @@ -252,9 +247,10 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { assert((await Session.getSessionInformation("someHandle")) === "someHandle"); }); - it("test with core base path", async function () { + // can't set base_path when creating a new app + it.skip("test with core base path", async function () { // first we need to know if the core used supports base_path config - const connectionURI = await startST({ port: 8081, coreConfig: { base_path: "/test" } }); + const connectionURI = await createCoreApplication({ port: 8081, coreConfig: { base_path: "/test" } }); try { const res = await fetch(`${connectionURI}/test/hello`); @@ -282,9 +278,10 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { assert(res.length === 0); }); - it("test with incorrect core base path should fail", async function () { + // can't set base_path when creating a new app + it.skip("test with incorrect core base path should fail", async function () { // first we need to know if the core used supports base_path config - const connectionURI = await startST({ port: 8081, coreConfig: { base_path: "/some/path" } }); + const connectionURI = await createCoreApplication({ port: 8081, coreConfig: { base_path: "/some/path" } }); try { const res = await fetch(`${connectionURI}/some/path/hello`); @@ -322,9 +319,10 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { } }); - it("test with multiple core base path", async function () { + // can't set base_path when creating a new app + it.skip("test with multiple core base path", async function () { // first we need to know if the core used supports base_path config - const connectionURI = await startST({ port: 8081, coreConfig: { base_path: "/some/path" } }); + const connectionURI = await createCoreApplication({ port: 8081, coreConfig: { base_path: "/some/path" } }); try { const res = await fetch(`${connectionURI}/some/path/hello`); @@ -339,7 +337,7 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { throw error; } - await startST({ + await createCoreApplication({ host: "localhost", port: 8082, coreConfig: { @@ -373,7 +371,7 @@ describe(`Querier: ${printPath("[test/querier.test.js]")}`, function () { }); it("test that no-cache header is added when querying the core", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { connectionURI, diff --git a/test/ratelimiting.test.js b/test/ratelimiting.test.js index 40941a13bf..05a7e4c72e 100644 --- a/test/ratelimiting.test.js +++ b/test/ratelimiting.test.js @@ -1,5 +1,5 @@ const { ProcessState } = require("../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startST } = require("./utils"); +const { printPath, createCoreApplication } = require("./utils"); let STExpress = require("../"); let Dashboard = require("../recipe/dashboard"); let EmailVerification = require("../recipe/emailverification"); @@ -14,19 +14,15 @@ const RateLimitedStatus = 429; describe(`Querier rate limiting: ${printPath("[test/ratelimiting.test.js]")}`, () => { beforeEach(async () => { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); after(async function () { - await killAllST(); - await cleanST(); Querier.apiVersion = undefined; }); it("Test that network call is retried properly", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { // Using 8083 because we need querier to call the test express server instead of the core @@ -105,7 +101,7 @@ describe(`Querier rate limiting: ${printPath("[test/ratelimiting.test.js]")}`, ( }); it("Test that rate limiting errors are thrown back to the user", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { // Using 8083 because we need querier to call the test express server instead of the core @@ -159,7 +155,7 @@ describe(`Querier rate limiting: ${printPath("[test/ratelimiting.test.js]")}`, ( }); it("Test that parallel calls have independent retry counters", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { // Using 8083 because we need querier to call the test express server instead of the core diff --git a/test/recipeModuleManager.test.js b/test/recipeModuleManager.test.js index 79e813d025..e8b8cb2e74 100644 --- a/test/recipeModuleManager.test.js +++ b/test/recipeModuleManager.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, resetAll } = require("./utils"); +const { printPath, createCoreApplication, resetAll } = require("./utils"); let { ProcessState } = require("../lib/build/processState"); let ST = require("../"); let Session = require("../recipe/session"); @@ -38,19 +38,12 @@ let { middleware, errorHandler } = require("../framework/express"); describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); resetTestRecipies(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("calling init multiple times", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { @@ -86,7 +79,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j // Check that querier has been inited when we call supertokens.init // Failure condition: initalizing supertoknes before the the first try catch will fail the test it("test that querier has been initiated when we call supertokens.init", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); try { await Querier.getNewInstanceOrThrowError(undefined); @@ -115,7 +108,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j // Check that modules have been inited when we call supertokens.init // Failure condition: initalizing supertoknes before the the first try catch will fail the test it("test that modules have been initiated when we call supertokens.init", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); try { SessionRecipe.getInstanceOrThrowError(); @@ -165,7 +158,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j //Failure condition: Tests will fail is using the incorrect base path it("test various inputs to routing with default base path", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { connectionURI, @@ -246,7 +239,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j //Failure condition: Tests will fail is using the wrong base path it("test various inputs to routing when base path is /", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); { ST.init({ supertokens: { @@ -333,7 +326,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j //Failure condition: Tests will fail if the incorrect rid header value is set when sending a request the path it("test routing with multiple recipes", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { @@ -398,7 +391,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j // Test various inputs to errorHandler (if it accepts or not) it("test various inputs to errorHandler", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { @@ -456,7 +449,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j // Error thrown from APIs implemented by recipes must not go unhandled it("test that error thrown from APIs implemented by recipes must not go unhandled", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { @@ -514,7 +507,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j // Disable a default route, and then implement your own API and check that that gets called // Failure condition: in testRecipe1 if the disabled value for the /default-route-disabled is set to false, the test will fail it("test if you diable a default route, and then implement your own API, your own api is called", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { @@ -555,7 +548,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j // If an error handler in a recipe throws an error, that error next to go to the user's error handler it("test if the error handler in a recipe throws an error, it goes to the user's error handler", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { @@ -598,7 +591,7 @@ describe(`recipeModuleManagerTest: ${printPath("[test/recipeModuleManager.test.j // Test getAllCORSHeaders it("test the getAllCORSHeaders function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); ST.init({ supertokens: { diff --git a/test/session.test.js b/test/session.test.js index 2573b72876..20d85dbb5e 100644 --- a/test/session.test.js +++ b/test/session.test.js @@ -14,13 +14,11 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, - setKeyValueInConfig, - killAllSTCoresOnly, + mockResponse, mockRequest, } = require("./utils"); @@ -50,19 +48,12 @@ const { default: RecipeUserId } = require("../lib/build/recipeUserId"); describe(`session: ${printPath("[test/session.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // check if output headers and set cookies for create session is fine it("test that output headers and set cookie for create session is fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -117,7 +108,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { // check if output headers and set cookies for refresh session is fine it("test that output headers and set cookie for refresh session is fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -186,7 +177,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that session tokens are cleared if refresh token api is called without the refresh token but with access token", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -246,7 +237,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that custom cookie format does nto throw an error during cookie parsing", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -304,7 +295,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that session tokens are cleared if refresh token api is called without the refresh token but with an expired access token", async function () { - const connectionURI = await startST({ coreConfig: { access_token_validity: 1 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 1 } }); SuperTokens.init({ supertokens: { connectionURI, @@ -367,7 +358,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that access and refresh token for olderCookieDomain is cleared if multiple tokens are passed to the refresh endpoint", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -418,7 +409,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that refresh endpoint throws a 500 if multiple tokens are passed and olderCookieDomain is undefined", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -461,7 +452,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that verifySession returns 401 if multiple tokens are passed in the request", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -530,7 +521,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test verifySession returns 200 in header based auth even if multiple tokens are present in the cookie", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -597,7 +588,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that refresh endpoint refreshes the token in header based auth even if multiple tokens are present in the cookie", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -664,7 +655,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { // check if input cookies are missing, an appropriate error is thrown // Failure condition: if valid cookies are set in the refresh call the test will fail it("test that if input cookies are missing, an appropriate error is thrown", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -718,7 +709,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { // check if input cookies are there, no error is thrown // Failure condition: if cookies are no set in the refresh call the test will fail it("test that if input cookies are there, no error is thrown", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -772,7 +763,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //- check for token theft detection it("token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -832,7 +823,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("token theft detection with API key", async function () { - const connectionURI = await startST({ coreConfig: { api_keys: "shfo3h98308hOIHoei309saiho" } }); + const connectionURI = await createCoreApplication({ coreConfig: { api_keys: "shfo3h98308hOIHoei309saiho" } }); SuperTokens.init({ supertokens: { connectionURI, @@ -893,7 +884,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("query without API key", async function () { - const connectionURI = await startST({ coreConfig: { api_keys: "shfo3h98308hOIHoei309saiho" } }); + const connectionURI = await createCoreApplication({ coreConfig: { api_keys: "shfo3h98308hOIHoei309saiho" } }); SuperTokens.init({ supertokens: { connectionURI, @@ -921,7 +912,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //check basic usage of session it("test basic usage of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1019,7 +1010,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //check session verify for with / without anti-csrf present it("test session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1071,7 +1062,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //check session verify for with / without anti-csrf present** it("test session verify without anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1131,7 +1122,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //check revoking session(s) it("test revoking of sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1236,7 +1227,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //check manipulating session data it("test manipulating session data", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1270,7 +1261,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test manipulating session data with new get session function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1310,7 +1301,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test null and undefined values passed for session data", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1365,7 +1356,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test null and undefined values passed for session data with new get session method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1424,7 +1415,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //check manipulating jwt payload it("test manipulating jwt payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1459,7 +1450,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test manipulating jwt payload with new get session method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1500,7 +1491,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test null and undefined values passed for jwt payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1555,7 +1546,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test null and undefined values passed for jwt payload with new get session method", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1614,7 +1605,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { //if anti-csrf is disabled from ST core, check that not having that in input to verify session is fine** it("test that when anti-csrf is disabled from ST core not having that in input to verify session is fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1667,7 +1658,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that anti-csrf disabled and sameSite none does not throw an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -1685,7 +1676,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that anti-csrf disabled and sameSite lax does now throw an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1705,7 +1696,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that anti-csrf disabled and sameSite strict does now throw an error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1725,7 +1716,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that custom user id is returned correctly", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1764,7 +1755,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that get session by session handle payload is correct", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1807,7 +1798,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("test that revoked session throws error when calling get session by session handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1854,7 +1845,7 @@ describe(`session: ${printPath("[test/session.test.js]")}`, function () { }); it("should use override functions in sessioncontainer methods", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/session/accessTokenVersions.test.js b/test/session/accessTokenVersions.test.js index 66fee7c619..1d452d714a 100644 --- a/test/session/accessTokenVersions.test.js +++ b/test/session/accessTokenVersions.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse, resetAll } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse, resetAll } = require("../utils"); const assert = require("assert"); const { Querier } = require("../../lib/build/querier"); const express = require("express"); @@ -30,19 +30,12 @@ const { validateAccessTokenStructure } = require("../../lib/build/recipe/session describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("createNewSession", () => { it("should create a V5 token", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -84,7 +77,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should create a V5 token signed by a static key if set in session recipe config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -130,7 +123,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should ignore protected props", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -176,7 +169,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should ignore protected props when creating from prev payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -256,7 +249,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should make sign in/up return a 500 when adding protected props", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -321,7 +314,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t describe("mergeIntoAccessTokenPayload", () => { it("should help migrating a v2 token using protected props", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -422,7 +415,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should help migrating a v2 token using protected props when called using session handle", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -491,7 +484,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t describe("verifySession", () => { it("should validate v2 tokens", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -550,7 +543,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should validate v2 tokens with check database enabled", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -639,7 +632,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should validate v4 tokens", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -707,7 +700,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should validate v4 tokens with check database enabled", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -806,7 +799,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should validate v5 tokens with check database enabled", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -888,7 +881,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should not validate token signed by a static key if not set in session recipe config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -962,7 +955,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t describe("refresh session", () => { it("should refresh legacy sessions to new version", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1017,7 +1010,7 @@ describe(`AccessToken versions: ${printPath("[test/session/accessTokenVersions.t }); it("should throw when refreshing legacy session with protected prop in payload", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/session/claims/createNewSession.test.js b/test/session/claims/createNewSession.test.js index b4b0f2604e..29c8ec75f8 100644 --- a/test/session/claims/createNewSession.test.js +++ b/test/session/claims/createNewSession.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, mockResponse, mockRequest } = require("../../utils"); +const { printPath, createCoreApplication, mockResponse, mockRequest } = require("../../utils"); const assert = require("assert"); const { ProcessState } = require("../../../lib/build/processState"); const SuperTokens = require("../../.."); @@ -21,19 +21,12 @@ const { TrueClaim, UndefinedClaim } = require("./testClaims"); describe(`sessionClaims/createNewSession: ${printPath("[test/session/claims/createNewSession.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("createNewSession", () => { it("should create access token payload w/ session claims", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -80,7 +73,7 @@ describe(`sessionClaims/createNewSession: ${printPath("[test/session/claims/crea }); it("should create access token payload wo/ session claims with an undefined value", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -125,7 +118,7 @@ describe(`sessionClaims/createNewSession: ${printPath("[test/session/claims/crea }); it("should merge claims and the passed access token payload obj", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const payloadParam = { initial: true }; const custom2 = { undef: undefined, nullProp: null, inner: "asdf" }; const customClaims = { diff --git a/test/session/claims/fetchAndSetClaim.test.js b/test/session/claims/fetchAndSetClaim.test.js index 9ac87867d8..f18dd55184 100644 --- a/test/session/claims/fetchAndSetClaim.test.js +++ b/test/session/claims/fetchAndSetClaim.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, startST, killAllST, setupST, cleanST, mockResponse, mockRequest } = require("../../utils"); +const { printPath, createCoreApplication, mockResponse, mockRequest } = require("../../utils"); const assert = require("assert"); const { default: SessionClass } = require("../../../lib/build/recipe/session/sessionClass"); const sinon = require("sinon"); @@ -23,16 +23,9 @@ const { ProcessState } = require("../../../lib/build/processState"); describe(`sessionClaims/fetchAndSetClaim: ${printPath("[test/session/claims/fetchAndSetClaim.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("SessionClass.fetchAndSetClaim", () => { afterEach(() => { sinon.restore(); @@ -64,7 +57,7 @@ describe(`sessionClaims/fetchAndSetClaim: ${printPath("[test/session/claims/fetc }); it("should update using a handle if claim fetchValue returns a value", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { diff --git a/test/session/claims/getClaimValue.test.js b/test/session/claims/getClaimValue.test.js index ac097f2ea0..32683c2d3a 100644 --- a/test/session/claims/getClaimValue.test.js +++ b/test/session/claims/getClaimValue.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, startST, killAllST, setupST, cleanST, mockResponse, mockRequest } = require("../../utils"); +const { printPath, createCoreApplication, mockResponse, mockRequest } = require("../../utils"); const assert = require("assert"); const SuperTokens = require("../../.."); const Session = require("../../../recipe/session"); @@ -22,23 +22,16 @@ const { ProcessState } = require("../../../lib/build/processState"); describe(`sessionClaims/getClaimValue: ${printPath("[test/session/claims/getClaimValue.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("SessionClass.getClaimValue", () => { afterEach(() => { sinon.restore(); }); it("should get the right value", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -81,7 +74,7 @@ describe(`sessionClaims/getClaimValue: ${printPath("[test/session/claims/getClai }); it("should get the right value using session handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -127,7 +120,7 @@ describe(`sessionClaims/getClaimValue: ${printPath("[test/session/claims/getClai }); it("should work for not existing handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { diff --git a/test/session/claims/removeClaim.test.js b/test/session/claims/removeClaim.test.js index 583d27c50f..1271f9aa0d 100644 --- a/test/session/claims/removeClaim.test.js +++ b/test/session/claims/removeClaim.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, startST, killAllST, setupST, cleanST, mockResponse, mockRequest } = require("../../utils"); +const { printPath, createCoreApplication, mockResponse, mockRequest } = require("../../utils"); const assert = require("assert"); const SuperTokens = require("../../.."); const Session = require("../../../recipe/session"); @@ -23,16 +23,9 @@ const { ProcessState } = require("../../../lib/build/processState"); describe(`sessionClaims/removeClaim: ${printPath("[test/session/claims/removeClaim.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("SessionClass.removeClaim", () => { afterEach(() => { sinon.restore(); @@ -49,7 +42,7 @@ describe(`sessionClaims/removeClaim: ${printPath("[test/session/claims/removeCla }); it("should clear previously set claim", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -100,7 +93,7 @@ describe(`sessionClaims/removeClaim: ${printPath("[test/session/claims/removeCla }); it("should clear previously set claim using a handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -153,7 +146,7 @@ describe(`sessionClaims/removeClaim: ${printPath("[test/session/claims/removeCla }); it("should work ok for not existing handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { diff --git a/test/session/claims/setClaimValue.test.js b/test/session/claims/setClaimValue.test.js index 01e96d29d9..bfa15b9b1e 100644 --- a/test/session/claims/setClaimValue.test.js +++ b/test/session/claims/setClaimValue.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, startST, killAllST, setupST, cleanST, mockResponse, mockRequest } = require("../../utils"); +const { printPath, createCoreApplication, mockResponse, mockRequest } = require("../../utils"); const assert = require("assert"); const SuperTokens = require("../../.."); const Session = require("../../../recipe/session"); @@ -23,16 +23,9 @@ const { ProcessState } = require("../../../lib/build/processState"); describe(`sessionClaims/setClaimValue: ${printPath("[test/session/claims/setClaimValue.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("SessionClass.setClaimValue", () => { afterEach(() => { sinon.restore(); @@ -56,7 +49,7 @@ describe(`sessionClaims/setClaimValue: ${printPath("[test/session/claims/setClai }); it("should overwrite claim value", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -110,7 +103,7 @@ describe(`sessionClaims/setClaimValue: ${printPath("[test/session/claims/setClai }); it("should overwrite claim value using session handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -165,7 +158,7 @@ describe(`sessionClaims/setClaimValue: ${printPath("[test/session/claims/setClai }); it("should work ok for not existing handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { diff --git a/test/session/claims/validateClaimsForSessionHandle.test.js b/test/session/claims/validateClaimsForSessionHandle.test.js index c9d8d343aa..54cfafc694 100644 --- a/test/session/claims/validateClaimsForSessionHandle.test.js +++ b/test/session/claims/validateClaimsForSessionHandle.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, startST, killAllST, setupST, cleanST, mockResponse, mockRequest } = require("../../utils"); +const { printPath, createCoreApplication, mockResponse, mockRequest } = require("../../utils"); const assert = require("assert"); const SuperTokens = require("../../.."); const Session = require("../../../recipe/session"); @@ -24,23 +24,16 @@ describe(`sessionClaims/validateClaimsForSessionHandle: ${printPath( "[test/session/claims/validateClaimsForSessionHandle.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("Session.validateClaimsForSessionHandle", () => { afterEach(() => { sinon.restore(); }); it("should return the right validation errors", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -101,7 +94,7 @@ describe(`sessionClaims/validateClaimsForSessionHandle: ${printPath( }); it("should work for not existing handle", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { diff --git a/test/session/claims/verifySession.test.js b/test/session/claims/verifySession.test.js index 7f044a6ae8..1726a77e93 100644 --- a/test/session/claims/verifySession.test.js +++ b/test/session/claims/verifySession.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../../utils"); const assert = require("assert"); const { ProcessState } = require("../../../lib/build/processState"); const SuperTokens = require("../../../"); @@ -30,8 +30,6 @@ const { default: RecipeUserId } = require("../../../lib/build/recipeUserId"); describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifySession.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); @@ -39,15 +37,10 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS sinon.restore(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("verifySession", () => { describe("with getGlobalClaimValidators override", () => { it("should allow without claims required or present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -67,7 +60,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }); it("should allow with claim valid after refetching", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -101,7 +94,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }); it("should reject with claim required but not added", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -145,7 +138,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }); it("should allow with custom validator returning true", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const customValidator = { id: "testid", validate: () => ({ isValid: true }), @@ -183,7 +176,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }); it("should reject with custom validator returning false", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const customValidator = { id: "testid", validate: () => ({ isValid: false }), @@ -223,7 +216,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }); it("should reject with validator returning false with reason", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const customValidator = { id: "testid", validate: () => ({ isValid: false, reason: "testReason" }), @@ -288,7 +281,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }, ], }); - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -343,7 +336,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS .resolves({ invalidClaims: [], }); - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -379,7 +372,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS describe("with overrideGlobalClaimValidators", () => { it("should allow with empty list as override", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -418,7 +411,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }); it("should allow with refetched claim", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -457,7 +450,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS }); it("should reject with invalid refetched claim", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -504,7 +497,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS validate: () => ({ isValid: false, reason: "testReason" }), }; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -553,7 +546,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS validate: () => ({ isValid: true }), }; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -601,7 +594,7 @@ describe(`sessionClaims/verifySession: ${printPath("[test/session/claims/verifyS validate: () => ({ isValid: false, reason: "testReason" }), }; - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -677,6 +670,7 @@ function testGet(app, info, url, expectedStatus) { .get(url) .set("Cookie", ["sAccessToken=" + info.accessToken]) .set("anti-csrf", info.antiCsrf) + .timeout(10000) .expect(expectedStatus) .end((err, res) => { if (err) { diff --git a/test/session/errorHandlers.test.js b/test/session/errorHandlers.test.js index 361c4ff627..186a881aad 100644 --- a/test/session/errorHandlers.test.js +++ b/test/session/errorHandlers.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let assert = require("assert"); const express = require("express"); const request = require("supertest"); @@ -24,18 +24,11 @@ const { default: SessionError } = require("../../lib/build/recipe/session/error" describe(`errorHandlers: ${printPath("[test/errorHandlers.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("should override session errorHandlers", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/session/exposeAccessTokenToFrontendInCookieBasedAuth.test.js b/test/session/exposeAccessTokenToFrontendInCookieBasedAuth.test.js index ab2ad0ebb3..9fa9b9c6e2 100644 --- a/test/session/exposeAccessTokenToFrontendInCookieBasedAuth.test.js +++ b/test/session/exposeAccessTokenToFrontendInCookieBasedAuth.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); const assert = require("assert"); const express = require("express"); const request = require("supertest"); @@ -28,16 +28,9 @@ describe(`exposeAccessTokenToFrontendInCookieBasedAuth: ${printPath( "[test/session/exposeAccessTokenToFrontendInCookieBasedAuth.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("should default to false", () => { SuperTokens.init({ supertokens: { @@ -65,7 +58,7 @@ function getTestCases(exposeAccessTokenToFrontendInCookieBasedAuth) { const sessionConfig = { exposeAccessTokenToFrontendInCookieBasedAuth, getTokenTransferMethod: () => "cookie" }; describe("createNewSession", () => { it("should attach the appropriate tokens", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -98,7 +91,7 @@ function getTestCases(exposeAccessTokenToFrontendInCookieBasedAuth) { describe("mergeIntoAccessTokenPayload", () => { it("should attach the appropriate tokens", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -156,7 +149,7 @@ function getTestCases(exposeAccessTokenToFrontendInCookieBasedAuth) { describe("verifySession", () => { it("should attach the appropriate tokens after refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -218,7 +211,7 @@ function getTestCases(exposeAccessTokenToFrontendInCookieBasedAuth) { describe("refresh session", () => { it("should attach the appropriate tokens", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/session/jwksCache.test.js b/test/session/jwksCache.test.js index e86c53e37c..6433ee6fea 100644 --- a/test/session/jwksCache.test.js +++ b/test/session/jwksCache.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, setKeyValueInConfig, resetAll } = require("../utils"); +const { printPath, createCoreApplication, resetAll } = require("../utils"); const assert = require("assert"); const SuperTokens = require("../.."); const Session = require("../../recipe/session"); @@ -23,9 +23,6 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct let requestMock; let clock; beforeEach(async function () { - await killAllST(); - await setupST(); - requestMock.reset(); requestMock.callThrough(); if (clock) { @@ -39,14 +36,12 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct after(async function () { requestMock.restore(); - await killAllST(); - await cleanST(); }); it("should fetch the keys as expected", async () => { clock = sinon.useFakeTimers({ shouldAdvanceTime: true, now: Date.now() }); - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -77,7 +72,7 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct it("should not re-fetch if the cache is available", async () => { clock = sinon.useFakeTimers({ shouldAdvanceTime: true, now: Date.now() }); - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -106,7 +101,7 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct }); it("should re-fetch keys for unknown kid", async () => { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { access_token_dynamic_signing_key_update_interval: "0.001" }, }); // 5 seconds is the update interval SuperTokens.init({ @@ -152,7 +147,7 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct }); it("should throw if jwks endpoint errors", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -189,7 +184,7 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct it("should re-fetch after the cache expires", async () => { clock = sinon.useFakeTimers({ shouldAdvanceTime: true, now: Date.now() }); - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -233,7 +228,7 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct }); it("jwks multiple cores work ok", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI: `${connectionURI};http://localhost:8081`, @@ -261,7 +256,7 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct }); it("jwks endpoint throwing should fall back to next core if fetching throws", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { // We are using two valid core values here, but make it throw below @@ -293,7 +288,7 @@ describe(`JWKs caching: ${printPath("[test/session/jwksCache.test.js]")}`, funct }); it("jwks endpoint throwing should fall back to next core if fetching returns the wrong status/shape", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/session/sessionHandlingFuncsWithoutReq.test.js b/test/session/sessionHandlingFuncsWithoutReq.test.js index b09d0f2230..88fff2b268 100644 --- a/test/session/sessionHandlingFuncsWithoutReq.test.js +++ b/test/session/sessionHandlingFuncsWithoutReq.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse } = require("../utils"); const assert = require("assert"); const SuperTokens = require("../.."); const Session = require("../../recipe/session"); @@ -23,19 +23,9 @@ let { Querier } = require("../../lib/build/querier"); describe(`Session handling functions without modifying response: ${printPath( "[test/session/sessionHandlingFuncsWithoutReq.test.js]" )}`, function () { - beforeEach(async function () { - await killAllST(); - await setupST(); - }); - - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("createNewSessionWithoutRequestResponse", () => { it("should create a new session", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -68,7 +58,7 @@ describe(`Session handling functions without modifying response: ${printPath( }); it("should create a new session w/ anti-csrf", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -106,7 +96,7 @@ describe(`Session handling functions without modifying response: ${printPath( describe("getSessionWithoutRequestResponse", () => { it("should validate basic access token", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -138,7 +128,7 @@ describe(`Session handling functions without modifying response: ${printPath( }); it("should validate basic access token with anti-csrf", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -192,7 +182,7 @@ describe(`Session handling functions without modifying response: ${printPath( }); it("should validate access tokens created by createJWT", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -227,7 +217,7 @@ describe(`Session handling functions without modifying response: ${printPath( }); it("should validate access tokens created by createJWT w/ checkDatabase", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -322,7 +312,7 @@ describe(`Session handling functions without modifying response: ${printPath( }); it("should return error for claim validation failures", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -358,7 +348,7 @@ describe(`Session handling functions without modifying response: ${printPath( describe("refreshSessionWithoutRequestResponse", () => { it("should refresh session", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -397,7 +387,7 @@ describe(`Session handling functions without modifying response: ${printPath( }); it("should work with anti-csrf", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -449,7 +439,7 @@ describe(`Session handling functions without modifying response: ${printPath( }); it("should return error for non-tokens", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/session/useDynamicSigningKeySwitching.test.js b/test/session/useDynamicSigningKeySwitching.test.js index 34fd6ab6d4..b99d05c8ae 100644 --- a/test/session/useDynamicSigningKeySwitching.test.js +++ b/test/session/useDynamicSigningKeySwitching.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, extractInfoFromResponse, resetAll } = require("../utils"); +const { printPath, createCoreApplication, extractInfoFromResponse, resetAll } = require("../utils"); const assert = require("assert"); const SuperTokens = require("../.."); const Session = require("../../recipe/session"); @@ -24,19 +24,9 @@ const { parseJWTWithoutSignatureVerification } = require("../../lib/build/recipe describe(`Switching useDynamicAccessTokenSigningKey after session creation: ${printPath( "[test/session/sessionHandlingFuncsWithoutReq.test.js]" )}`, function () { - beforeEach(async function () { - await killAllST(); - await setupST(); - }); - - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("true to false", () => { it("should throw when verifying", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -93,7 +83,7 @@ describe(`Switching useDynamicAccessTokenSigningKey after session creation: ${pr }); it("should work after refresh", async () => { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/sessionAccessTokenSigningKeyUpdate.test.js b/test/sessionAccessTokenSigningKeyUpdate.test.js index f237fbc673..9b5cc5c3fa 100644 --- a/test/sessionAccessTokenSigningKeyUpdate.test.js +++ b/test/sessionAccessTokenSigningKeyUpdate.test.js @@ -12,16 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { - printPath, - setupST, - startST, - killAllST, - cleanST, - setKeyValueInConfig, - killAllSTCoresOnly, - mockRequest, -} = require("./utils"); +const { printPath, createCoreApplication } = require("./utils"); let assert = require("assert"); let { Querier } = require("../lib/build/querier"); let { ProcessState, PROCESS_STATE } = require("../lib/build/processState"); @@ -49,8 +40,6 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( )}`, function () { let requestMock; beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); requestMock.reset(); requestMock.callThrough(); @@ -62,12 +51,10 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( after(async function () { requestMock.restore(); - await killAllST(); - await cleanST(); }); it("check that if signing key changes, things are still fine", async function () { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { access_token_dynamic_signing_key_update_interval: "0.001" }, }); // 5 seconds is the update interval SuperTokens.init({ @@ -214,7 +201,7 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( }); it("check that if signing key changes, after new key is fetched - via token query, old tokens don't query the core", async function () { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { access_token_dynamic_signing_key_update_interval: "0.001" }, }); // 5 seconds is the update interval SuperTokens.init({ @@ -305,7 +292,7 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( }); it("check that if signing key changes, after new key is fetched - via creation of new token, old tokens don't query the core", async function () { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { access_token_dynamic_signing_key_update_interval: "0.001" }, }); // 5 seconds is the update interval SuperTokens.init({ @@ -393,7 +380,7 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( }); it("check that if signing key changes, after new key is fetched - via verification of old token, old tokens don't query the core", async function () { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { access_token_dynamic_signing_key_update_interval: "0.001" }, }); // 5 seconds is the update interval SuperTokens.init({ @@ -483,10 +470,9 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( assert.strictEqual(requestMock.callCount, 1); }); - it("test reducing access token signing key update interval time", async function () { - const appId = "testapp-" + Date.now(); - const connectionURI = await startST({ - appId, + // skipping this test because it requires killing the core and starting it again, which is not supported anymore + it.skip("test reducing access token signing key update interval time", async function () { + const connectionURI = await createCoreApplication({ coreConfig: { access_token_dynamic_signing_key_update_interval: "0.0041", // 10 seconds }, @@ -531,17 +517,16 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( assert(verifyState3 === undefined); } - // we kill the core - await killAllSTCoresOnly(); - await setupST(); + // // we kill the core + // await killAllSTCoresOnly(); - // start server again - await startST({ - appId, - coreConfig: { - access_token_dynamic_signing_key_update_interval: "0.0041", // 10 seconds - }, - }); + // // start server again + // await createCoreApplication({ + // appId, + // coreConfig: { + // access_token_dynamic_signing_key_update_interval: "0.0041", // 10 seconds + // }, + // }); { await SessionFunctions.getSession( @@ -648,7 +633,7 @@ describe(`sessionAccessTokenSigningKeyUpdate: ${printPath( }); it("no access token signing key update", async function () { - const connectionURI = await startST({ + const connectionURI = await createCoreApplication({ coreConfig: { access_token_signing_key_dynamic: "false", access_token_dynamic_signing_key_update_interval: "0.0011", // 4 seconds diff --git a/test/sessionExpress.test.js b/test/sessionExpress.test.js index a931dd2cfa..8ae486531f 100644 --- a/test/sessionExpress.test.js +++ b/test/sessionExpress.test.js @@ -14,12 +14,11 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, - setKeyValueInConfig, + delay, } = require("./utils"); let assert = require("assert"); @@ -36,19 +35,12 @@ let { middleware, errorHandler } = require("../framework/express"); describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // check if disabling api, the default refresh API does not work - you get a 404 it("test that if disabling api, the default refresh API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -115,7 +107,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test that if disabling api, the default sign out API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -181,7 +173,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //- check for token theft detection it("express token theft detection", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -296,7 +288,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //- check for token theft detection it("express token theft detection with auto refresh middleware", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -391,7 +383,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //check basic usage of session it("test basic usage of express sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -540,7 +532,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test basic usage of express sessions with headers", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -698,7 +690,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test that if accessTokenPath is set to custom /access, then path of accessToken from session is equal to this", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -746,7 +738,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test that if default accessTokenPath is used, then path of accessToken from session is equal to slash", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -793,7 +785,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test signout API works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -850,7 +842,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test signout API works if even session is deleted on the backend after creation", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -920,7 +912,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //check basic usage of session it("test basic usage of express sessions with auto refresh", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -1072,7 +1064,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //check session verify for with / without anti-csrf present it("test express session verify with anti-csrf present", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1149,7 +1141,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi // check session verify for with / without anti-csrf present it("test session verify without anti-csrf present express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1231,7 +1223,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //check revoking session(s)** it("test revoking express sessions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1369,7 +1361,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //check manipulating session data it("test manipulating session data with express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1515,7 +1507,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //check manipulating jwt payload it("test manipulating jwt payload with express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1729,7 +1721,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi // test with existing header params being there and that the lib appends to those and not overrides those it("test that express appends to existing header params and does not override", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1775,7 +1767,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi //if anti-csrf is disabled from ST core, check that not having that in input to verify session is fine** it("test that when anti-csrf is disabled from from ST core, not having to input in verify session is fine in express", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1848,7 +1840,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test that getSession does not clear cookies if a session does not exist in the first place", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1898,7 +1890,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test that refreshSession does not clear cookies if a session does not exist in the first place", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -1948,7 +1940,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test that when anti-csrf is enabled with custom header, and we don't provide that in verifySession, we get try refresh token", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -2092,7 +2084,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test resfresh API when using CUSTOM HEADER anti-csrf", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -2167,7 +2159,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test that init can be called post route and middleware declaration", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const app = express(); @@ -2250,7 +2242,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test overriding of sessions functions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let createNewSessionCalled = false; let getSessionCalled = false; @@ -2446,7 +2438,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test overriding of sessions apis", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let signoutCalled = false; SuperTokens.init({ @@ -2536,7 +2528,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test overriding of sessions functions, error thrown", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let createNewSessionCalled = false; let session = undefined; @@ -2614,7 +2606,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test overriding of sessions apis, error thrown", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let signoutCalled = false; SuperTokens.init({ @@ -2709,7 +2701,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("check that refresh doesn't clear cookies if missing anti csrf via custom header", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -2767,7 +2759,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("check that refresh doesn't clear cookies if missing anti csrf via token", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { connectionURI, @@ -2824,7 +2816,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test session error handler overriding", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let testpass = false; SuperTokens.init({ supertokens: { @@ -2891,7 +2883,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test revoking a session during refresh with revokeSession function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -2981,7 +2973,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test revoking a session during refresh with revokeSession function and sending 401", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -3073,7 +3065,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test revoking a session during refresh with throwing unauthorised error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -3167,7 +3159,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("test revoking a session during refresh fails if just sending 401", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { @@ -3253,7 +3245,7 @@ describe(`sessionExpress: ${printPath("[test/sessionExpress.test.js]")}`, functi }); it("Test that token transfer method works correctly when using origin function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); SuperTokens.init({ supertokens: { diff --git a/test/thirdparty/authorisationUrlFeature.test.js b/test/thirdparty/authorisationUrlFeature.test.js index 0476770a9f..7aaee5c95d 100644 --- a/test/thirdparty/authorisationUrlFeature.test.js +++ b/test/thirdparty/authorisationUrlFeature.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let Multitenancy = require("../../lib/build/recipe/multitenancy"); let assert = require("assert"); @@ -60,18 +60,11 @@ describe(`authorisationTest: ${printPath("[test/thirdparty/authorisationFeature. }; }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test that using development OAuth keys will use the development authorisation url", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); // testing with the google OAuth development key STExpress.init({ @@ -133,7 +126,7 @@ describe(`authorisationTest: ${printPath("[test/thirdparty/authorisationFeature. }); it("test calling authorisation url API with empty init", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); // testing with the google OAuth development key STExpress.init({ @@ -179,7 +172,7 @@ describe(`authorisationTest: ${printPath("[test/thirdparty/authorisationFeature. }); it("test calling authorisation url API with empty init with dynamic third party provider", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); // testing with the google OAuth development key STExpress.init({ @@ -248,7 +241,7 @@ describe(`authorisationTest: ${printPath("[test/thirdparty/authorisationFeature. }); it("test minimum config for thirdparty module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -296,7 +289,7 @@ describe(`authorisationTest: ${printPath("[test/thirdparty/authorisationFeature. }); it("test thirdparty provider doesn't exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -338,7 +331,7 @@ describe(`authorisationTest: ${printPath("[test/thirdparty/authorisationFeature. }); it("test invalid GET params for thirdparty module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/thirdparty/config.test.js b/test/thirdparty/config.test.js index 6ff3dc8050..16c5c9d169 100644 --- a/test/thirdparty/config.test.js +++ b/test/thirdparty/config.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, resetAll } = require("../utils"); +const { printPath, createCoreApplication, resetAll } = require("../utils"); let STExpress = require("../../"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -26,18 +26,11 @@ let { middleware, errorHandler } = require("../../framework/express"); */ describe(`configTest: ${printPath("[test/thirdparty/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test config for thirdparty module, no provider passed", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); try { STExpress.init({ supertokens: { @@ -63,7 +56,7 @@ describe(`configTest: ${printPath("[test/thirdparty/config.test.js]")}`, functio }); it("test minimum config for thirdparty module, custom provider", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/thirdparty/emailverify.test.js b/test/thirdparty/emailverify.test.js index 11cedecbfb..c72f280bbf 100644 --- a/test/thirdparty/emailverify.test.js +++ b/test/thirdparty/emailverify.test.js @@ -15,10 +15,9 @@ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + signInUPCustomRequest, extractInfoFromResponse, emailVerifyTokenRequest, @@ -64,18 +63,11 @@ describe(`emailverify: ${printPath("[test/thirdparty/emailverify.test.js]")}`, f }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test default backward compatibility api being called: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -149,7 +141,7 @@ describe(`emailverify: ${printPath("[test/thirdparty/emailverify.test.js]")}`, f }); it("test default backward compatibility api being called, error message not sent back to user: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -224,7 +216,7 @@ describe(`emailverify: ${printPath("[test/thirdparty/emailverify.test.js]")}`, f }); it("test custom override: email verify", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let email = undefined; let emailVerifyURL = undefined; let type = undefined; @@ -312,7 +304,7 @@ describe(`emailverify: ${printPath("[test/thirdparty/emailverify.test.js]")}`, f }); it("test that providing your own email callback and make sure it is called", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let userInfo = null; let emailToken = null; diff --git a/test/thirdparty/multitenancy.test.js b/test/thirdparty/multitenancy.test.js index 82bf9790c2..3085d4c355 100644 --- a/test/thirdparty/multitenancy.test.js +++ b/test/thirdparty/multitenancy.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy } = require("../utils"); let SuperTokens = require("../../"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -21,20 +21,13 @@ let Multitenancy = require("../../recipe/multitenancy"); describe(`multitenancy: ${printPath("[test/thirdparty/multitenancy.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // test config for emailpassword module // Failure condition: passing custom data or data of invalid type/ syntax to the module it("test recipe functions", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -101,7 +94,7 @@ describe(`multitenancy: ${printPath("[test/thirdparty/multitenancy.test.js]")}`, }); it("test getProvider", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -165,7 +158,7 @@ describe(`multitenancy: ${printPath("[test/thirdparty/multitenancy.test.js]")}`, }); it("test getProvider merges the config from static and core 1", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, @@ -207,7 +200,7 @@ describe(`multitenancy: ${printPath("[test/thirdparty/multitenancy.test.js]")}`, }); it("test getProvider returns correct config from core", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/thirdparty/oidc.test.js b/test/thirdparty/oidc.test.js index 0ad5f45f91..15c6554807 100644 --- a/test/thirdparty/oidc.test.js +++ b/test/thirdparty/oidc.test.js @@ -13,7 +13,7 @@ * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy } = require("../utils"); let STExpress = require("../../"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -23,18 +23,12 @@ let ThirdParty = require("../../lib/build/recipe/thirdparty"); describe(`oidcTest: ${printPath("[test/thirdparty/oidc.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); it("should use code challenge method S256 if supported by the provider", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -86,7 +80,7 @@ describe(`oidcTest: ${printPath("[test/thirdparty/oidc.test.js]")}`, function () }); it("should not use pkce if oidc response does not support S256", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -131,7 +125,7 @@ describe(`oidcTest: ${printPath("[test/thirdparty/oidc.test.js]")}`, function () }); it("should use pkce if oidc response does not support S256 but forcePKCE is true", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { diff --git a/test/thirdparty/override.test.js b/test/thirdparty/override.test.js index 28746ff152..9baa759c70 100644 --- a/test/thirdparty/override.test.js +++ b/test/thirdparty/override.test.js @@ -14,11 +14,9 @@ */ const { printPath, - setupST, - startST, - stopST, - killAllST, - cleanST, + + createCoreApplication, + resetAll, signUPRequest, assertJSONEquals, @@ -71,18 +69,11 @@ describe(`overrideTest: ${printPath("[test/thirdparty/override.test.js]")}`, fun }; }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("overriding functions tests", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let newUser = undefined; STExpress.init({ @@ -249,7 +240,7 @@ describe(`overrideTest: ${printPath("[test/thirdparty/override.test.js]")}`, fun }); it("overriding api tests", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let newUser = undefined; STExpress.init({ @@ -361,7 +352,7 @@ describe(`overrideTest: ${printPath("[test/thirdparty/override.test.js]")}`, fun }); it("overriding functions tests, throws error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; STExpress.init({ supertokens: { @@ -511,7 +502,7 @@ describe(`overrideTest: ${printPath("[test/thirdparty/override.test.js]")}`, fun }); it("overriding api tests, throws error", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let user = undefined; let newUser = undefined; let emailExists = undefined; diff --git a/test/thirdparty/provider.config.test.js b/test/thirdparty/provider.config.test.js index 1fb9320b3d..f072b83384 100644 --- a/test/thirdparty/provider.config.test.js +++ b/test/thirdparty/provider.config.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST, removeAppAndTenants } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy, removeAppAndTenants } = require("../utils"); let STExpress = require("../../"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -29,18 +29,11 @@ const { configsForVerification, providers } = require("./tpConfigsForVerificatio describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test the provider override is not increasing call stack", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); let stackCount = []; @@ -92,7 +85,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test the config is same within override and provider instance", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); let oIConfig; STExpress.init({ @@ -139,7 +132,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test the config is same within override and provider instance when overriding getConfigForClientType", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); let oIConfig; STExpress.init({ @@ -193,7 +186,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test built-in provider computed config from static config", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -224,7 +217,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test built-in provider computed config from core config", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -253,7 +246,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test clientType matching when only one clientType is provided from static", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -286,7 +279,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test clientType matching when there are more than one clientType from static", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -326,7 +319,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test clientType matching when there is one clientType from core", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -351,7 +344,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test clientType matching when there are more than one clientType from core", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -383,7 +376,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test clientType matching when there are same clientTypes from static and core", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -431,7 +424,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test clientType matching when there are different clientTypes from static and core", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { @@ -473,24 +466,11 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test }); it("test getProvider and signInUp on an app and tenant", async function () { - const connectionURI = await startSTWithMultitenancy({ noApp: true }); - - await removeAppAndTenants("a1"); - - // Create app - await fetch(`http://localhost:8080/recipe/multitenancy/app/v2`, { - method: "PUT", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - appId: "a1", - }), - }); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { - connectionURI: "http://localhost:8080/appid-a1", + connectionURI, }, appInfo: { apiDomain: "api.supertokens.io", diff --git a/test/thirdparty/provider.config_from_core.test.js b/test/thirdparty/provider.config_from_core.test.js index 7e82aaee10..d7ac6c0af9 100644 --- a/test/thirdparty/provider.config_from_core.test.js +++ b/test/thirdparty/provider.config_from_core.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST, removeAppAndTenants } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy, removeAppAndTenants } = require("../utils"); let STExpress = require("../.."); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -29,16 +29,9 @@ const { configsForVerification, providers } = require("./tpConfigsForVerificatio describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("test built-in provider computed config from core config with overrides", async function () { const overrides = [ { @@ -105,7 +98,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test it(`should work for ${provider.config.thirdPartyId} with override ${JSON.stringify( overrideVal.input )}`, async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { diff --git a/test/thirdparty/provider.config_from_static.test.js b/test/thirdparty/provider.config_from_static.test.js index 84afb6dfdc..e22feaaae3 100644 --- a/test/thirdparty/provider.config_from_static.test.js +++ b/test/thirdparty/provider.config_from_static.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST, removeAppAndTenants } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy, removeAppAndTenants } = require("../utils"); let STExpress = require("../.."); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -29,16 +29,9 @@ const { configsForVerification, providers } = require("./tpConfigsForVerificatio describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("test built-in provider computed config from static config with overrides", async function () { const overrides = [ { @@ -105,7 +98,7 @@ describe(`providerConfigTest: ${printPath("[test/thirdparty/provider.config.test it(`should work for ${provider.config.thirdPartyId} with override ${JSON.stringify( overrideVal.input )}`, async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); STExpress.init({ supertokens: { diff --git a/test/thirdparty/provider.test.js b/test/thirdparty/provider.test.js index 83aabb0845..c0d872b529 100644 --- a/test/thirdparty/provider.test.js +++ b/test/thirdparty/provider.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -50,18 +50,11 @@ const privateKey = */ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test minimum config for third party provider google", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -161,7 +154,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test passing additional params, check they are present in authorisation url for thirdparty provider google", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -241,7 +234,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test passing scopes in config for thirdparty provider google", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -316,7 +309,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test minimum config for third party provider facebook", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let clientSecret = "test-secret"; @@ -411,7 +404,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test passing scopes in config for third party provider facebook", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let clientSecret = "test-secret"; @@ -481,7 +474,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test minimum config for third party provider github", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let clientSecret = "test-secret"; @@ -576,7 +569,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test additional params, check they are present in authorisation url for third party provider github", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let clientSecret = "test-secret"; @@ -651,7 +644,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test passing scopes in config for third party provider github", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let clientSecret = "test-secret"; @@ -721,7 +714,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test minimum config for third party provider apple", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let additionalConfig = { @@ -823,7 +816,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test passing additional params, check they are present in authorisation url for third party provider apple", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let additionalConfig = { @@ -903,7 +896,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test passing scopes in config for third party provider apple", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let additionalConfig = { @@ -978,7 +971,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it.skip("test passing invalid privateKey in config for third party provider apple", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let clientId = "test"; let additionalConfig = { @@ -1026,7 +1019,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("test duplicate provider", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); try { STExpress.init({ supertokens: { @@ -1078,7 +1071,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("Test that sign in up fails if validateAccessToken throws", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1156,7 +1149,7 @@ describe(`providerTest: ${printPath("[test/thirdparty/provider.test.js]")}`, fun }); it("Test that sign in up works if validateAccessToken does not throw", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let overridenValidateCalled = false; STExpress.init({ supertokens: { diff --git a/test/thirdparty/recipeFunctions.test.js b/test/thirdparty/recipeFunctions.test.js index fbcc5b8ba6..3c077cc836 100644 --- a/test/thirdparty/recipeFunctions.test.js +++ b/test/thirdparty/recipeFunctions.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, setKeyValueInConfig } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); let assert = require("assert"); @@ -24,19 +24,12 @@ let ThirdParty = require("../../recipe/thirdparty"); describe(`recipeFunctions: ${printPath("[test/thirdparty/recipeFunctions.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // test that creating a user with ThirdParty, and they have a verified email that, isEmailVerified returns true and the opposite case it("for ThirdParty user that isEmailVerified returns the correct email verification status", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/thirdparty/signinupFeature.test.js b/test/thirdparty/signinupFeature.test.js index 586c08738f..ead1c8e7a6 100644 --- a/test/thirdparty/signinupFeature.test.js +++ b/test/thirdparty/signinupFeature.test.js @@ -14,10 +14,9 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, signUPRequest, isCDIVersionCompatible, @@ -150,18 +149,11 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }; }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test with rid thirdpartypasswordless still works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -270,7 +262,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test with rid thirdpartyemailpassword still works", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -376,7 +368,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test that disable api, the default signinup API does not work", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -445,7 +437,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test minimum config without code for thirdparty module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -548,7 +540,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test missing redirectURIInfo and oAuthTokens", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -592,7 +584,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test minimum config for thirdparty module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -713,7 +705,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test minimum config for thirdparty module, email unverified", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -792,7 +784,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test thirdparty provider doesn't exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -843,7 +835,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test email not returned in getProfileInfo function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -896,7 +888,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test error thrown from getProfileInfo function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -955,7 +947,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test invalid POST params for thirdparty module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1076,7 +1068,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test handlePostSignUpIn gets set correctly", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); process.env.userId = ""; process.env.loginType = ""; @@ -1124,7 +1116,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") app.use(errorHandler()); - nock("https://test.com").post("/oauth/token").times(2).reply(200, {}); + nock("https://test.com").post("/oauth/token").times(1).reply(200, {}); let response1 = await request(app) .post("/auth/signinup") @@ -1143,7 +1135,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test minimum config with one provider", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -1209,7 +1201,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test getUserCount and pagination works fine", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1283,7 +1275,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("getUserById when user does not exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -1349,7 +1341,7 @@ describe(`signinupTest: ${printPath("[test/thirdparty/signinupFeature.test.js]") }); it("test getUserByThirdPartyInfo when user does not exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/thirdparty/signoutFeature.test.js b/test/thirdparty/signoutFeature.test.js index a1f20d9a38..c3ea0548d8 100644 --- a/test/thirdparty/signoutFeature.test.js +++ b/test/thirdparty/signoutFeature.test.js @@ -14,12 +14,10 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, - setKeyValueInConfig, } = require("../utils"); let STExpress = require("../../"); let assert = require("assert"); @@ -57,18 +55,11 @@ describe(`signoutTest: ${printPath("[test/thirdparty/signoutFeature.test.js]")}` }; }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test the default route and it should revoke the session", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -149,7 +140,7 @@ describe(`signoutTest: ${printPath("[test/thirdparty/signoutFeature.test.js]")}` }); it("test that disabling default route and calling the API returns 404", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -202,7 +193,7 @@ describe(`signoutTest: ${printPath("[test/thirdparty/signoutFeature.test.js]")}` }); it("test that calling the API without a session should return 401", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -246,7 +237,7 @@ describe(`signoutTest: ${printPath("[test/thirdparty/signoutFeature.test.js]")}` }); it("test that signout API reutrns try refresh token, refresh session and signout should return OK", async function () { - const connectionURI = await startST({ coreConfig: { access_token_validity: 2 } }); + const connectionURI = await createCoreApplication({ coreConfig: { access_token_validity: 2 } }); STExpress.init({ supertokens: { diff --git a/test/thirdparty/users.test.js b/test/thirdparty/users.test.js index 3735d69026..b7bf4154e4 100644 --- a/test/thirdparty/users.test.js +++ b/test/thirdparty/users.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, signInUPCustomRequest } = require("../utils"); +const { printPath, createCoreApplication, signInUPCustomRequest } = require("../utils"); const { getUserCount, getUsersNewestFirst, getUsersOldestFirst } = require("../../lib/build/"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -48,18 +48,11 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function }); beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test getUsersOldestFirst", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -86,11 +79,18 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function app.use(errorHandler()); - await signInUPCustomRequest(app, "test@gmail.com", "testPass0"); - await signInUPCustomRequest(app, "test1@gmail.com", "testPass1"); - await signInUPCustomRequest(app, "test2@gmail.com", "testPass2"); - await signInUPCustomRequest(app, "test3@gmail.com", "testPass3"); - await signInUPCustomRequest(app, "test4@gmail.com", "testPass4"); + const randomValue = Math.random(); + + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signInUPCustomRequest(app, email, `testPass-${randomValue}` + i); + } let users = await getUsersOldestFirst({ tenantId: "public" }); assert.strictEqual(users.users.length, 5); @@ -98,12 +98,12 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function users = await getUsersOldestFirst({ tenantId: "public", limit: 1 }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[0]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersOldestFirst({ tenantId: "public", limit: 1, paginationToken: users.nextPaginationToken }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test1@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[1]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersOldestFirst({ tenantId: "public", limit: 5, paginationToken: users.nextPaginationToken }); @@ -130,7 +130,7 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function }); it("test getUsersNewestFirst", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -157,11 +157,18 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function app.use(errorHandler()); - await signInUPCustomRequest(app, "test@gmail.com", "testPass0"); - await signInUPCustomRequest(app, "test1@gmail.com", "testPass1"); - await signInUPCustomRequest(app, "test2@gmail.com", "testPass2"); - await signInUPCustomRequest(app, "test3@gmail.com", "testPass3"); - await signInUPCustomRequest(app, "test4@gmail.com", "testPass4"); + const randomValue = Math.random(); + + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signInUPCustomRequest(app, email, `testPass-${randomValue}` + i); + } let users = await getUsersNewestFirst({ tenantId: "public" }); assert.strictEqual(users.users.length, 5); @@ -169,12 +176,12 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function users = await getUsersNewestFirst({ tenantId: "public", limit: 1 }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test4@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[emails.length - 1]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersNewestFirst({ tenantId: "public", limit: 1, paginationToken: users.nextPaginationToken }); assert.strictEqual(users.users.length, 1); - assert.strictEqual(users.users[0].emails[0], "test3@gmail.com"); + assert.strictEqual(users.users[0].emails[0], emails[emails.length - 2]); assert.strictEqual(typeof users.nextPaginationToken, "string"); users = await getUsersNewestFirst({ tenantId: "public", limit: 5, paginationToken: users.nextPaginationToken }); @@ -182,7 +189,7 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function assert.strictEqual(users.nextPaginationToken, undefined); try { - await getUsersOldestFirst({ tenantId: "public", limit: 10, paginationToken: "invalid-pagination-token" }); + await getUsersNewestFirst({ tenantId: "public", limit: 10, paginationToken: "invalid-pagination-token" }); assert(false); } catch (err) { if (!err.message.includes("invalid pagination token")) { @@ -191,7 +198,7 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function } try { - await getUsersOldestFirst({ tenantId: "public", limit: -1 }); + await getUsersNewestFirst({ tenantId: "public", limit: -1 }); assert(false); } catch (err) { if (!err.message.includes("limit must a positive integer with min value 1")) { @@ -201,7 +208,7 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function }); it("test getUserCount", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -231,14 +238,21 @@ describe(`usersTest: ${printPath("[test/thirdparty/users.test.js]")}`, function app.use(errorHandler()); - await signInUPCustomRequest(app, "test@gmail.com", "testPass0"); + const randomValue = Math.random(); + + await signInUPCustomRequest(app, Math.random() + "@gmail.com", `testPass-${randomValue}-4`); userCount = await getUserCount(); assert.strictEqual(userCount, 1); - await signInUPCustomRequest(app, "test1@gmail.com", "testPass1"); - await signInUPCustomRequest(app, "test2@gmail.com", "testPass2"); - await signInUPCustomRequest(app, "test3@gmail.com", "testPass3"); - await signInUPCustomRequest(app, "test4@gmail.com", "testPass4"); + const emails = [ + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + Math.random() + "@gmail.com", + ]; + for await (const [i, email] of emails.entries()) { + await signInUPCustomRequest(app, email, `testPass-${randomValue}-${i}`); + } userCount = await getUserCount(); assert.strictEqual(userCount, 5); diff --git a/test/totp/recipeFunctions.test.js b/test/totp/recipeFunctions.test.js index e895a5e0d4..5833f3e31b 100644 --- a/test/totp/recipeFunctions.test.js +++ b/test/totp/recipeFunctions.test.js @@ -13,7 +13,7 @@ * under the License. */ -const { printPath, setupST, startST, killAllST, cleanST, setKeyValueInConfig } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let Session = require("../../recipe/session"); let MultiFactorAuth = require("../../recipe/multifactorauth"); @@ -27,18 +27,11 @@ const OTPAuth = require("otpauth"); describe(`recipeFunctions: ${printPath("[test/totp/recipeFunctions.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test create device", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -62,7 +55,7 @@ describe(`recipeFunctions: ${printPath("[test/totp/recipeFunctions.test.js]")}`, }); it("test update device", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -94,7 +87,7 @@ describe(`recipeFunctions: ${printPath("[test/totp/recipeFunctions.test.js]")}`, }); it("test remove device", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -125,7 +118,7 @@ describe(`recipeFunctions: ${printPath("[test/totp/recipeFunctions.test.js]")}`, }); it("test verify device", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -163,7 +156,7 @@ describe(`recipeFunctions: ${printPath("[test/totp/recipeFunctions.test.js]")}`, }); it("test verify totp", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -213,7 +206,7 @@ describe(`recipeFunctions: ${printPath("[test/totp/recipeFunctions.test.js]")}`, }); it("test invalid totp", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userContext.test.js b/test/userContext.test.js index c5b0d69a1b..7e8675c085 100644 --- a/test/userContext.test.js +++ b/test/userContext.test.js @@ -14,12 +14,10 @@ */ const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + extractInfoFromResponse, - setKeyValueInConfig, } = require("./utils"); let assert = require("assert"); const express = require("express"); @@ -40,18 +38,11 @@ const { fail } = require("assert"); describe(`userContext: ${printPath("[test/userContext.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("testing context across interface and recipe function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let works = false; let signUpContextWorks = false; STExpress.init({ @@ -188,7 +179,7 @@ describe(`userContext: ${printPath("[test/userContext.test.js]")}`, function () }); it("testing default context across interface and recipe function", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let signInContextWorks = false; let signInAPIContextWorks = false; let createNewSessionContextWorks = false; @@ -291,7 +282,7 @@ describe(`userContext: ${printPath("[test/userContext.test.js]")}`, function () }); it("Test that SuperTokens.getRequestFromUserContext works as expected", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); let signInContextWorks = false; let signInAPIContextWorks = false; let createNewSessionContextWorks = false; diff --git a/test/useridmapping/createUserIdMapping.test.js b/test/useridmapping/createUserIdMapping.test.js index b8ef1c4c4f..160d237517 100644 --- a/test/useridmapping/createUserIdMapping.test.js +++ b/test/useridmapping/createUserIdMapping.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const EmailPasswordRecipe = require("../../lib/build/recipe/emailpassword").default; @@ -11,19 +11,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`createUserIdMappingTest: ${printPath("[test/useridmapping/createUserIdMapping.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("createUserIdMappingTest", () => { it("create a userId mapping", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -74,7 +67,7 @@ describe(`createUserIdMappingTest: ${printPath("[test/useridmapping/createUserId }); it("create a userId mapping with an unknown superTokensUserId", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -106,7 +99,7 @@ describe(`createUserIdMappingTest: ${printPath("[test/useridmapping/createUserId }); it("create a userId mapping when a mapping already exists", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -188,7 +181,7 @@ describe(`createUserIdMappingTest: ${printPath("[test/useridmapping/createUserId }); it("create a userId mapping when userId already has usermetadata with and without force", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/useridmapping/deleteUserIdMapping.test.js b/test/useridmapping/deleteUserIdMapping.test.js index 7e7220c048..0e1ae84d83 100644 --- a/test/useridmapping/deleteUserIdMapping.test.js +++ b/test/useridmapping/deleteUserIdMapping.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const EmailPasswordRecipe = require("../../lib/build/recipe/emailpassword").default; @@ -11,19 +11,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`deleteUserIdMappingTest: ${printPath("[test/useridmapping/deleteUserIdMapping.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("deleteUserIdMapping:", () => { it("delete an unknown userId mapping", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -67,7 +60,7 @@ describe(`deleteUserIdMappingTest: ${printPath("[test/useridmapping/deleteUserId }); it("delete a userId mapping with userIdType as SUPERTOKENS", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -121,7 +114,7 @@ describe(`deleteUserIdMappingTest: ${printPath("[test/useridmapping/deleteUserId }); it("delete a userId mapping with userIdType as EXTERNAL", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -175,7 +168,7 @@ describe(`deleteUserIdMappingTest: ${printPath("[test/useridmapping/deleteUserId }); it("delete a userId mapping with userIdType as ANY", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -256,7 +249,7 @@ describe(`deleteUserIdMappingTest: ${printPath("[test/useridmapping/deleteUserId }); it("delete a userId mapping when userMetadata exists with externalId with and without force", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/useridmapping/getUserIdMapping.test.js b/test/useridmapping/getUserIdMapping.test.js index f4c47754df..c036f74abd 100644 --- a/test/useridmapping/getUserIdMapping.test.js +++ b/test/useridmapping/getUserIdMapping.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const EmailPasswordRecipe = require("../../lib/build/recipe/emailpassword").default; @@ -10,19 +10,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`getUserIdMappingTest: ${printPath("[test/useridmapping/getUserIdMapping.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getUserIdMappingTest", () => { it("get userId mapping", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -115,7 +108,7 @@ describe(`getUserIdMappingTest: ${printPath("[test/useridmapping/getUserIdMappin }); it("get userId mapping when mapping does not exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -165,7 +158,7 @@ describe(`getUserIdMappingTest: ${printPath("[test/useridmapping/getUserIdMappin }); it("get userId mapping when externalUserIdInfo does not exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/useridmapping/recipeTests/emailpassword.test.js b/test/useridmapping/recipeTests/emailpassword.test.js index 28e7740d98..87c4f75ba5 100644 --- a/test/useridmapping/recipeTests/emailpassword.test.js +++ b/test/useridmapping/recipeTests/emailpassword.test.js @@ -1,5 +1,5 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../../utils"); +const { printPath, createCoreApplication } = require("../../utils"); const { ProcessState } = require("../../../lib/build/processState"); const STExpress = require("../../.."); const EmailPasswordRecipe = require("../../../lib/build/recipe/emailpassword").default; @@ -11,19 +11,12 @@ describe(`userIdMapping with emailpassword: ${printPath( "[test/useridmapping/recipeTests/emailpassword.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getUserById", () => { it("create an emailPassword user and map their userId, retrieve the user info using getUserById and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -86,7 +79,7 @@ describe(`userIdMapping with emailpassword: ${printPath( describe("getUserByEmail", () => { it("create an emailPassword user and map their userId, retrieve the user info using getUserByEmail and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -141,7 +134,7 @@ describe(`userIdMapping with emailpassword: ${printPath( describe("signIn", () => { it("create an emailPassword user and map their userId, signIn, check that the userRetrieved has the mapped userId", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -193,7 +186,7 @@ describe(`userIdMapping with emailpassword: ${printPath( describe("password reset", () => { it("create an emailPassword user and map their userId, and do a password reset using the external id, check that it gets reset", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -266,7 +259,7 @@ describe(`userIdMapping with emailpassword: ${printPath( describe("update email and password", () => { it("create an emailPassword user and map their userId, update their email and password using the externalId", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/useridmapping/recipeTests/passwordless.test.js b/test/useridmapping/recipeTests/passwordless.test.js index d29b0c52fb..4ac74439b4 100644 --- a/test/useridmapping/recipeTests/passwordless.test.js +++ b/test/useridmapping/recipeTests/passwordless.test.js @@ -1,5 +1,5 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../../utils"); +const { printPath, createCoreApplication } = require("../../utils"); const { ProcessState } = require("../../../lib/build/processState"); const STExpress = require("../../.."); const PasswordlessRecipe = require("../../../lib/build/recipe/passwordless").default; @@ -11,19 +11,12 @@ describe(`userIdMapping with passwordless: ${printPath( "[test/useridmapping/recipeTests/passwordless.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("consumeCode", () => { it("create a passwordless user and map their userId, signIn again and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -108,7 +101,7 @@ describe(`userIdMapping with passwordless: ${printPath( describe("getUserById", () => { it("create a passwordless user and map their userId, call getUserById and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -179,7 +172,7 @@ describe(`userIdMapping with passwordless: ${printPath( describe("getUserByEmail", () => { it("create a passwordless user and map their userId, call getUserByEmail and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -252,7 +245,7 @@ describe(`userIdMapping with passwordless: ${printPath( describe("getUserByPhoneNumber", () => { it("create a passwordless user and map their userId, call getUserByPhoneNumber and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -325,7 +318,7 @@ describe(`userIdMapping with passwordless: ${printPath( describe("updateUser", () => { it("create a passwordless user and map their userId, call updateUser to add their email and retrieve the user to see if the changes are reflected", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/useridmapping/recipeTests/supertokens.test.js b/test/useridmapping/recipeTests/supertokens.test.js index 2b6425893e..60253d2d83 100644 --- a/test/useridmapping/recipeTests/supertokens.test.js +++ b/test/useridmapping/recipeTests/supertokens.test.js @@ -1,5 +1,5 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../../utils"); +const { printPath, createCoreApplication } = require("../../utils"); const { ProcessState } = require("../../../lib/build/processState"); const STExpress = require("../../.."); const EmailPasswordRecipe = require("../../../lib/build/recipe/emailpassword").default; @@ -12,19 +12,12 @@ describe(`userIdMapping with supertokens recipe: ${printPath( "[test/useridmapping/recipeTests/supertokens.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("deleteUser", () => { it("create an emailPassword user and map their userId, then delete user with the externalId", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -108,7 +101,7 @@ describe(`userIdMapping with supertokens recipe: ${printPath( describe("getUsers", () => { it("create multiple users and map one of the users userId, retrieve all users and check that response will contain the externalId for the mapped user", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/useridmapping/recipeTests/thirdparty.test.js b/test/useridmapping/recipeTests/thirdparty.test.js index 2dc22f6d04..dd764a82e3 100644 --- a/test/useridmapping/recipeTests/thirdparty.test.js +++ b/test/useridmapping/recipeTests/thirdparty.test.js @@ -1,5 +1,5 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../../utils"); +const { printPath, createCoreApplication } = require("../../utils"); const { ProcessState } = require("../../../lib/build/processState"); const STExpress = require("../../.."); const ThirdPartyRecipe = require("../../../lib/build/recipe/thirdparty").default; @@ -11,19 +11,12 @@ describe(`userIdMapping with thirdparty: ${printPath( "[test/useridmapping/recipeTests/thirdparty.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("signInUp", () => { it("create a thirdParty user and map their userId, signIn and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -97,7 +90,7 @@ describe(`userIdMapping with thirdparty: ${printPath( describe("getUserById", () => { it("create a thirdParty user and map their userId, retrieve the user info using getUserById and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -164,7 +157,7 @@ describe(`userIdMapping with thirdparty: ${printPath( describe("getUsersByEmail", () => { it("create a thirdParty user and map their userId, retrieve the user info using getUsersByEmail and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -231,7 +224,7 @@ describe(`userIdMapping with thirdparty: ${printPath( describe("getUserByThirdPartyInfo", () => { it("create a thirdParty user and map their userId, retrieve the user info using getUserByThirdPartyInfo and check that the externalId is returned", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/useridmapping/updateOrDeleteUserIdMappingInfo.test.js b/test/useridmapping/updateOrDeleteUserIdMappingInfo.test.js index 6f14f3f2b2..9bd7a5a94c 100644 --- a/test/useridmapping/updateOrDeleteUserIdMappingInfo.test.js +++ b/test/useridmapping/updateOrDeleteUserIdMappingInfo.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const EmailPasswordRecipe = require("../../lib/build/recipe/emailpassword").default; @@ -12,19 +12,12 @@ describe(`updateOrDeleteUserIdMappingInfoTest: ${printPath( "[test/useridmapping/updateOrDeleteUserIdMappingInfo.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("updateOrDeleteUserIdMappingInfoTest", () => { it("update externalUserId mapping info with unknown userId", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -79,7 +72,7 @@ describe(`updateOrDeleteUserIdMappingInfoTest: ${printPath( }); it("update externalUserId mapping info with userIdType as SUPERTOKENS and EXTERNAL", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -182,7 +175,7 @@ describe(`updateOrDeleteUserIdMappingInfoTest: ${printPath( }); it("update externalUserId mapping info with userIdType as ANY", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/usermetadata/clearUserMetadata.test.js b/test/usermetadata/clearUserMetadata.test.js index c277d022fd..f20b5ee48d 100644 --- a/test/usermetadata/clearUserMetadata.test.js +++ b/test/usermetadata/clearUserMetadata.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserMetadataRecipe = require("../../lib/build/recipe/usermetadata").default; @@ -9,19 +9,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`clearUserMetadataTest: ${printPath("[test/usermetadata/clearUserMetadata.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("clearUserMetadata", () => { it("should return OK for unknown user id", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; @@ -50,7 +43,7 @@ describe(`clearUserMetadataTest: ${printPath("[test/usermetadata/clearUserMetada }); it("should clear stored userId", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testMetadata = { diff --git a/test/usermetadata/config.test.js b/test/usermetadata/config.test.js index 875694e0c0..ceb873b34c 100644 --- a/test/usermetadata/config.test.js +++ b/test/usermetadata/config.test.js @@ -1,4 +1,4 @@ -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); const { ProcessState } = require("../../lib/build/processState"); const STExpress = require("../.."); const UserMetadataRecipe = require("../../lib/build/recipe/usermetadata/recipe").default; @@ -7,19 +7,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`configTest: ${printPath("[test/usermetadata/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("recipe init", () => { it("should work fine without config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/usermetadata/getUserMetadata.test.js b/test/usermetadata/getUserMetadata.test.js index dccda8a79e..8c6258c229 100644 --- a/test/usermetadata/getUserMetadata.test.js +++ b/test/usermetadata/getUserMetadata.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); const STExpress = require("../../"); const { ProcessState } = require("../../lib/build/processState"); const UserMetadataRecipe = require("../../lib/build/recipe/usermetadata").default; @@ -9,19 +9,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`getUserMetadataTest: ${printPath("[test/usermetadata/getUserMetadata.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getUserMetadata", () => { it("should return an empty object for unknown userIds", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; @@ -51,7 +44,7 @@ describe(`getUserMetadataTest: ${printPath("[test/usermetadata/getUserMetadata.t }); it("should return an object if it's created.", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testMetadata = { diff --git a/test/usermetadata/override.test.js b/test/usermetadata/override.test.js index e856ed2431..9ecbe70407 100644 --- a/test/usermetadata/override.test.js +++ b/test/usermetadata/override.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); const STExpress = require("../../"); const { ProcessState } = require("../../lib/build/processState"); const UserMetadataRecipe = require("../../lib/build/recipe/usermetadata").default; @@ -9,19 +9,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`overrideTest: ${printPath("[test/usermetadata/override.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("recipe functions", () => { it("should work without an override config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testUserContext = { hello: ":)" }; @@ -58,7 +51,7 @@ describe(`overrideTest: ${printPath("[test/usermetadata/override.test.js]")}`, f }); it("should call user provided overrides", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testUserContext = { hello: ":)" }; diff --git a/test/usermetadata/updateUserMetadata.test.js b/test/usermetadata/updateUserMetadata.test.js index c83fe7b0da..e724d3ee9e 100644 --- a/test/usermetadata/updateUserMetadata.test.js +++ b/test/usermetadata/updateUserMetadata.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserMetadataRecipe = require("../../lib/build/recipe/usermetadata").default; @@ -9,19 +9,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`updateUserMetadataTest: ${printPath("[test/usermetadata/updateUserMetadata.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("updateUserMetadata", () => { it("should create metadata for unknown user id", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testMetadata = { @@ -58,7 +51,7 @@ describe(`updateUserMetadataTest: ${printPath("[test/usermetadata/updateUserMeta }); it("should create metadata with utf8 encoding", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testMetadata = { @@ -95,7 +88,7 @@ describe(`updateUserMetadataTest: ${printPath("[test/usermetadata/updateUserMeta }); it("should create metadata for cleared user id", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testMetadata = { @@ -135,7 +128,7 @@ describe(`updateUserMetadataTest: ${printPath("[test/usermetadata/updateUserMeta }); it("should update metadata by shallow merge", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const testUserId = "userId"; const testMetadata = { diff --git a/test/userroles/addRoleToUser.test.js b/test/userroles/addRoleToUser.test.js index e50629799b..6e83c3ac31 100644 --- a/test/userroles/addRoleToUser.test.js +++ b/test/userroles/addRoleToUser.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -10,19 +10,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`addRoleToUserTest: ${printPath("[test/userroles/addRoleToUser.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("addRoleToUserTest", () => { it("add a role to a user", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -70,7 +63,7 @@ describe(`addRoleToUserTest: ${printPath("[test/userroles/addRoleToUser.test.js] }); it("add duplicate role to the user", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -125,7 +118,7 @@ describe(`addRoleToUserTest: ${printPath("[test/userroles/addRoleToUser.test.js] }); it("add unknown role to the user", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userroles/claims.test.js b/test/userroles/claims.test.js index 1b8f9b8e20..45d1bb15bc 100644 --- a/test/userroles/claims.test.js +++ b/test/userroles/claims.test.js @@ -1,13 +1,11 @@ const assert = require("assert"); const { printPath, - setupST, - startST, - killAllST, - cleanST, + + createCoreApplication, + mockResponse, mockRequest, - setKeyValueInConfig, } = require("../utils"); const { ProcessState } = require("../../lib/build/processState"); const STExpress = require("../.."); @@ -18,19 +16,12 @@ const { maxVersion } = require("../../lib/build/utils"); describe(`claimsTest: ${printPath("[test/userroles/claims.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("recipe init", () => { it("should add claims to session without config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -61,7 +52,7 @@ describe(`claimsTest: ${printPath("[test/userroles/claims.test.js]")}`, function }); it("should not add claims if disabled in config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -98,7 +89,7 @@ describe(`claimsTest: ${printPath("[test/userroles/claims.test.js]")}`, function }); it("should add claims to session with values", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -133,7 +124,7 @@ describe(`claimsTest: ${printPath("[test/userroles/claims.test.js]")}`, function describe("validation", () => { it("should validate roles", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -181,7 +172,7 @@ describe(`claimsTest: ${printPath("[test/userroles/claims.test.js]")}`, function }); }); it("should validate roles after refetching", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -218,7 +209,7 @@ describe(`claimsTest: ${printPath("[test/userroles/claims.test.js]")}`, function await session.assertClaims([UserRoles.UserRoleClaim.validators.includes("test")]); }); it("should validate permissions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -266,7 +257,7 @@ describe(`claimsTest: ${printPath("[test/userroles/claims.test.js]")}`, function }); }); it("should validate permissions after refetching", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/userroles/config.test.js b/test/userroles/config.test.js index db4cb5406b..a6701ca972 100644 --- a/test/userroles/config.test.js +++ b/test/userroles/config.test.js @@ -1,4 +1,4 @@ -const { printPath, setupST, startST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); const { ProcessState } = require("../../lib/build/processState"); const STExpress = require("../.."); const UserRolesRecipe = require("../../lib/build/recipe/userroles/recipe").default; @@ -8,19 +8,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`configTest: ${printPath("[test/userroles/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("recipe init", () => { it("should work fine without config", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, diff --git a/test/userroles/createNewRoleOrAddPermissions.test.js b/test/userroles/createNewRoleOrAddPermissions.test.js index 5b28ae4a26..43a4a59b7e 100644 --- a/test/userroles/createNewRoleOrAddPermissions.test.js +++ b/test/userroles/createNewRoleOrAddPermissions.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -12,19 +12,12 @@ describe(`createNewRoleOrAddPermissionsTest: ${printPath( "[test/userroles/createNewRoleOrAddPermissions.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("createNewRoleOrAddPermissions", () => { it("create a new role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -51,7 +44,7 @@ describe(`createNewRoleOrAddPermissionsTest: ${printPath( }); it("create the same role twice", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const role = "role"; @@ -88,7 +81,7 @@ describe(`createNewRoleOrAddPermissionsTest: ${printPath( }); it("create a role with permissions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const role = "role"; const permissions = ["permission1"]; @@ -127,7 +120,7 @@ describe(`createNewRoleOrAddPermissionsTest: ${printPath( }); it("add new permissions to a role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const role = "role"; const permissions = ["permission1"]; @@ -179,7 +172,7 @@ describe(`createNewRoleOrAddPermissionsTest: ${printPath( }); it("add duplicate permission", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); const role = "role"; const permissions = ["permission1"]; diff --git a/test/userroles/deleteRole.test.js b/test/userroles/deleteRole.test.js index 341a16f8de..dc500eee62 100644 --- a/test/userroles/deleteRole.test.js +++ b/test/userroles/deleteRole.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -10,19 +10,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`deleteRole: ${printPath("[test/userroles/deleteRole.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("deleteRole", () => { it("create roles, add them to a user and delete one of the roles", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -78,7 +71,7 @@ describe(`deleteRole: ${printPath("[test/userroles/deleteRole.test.js]")}`, func }); it("delete a role that does not exist", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userroles/getPermissionsForRole.test.js b/test/userroles/getPermissionsForRole.test.js index 6efb2df657..2b959176ff 100644 --- a/test/userroles/getPermissionsForRole.test.js +++ b/test/userroles/getPermissionsForRole.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -10,19 +10,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`getPermissionsForRole: ${printPath("[test/userroles/getPermissionsForRole.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getPermissionsForRole", () => { it("get permissions for a role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -61,7 +54,7 @@ describe(`getPermissionsForRole: ${printPath("[test/userroles/getPermissionsForR }); it("get permissions for an unknown role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userroles/getRolesForUser.test.js b/test/userroles/getRolesForUser.test.js index d172da7b81..1c455780fd 100644 --- a/test/userroles/getRolesForUser.test.js +++ b/test/userroles/getRolesForUser.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -10,19 +10,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`getRolesForUser: ${printPath("[test/userroles/getRolesForUser.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getRolesForUser", () => { it("create roles, add them to a user check that the user has the roles", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userroles/getRolesThatHavePermissions.test.js b/test/userroles/getRolesThatHavePermissions.test.js index 87c69ccee7..89d5cc6ef4 100644 --- a/test/userroles/getRolesThatHavePermissions.test.js +++ b/test/userroles/getRolesThatHavePermissions.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -12,19 +12,12 @@ describe(`getRolesThatHavePermissions: ${printPath( "[test/userroles/getRolesThatHavePermissions.test.js]" )}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getRolesThatHavePermissions", () => { it("get roles that have permissions", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -66,7 +59,7 @@ describe(`getRolesThatHavePermissions: ${printPath( }); it("get roles for unknown permission", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userroles/getUsersThatHaveRole.test.js b/test/userroles/getUsersThatHaveRole.test.js index 5a411e02de..e6f5aeb352 100644 --- a/test/userroles/getUsersThatHaveRole.test.js +++ b/test/userroles/getUsersThatHaveRole.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -10,19 +10,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`getUsersThatHaveRole: ${printPath("[test/userroles/getUsersThatHaveRole.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getUsersThatHaveRole", () => { it("get users for a role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -67,7 +60,7 @@ describe(`getUsersThatHaveRole: ${printPath("[test/userroles/getUsersThatHaveRol }); it("get users for an unknown role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userroles/multitenantRole.test.js b/test/userroles/multitenantRole.test.js index 2dbc483ec6..8bed5d696a 100644 --- a/test/userroles/multitenantRole.test.js +++ b/test/userroles/multitenantRole.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplicationWithMultitenancy } = require("../utils"); let assert = require("assert"); const express = require("express"); const request = require("supertest"); @@ -27,18 +27,11 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`multitenant role: ${printPath("[test/userroles/multitenantRole.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - it("test that different roles can be assigned for the same user for each tenant", async function () { - const connectionURI = await startSTWithMultitenancy(); + const connectionURI = await createCoreApplicationWithMultitenancy(); SuperTokens.init({ supertokens: { connectionURI, diff --git a/test/userroles/removePermissionsFromRole.test.js b/test/userroles/removePermissionsFromRole.test.js index 467a3a7b78..4a815ac370 100644 --- a/test/userroles/removePermissionsFromRole.test.js +++ b/test/userroles/removePermissionsFromRole.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -10,19 +10,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`getPermissionsForRole: ${printPath("[test/userroles/getPermissionsForRole.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("getPermissionsForRole", () => { it("remove permissions from a role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -69,7 +62,7 @@ describe(`getPermissionsForRole: ${printPath("[test/userroles/getPermissionsForR }); it("remove permissions from an unknown role", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/userroles/removeUserRole.test.js b/test/userroles/removeUserRole.test.js index 5548bfa0d7..3da97ee307 100644 --- a/test/userroles/removeUserRole.test.js +++ b/test/userroles/removeUserRole.test.js @@ -1,6 +1,6 @@ const assert = require("assert"); -const { printPath, setupST, startST, killAllST, cleanST, areArraysEqual } = require("../utils"); +const { printPath, createCoreApplication, areArraysEqual } = require("../utils"); const STExpress = require("../.."); const { ProcessState } = require("../../lib/build/processState"); const UserRolesRecipe = require("../../lib/build/recipe/userroles").default; @@ -10,19 +10,12 @@ const { default: SessionRecipe } = require("../../lib/build/recipe/session/recip describe(`removeUserRoleTest: ${printPath("[test/userroles/removeUserRole.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - describe("removeUserRole", () => { it("remove role from user", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -84,7 +77,7 @@ describe(`removeUserRoleTest: ${printPath("[test/userroles/removeUserRole.test.j }); it("remove a role the user does not have", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { @@ -124,7 +117,7 @@ describe(`removeUserRoleTest: ${printPath("[test/userroles/removeUserRole.test.j }); it("remove an unknown role from the user", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { diff --git a/test/utils.js b/test/utils.js index 8a655acbdf..c9f18e0e37 100644 --- a/test/utils.js +++ b/test/utils.js @@ -40,6 +40,8 @@ const { default: OpenIDRecipe } = require("../lib/build/recipe/openid/recipe"); const { wrapRequest } = require("../framework/express"); const { join } = require("path"); let debug = require("debug"); +const { randomUUID } = require("node:crypto"); +const setCookieParser = require("set-cookie-parser"); const users = require("./users.json"); let assert = require("assert"); @@ -51,40 +53,6 @@ module.exports.printPath = function (path) { ])}`; }; -module.exports.executeCommand = async function (cmd) { - return new Promise((resolve, reject) => { - exec(cmd, (err, stdout, stderr) => { - if (err) { - reject(err); - return; - } - resolve({ stdout, stderr }); - }); - }); -}; - -module.exports.setKeyValueInConfig = async function (key, value) { - return new Promise((resolve, reject) => { - let installationPath = process.env.INSTALL_PATH; - fs.readFile(installationPath + "/config.yaml", "utf8", function (err, data) { - if (err) { - reject(err); - return; - } - let oldStr = new RegExp("((#\\s)?)" + key + "(:|((:\\s).+))\n"); - let newStr = key + ": " + value + "\n"; - let result = data.replace(oldStr, newStr); - fs.writeFile(installationPath + "/config.yaml", result, "utf8", function (err) { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }); - }); -}; - module.exports.extractInfoFromResponse = function (res) { let headers; let accessToken = undefined; @@ -99,64 +67,42 @@ module.exports.extractInfoFromResponse = function (res) { let idRefreshTokenHttpOnly = false; let refreshTokenHttpOnly = false; + let cookies = []; if (res instanceof CollectingResponse) { - const accessTokenCookie = res.cookies.find((info) => info.key === "sAccessToken"); - if (accessTokenCookie) { - accessToken = accessTokenCookie.value; - accessTokenExpiry = new Date(accessTokenCookie.expires).toUTCString(); - accessTokenDomain = accessTokenCookie.domain; - accessTokenHttpOnly = accessTokenCookie.httpOnly; - } - const refreshTokenCookie = res.cookies.find((info) => info.key === "sRefreshToken"); - if (refreshTokenCookie) { - refreshToken = refreshTokenCookie.value; - refreshTokenExpiry = new Date(refreshTokenCookie.expires).toUTCString(); - refreshTokenDomain = refreshTokenCookie.domain; - refreshTokenHttpOnly = refreshTokenCookie.httpOnly; - } headers = Object.fromEntries(res.headers.entries()); - } else { + cookies = res.cookies; + } else if (res) { headers = res.headers; - let cookies = res.headers["set-cookie"] || res.headers["Set-Cookie"]; + cookies = res.headers["set-cookie"] || res.headers["Set-Cookie"]; cookies = cookies === undefined ? [] : cookies; if (!Array.isArray(cookies)) { cookies = [cookies]; } - cookies.forEach((i) => { - if (i.split(";")[0].split("=")[0] === "sAccessToken") { - /** - * if token is sAccessToken=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIyIn0=.eyJzZXNzaW9uSGFuZGxlIjoiMWI4NDBhOTAtMjVmYy00ZjQ4LWE2YWMtMDc0MDIzZjNjZjQwIiwidXNlcklkIjoiIiwicmVmcmVzaFRva2VuSGFzaDEiOiJjYWNhZDNlMGNhMDVkNzRlNWYzNTc4NmFlMGQ2MzJjNDhmMTg1YmZmNmUxNThjN2I2OThkZDYwMzA1NzAyYzI0IiwidXNlckRhdGEiOnt9LCJhbnRpQ3NyZlRva2VuIjoiYTA2MjRjYWItZmIwNy00NTFlLWJmOTYtNWQ3YzU2MjMwZTE4IiwiZXhwaXJ5VGltZSI6MTYyNjUxMjM3NDU4NiwidGltZUNyZWF0ZWQiOjE2MjY1MDg3NzQ1ODYsImxtcnQiOjE2MjY1MDg3NzQ1ODZ9.f1sCkjt0OduS6I6FBQDBLV5zhHXpCU2GXnbe+8OCU6HKG00TX5CM8AyFlOlqzSHABZ7jES/+5k0Ff/rdD34cczlNqICcC4a23AjJg2a097rFrh8/8V7J5fr4UrHLIM4ojZNFz1NyVyDK/ooE6I7soHshEtEVr2XsnJ4q3d+fYs2wwx97PIT82hfHqgbRAzvlv952GYt+OH4bWQE4vTzDqGN7N2OKpn9l2fiCB1Ytzr3ocHRqKuQ8f6xW1n575Q1sSs9F9TtD7lrKfFQH+//6lyKFe2Q1SDc7YU4pE5Cy9Kc/LiqiTU+gsGIJL5qtMzUTG4lX38ugF4QDyNjDBMqCKw==; Max-Age=3599; Expires=Sat, 17 Jul 2021 08:59:34 GMT; Secure; HttpOnly; SameSite=Lax; Path=/' - * i.split(";")[0].split("=")[1] will result in eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIyIn0 - */ - accessToken = decodeURIComponent(i.split(";")[0].split("=").slice(1).join("=")); - if (i.split(";")[2].includes("Expires=")) { - accessTokenExpiry = i.split(";")[2].split("=")[1]; - } else if (i.split(";")[2].includes("expires=")) { - accessTokenExpiry = i.split(";")[2].split("=")[1]; - } else { - accessTokenExpiry = i.split(";")[3].split("=")[1]; - } - if (i.split(";")[1].includes("Domain=")) { - accessTokenDomain = i.split(";")[1].split("=")[1]; - } - accessTokenHttpOnly = i.split(";").findIndex((j) => j.includes("HttpOnly")) !== -1; - } else if (i.split(";")[0].split("=")[0] === "sRefreshToken") { - refreshToken = i.split(";")[0].split("=").slice(1).join("="); - if (i.split(";")[2].includes("Expires=")) { - refreshTokenExpiry = i.split(";")[2].split("=")[1]; - } else if (i.split(";")[2].includes("expires=")) { - refreshTokenExpiry = i.split(";")[2].split("=")[1]; - } else { - refreshTokenExpiry = i.split(";")[3].split("=")[1]; - } - if (i.split(";")[1].includes("Domain=")) { - refreshTokenDomain = i.split(";")[1].split("=").slice(1).join("="); - } - refreshTokenHttpOnly = i.split(";").findIndex((j) => j.includes("HttpOnly")) !== -1; - } - }); + cookies = cookies + .flat() // Ensure we have a flat array of cookies + // Split cookie strings into arrays + .map((cookieStr) => setCookieParser.splitCookiesString(cookieStr)) + .flat() // Since we have an array of arrays now + // `parse` the cookies + .map(setCookieParser.parseString); } + // `CollectingResponse` objects use `key`, `set-cookie-parser` objects use `name` + const accessTokenCookie = cookies.find((info) => (info?.key ?? info?.name) == "sAccessToken"); + if (accessTokenCookie) { + accessToken = accessTokenCookie?.value; + accessTokenExpiry = new Date(accessTokenCookie.expires).toUTCString(); + accessTokenDomain = accessTokenCookie.domain; + accessTokenHttpOnly = accessTokenCookie.httpOnly; + } + const refreshTokenCookie = cookies.find((info) => (info?.key ?? info?.name) === "sRefreshToken"); + if (refreshTokenCookie) { + refreshToken = refreshTokenCookie?.value; + refreshTokenExpiry = new Date(refreshTokenCookie.expires).toUTCString(); + refreshTokenDomain = refreshTokenCookie.domain; + refreshTokenHttpOnly = refreshTokenCookie.httpOnly; + } + let antiCsrf = headers["anti-csrf"]; let frontToken = headers["front-token"]; @@ -214,43 +160,6 @@ module.exports.extractCookieCountInfo = function (res) { }; }; -module.exports.setupST = async function () { - let installationPath = process.env.INSTALL_PATH; - try { - await module.exports.executeCommand("cd " + installationPath + " && cp temp/licenseKey ./licenseKey"); - } catch (ignore) {} - await module.exports.executeCommand("cd " + installationPath + " && cp temp/config.yaml ./config.yaml"); -}; - -module.exports.cleanST = async function () { - let installationPath = process.env.INSTALL_PATH; - try { - await module.exports.executeCommand("cd " + installationPath + " && rm licenseKey"); - } catch (ignore) {} - await module.exports.executeCommand("cd " + installationPath + " && rm config.yaml"); - await module.exports.executeCommand("cd " + installationPath + " && rm -rf .webserver-temp-*"); - await module.exports.executeCommand("cd " + installationPath + " && rm -rf .started"); -}; - -module.exports.stopST = async function (pid) { - let pidsBefore = await getListOfPids(); - if (pidsBefore.length === 0) { - return; - } - await module.exports.executeCommand("kill " + pid); - let startTime = Date.now(); - while (Date.now() - startTime < 10000) { - let pidsAfter = await getListOfPids(); - if (pidsAfter.includes(pid)) { - await new Promise((r) => setTimeout(r, 100)); - continue; - } else { - return; - } - } - throw new Error("error while stopping ST with PID: " + pid); -}; - module.exports.resetAll = function (disableLogging = true) { SuperTokens.reset(); AccountLinkingRecipe.reset(); @@ -275,120 +184,86 @@ module.exports.resetAll = function (disableLogging = true) { } }; -module.exports.killAllST = async function () { - let pids = await getListOfPids(); - for (let i = 0; i < pids.length; i++) { - await module.exports.stopST(pids[i]); - } - module.exports.resetAll(); - nock.cleanAll(); +module.exports.getCoreUrl = () => { + const host = process.env?.SUPERTOKENS_CORE_HOST ?? "localhost"; + const port = process.env?.SUPERTOKENS_CORE_PORT ?? "3567"; + + const coreUrl = `http://${host}:${port}`; + + return coreUrl; }; -module.exports.killAllSTCoresOnly = async function () { - let pids = await getListOfPids(); - for (let i = 0; i < pids.length; i++) { - await module.exports.stopST(pids[i]); +module.exports.getCoreUrlFromConnectionURI = (connectionURI) => { + let coreUrl = connectionURI; + + if (coreUrl.includes("appid-")) { + coreUrl = connectionURI.split("appid-")[0]; + } + + if (coreUrl.endsWith("/")) { + coreUrl = coreUrl.slice(0, -1); } + + return coreUrl; }; -module.exports.startST = async function (config = {}) { - const host = config.host ?? "localhost"; - const port = config.port ?? 8080; - const notUsingTestApp = - process.env.REAL_DB_TEST !== "true" || host !== "localhost" || port !== 8080 || config.noApp === true; - if (config.coreConfig && notUsingTestApp) { - for (const [k, v] of Object.entries(config.coreConfig)) { - await module.exports.setKeyValueInConfig(k, v); - } +module.exports.createCoreApplication = async function ({ appId, coreConfig } = {}) { + const coreUrl = module.exports.getCoreUrl(); + + if (!appId) { + appId = randomUUID(); } - return new Promise(async (resolve, reject) => { - let installationPath = process.env.INSTALL_PATH; - let pidsBefore = await getListOfPids(); - let returned = false; - module.exports - .executeCommand( - "cd " + - installationPath + - ` && java -Djava.security.egd=file:/dev/urandom -classpath "./core/*:./plugin-interface/*" io.supertokens.Main ./ DEV host=` + - host + - " port=" + - port + - " test_mode" - ) - .catch((err) => { - if (!returned) { - returned = true; - reject(err); - } - }); - let startTime = Date.now(); - while (Date.now() - startTime < 30000) { - let pidsAfter = await getListOfPids(); - if (pidsAfter.length <= pidsBefore.length) { - await new Promise((r) => setTimeout(r, 100)); - continue; - } - let nonIntersection = pidsAfter.filter((x) => !pidsBefore.includes(x)); - if (nonIntersection.length !== 1) { - if (!returned) { - returned = true; - reject("something went wrong while starting ST"); - } - } else { - if (!returned) { - returned = true; - if (notUsingTestApp) { - return resolve(`http://${host}:${port}`); - } - try { - // Math.random is an unsafe random but it doesn't actually matter here - // const appId = configs.appId ?? `testapp-${Date.now()}-${Math.floor(Math.random() * 1000)}`; - const appId = config.appId ?? `testapp`; - - await module.exports.removeAppAndTenants(appId); - - const OPAQUE_KEY_WITH_MULTITENANCY_FEATURE = - "ijaleljUd2kU9XXWLiqFYv5br8nutTxbyBqWypQdv2N-BocoNriPrnYQd0NXPm8rVkeEocN9ayq0B7c3Pv-BTBIhAZSclXMlgyfXtlwAOJk=9BfESEleW6LyTov47dXu"; - - await fetch(`http://${host}:${port}/ee/license`, { - method: "PUT", - headers: { - "content-type": "application/json; charset=utf-8", - }, - body: JSON.stringify({ - licenseKey: OPAQUE_KEY_WITH_MULTITENANCY_FEATURE, - }), - }); - - // Create app - const createAppResp = await fetch(`http://${host}:${port}/recipe/multitenancy/app/v2`, { - method: "PUT", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - appId, - coreConfig: config.coreConfig, - }), - }); - const respBody = await createAppResp.json(); - assert.strictEqual(respBody.status, "OK"); - resolve(`http://${host}:${port}/appid-${appId}`); - } catch (err) { - reject(err); - } - } - } - } - if (!returned) { - returned = true; - reject("could not start ST process"); - } + + if (!coreConfig) { + coreConfig = {}; + } else { + } + + const createAppResp = await fetch(`${coreUrl}/recipe/multitenancy/app/v2`, { + method: "PUT", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + appId, + coreConfig, + }), }); + + const respBody = await createAppResp.json(); + assert.strictEqual(respBody.status, "OK"); + assert.strictEqual(respBody.createdNew, true); + + return `${coreUrl}/appid-${appId}`; +}; + +module.exports.getAppIdFromConnectionURI = function (connectionURI) { + return connectionURI.split("/").pop().split("-").pop(); }; -module.exports.startSTWithMultitenancy = async function (config) { - const connectionURI = await module.exports.startST(config); +module.exports.removeCoreApplication = async function ({ connectionURI } = {}) { + const coreUrl = module.exports.getCoreUrlFromConnectionURI(connectionURI); + + const appId = module.exports.getAppIdFromConnectionURI(connectionURI); + + const createAppResp = await fetch(`${coreUrl}/recipe/multitenancy/app/remove`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + appId, + }), + }); + + const respBody = await createAppResp.json(); + assert.strictEqual(respBody.status, "OK"); + + return true; +}; + +module.exports.createCoreApplicationWithMultitenancy = async function (config) { + const connectionURI = await module.exports.createCoreApplication(config); const OPAQUE_KEY_WITH_MULTITENANCY_FEATURE = "ijaleljUd2kU9XXWLiqFYv5br8nutTxbyBqWypQdv2N-BocoNriPrnYQd0NXPm8rVkeEocN9ayq0B7c3Pv-BTBIhAZSclXMlgyfXtlwAOJk=9BfESEleW6LyTov47dXu"; @@ -404,8 +279,8 @@ module.exports.startSTWithMultitenancy = async function (config) { return connectionURI; }; -module.exports.startSTWithMultitenancyAndAccountLinking = async function (config) { - const connectionURI = await module.exports.startST(config); +module.exports.createCoreApplicationWithMultitenancyAndAccountLinking = async function (config) { + const connectionURI = await module.exports.createCoreApplication(config); const OPAQUE_KEY_WITH_FEATURES = "N2yITHflaFS4BPm7n0bnfFCjP4sJoTERmP0J=kXQ5YONtALeGnfOOe2rf2QZ0mfOh0aO3pBqfF-S0jb0ABpat6pySluTpJO6jieD6tzUOR1HrGjJO=50Ob3mHi21tQHJ"; @@ -468,31 +343,6 @@ module.exports.removeAppAndTenants = async function (appId) { } }; -async function getListOfPids() { - let installationPath = process.env.INSTALL_PATH; - let currList; - try { - currList = (await module.exports.executeCommand("cd " + installationPath + " && ls .started/")).stdout; - } catch (err) { - return []; - } - currList = currList.split("\n"); - let result = []; - for (let i = 0; i < currList.length; i++) { - let item = currList[i]; - if (item === "") { - continue; - } - try { - let pid = (await module.exports.executeCommand("cd " + installationPath + " && cat .started/" + item)) - .stdout; - pid = pid.split("\n")[0]; - result.push(pid); - } catch (err) {} - } - return result; -} - function createFormat(options) { if (options.length === 0) { return ``; diff --git a/test/webauthn/config.test.js b/test/webauthn/config.test.js index 22349276c0..9852c3b19d 100644 --- a/test/webauthn/config.test.js +++ b/test/webauthn/config.test.js @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -const { printPath, setupST, startST, stopST, killAllST, cleanST } = require("../utils"); +const { printPath, createCoreApplication } = require("../utils"); let STExpress = require("../../"); let assert = require("assert"); let { ProcessState } = require("../../lib/build/processState"); @@ -21,20 +21,13 @@ let WebAuthnRecipe = require("../../lib/build/recipe/webauthn/recipe").default; describe(`configTest: ${printPath("[test/webauthn/config.test.js]")}`, function () { beforeEach(async function () { - await killAllST(); - await setupST(); ProcessState.getInstance().reset(); }); - after(async function () { - await killAllST(); - await cleanST(); - }); - // test config for emailpassword module // Failure condition: passing custom data or data of invalid type/ syntax to the module it("test default config for webauthn module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: { connectionURI, @@ -71,7 +64,7 @@ describe(`configTest: ${printPath("[test/webauthn/config.test.js]")}`, function // Failure condition: passing data of invalid type/ syntax to the module it("test config for webauthn module", async function () { - const connectionURI = await startST(); + const connectionURI = await createCoreApplication(); STExpress.init({ supertokens: {