Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ releasePassword
/temp_*
/.nyc_output
.circleci/.pat
test-results*
7 changes: 5 additions & 2 deletions .mocharc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions mocha-multi-reporters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"reporterEnabled": "spec, mocha-junit-reporter, mocha-json-output-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "test-results.xml"
},
"mochaJsonOutputReporterReporterOptions": {
"output": "test-results.json"
}
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -193,4 +196,4 @@
"browser": {
"fs": false
}
}
}
66 changes: 30 additions & 36 deletions test/auth-modes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
*/
const {
printPath,
setupST,
startST,
killAllST,
cleanST,

createCoreApplication,

extractInfoFromResponse,
setKeyValueInConfig,

delay,
} = require("./utils");
const assert = require("assert");
Expand All @@ -37,25 +36,19 @@ const exampleJWT =

describe(`auth-modes: ${printPath("[test/auth-modes.test.js]")}`, function () {
beforeEach(async function () {
await killAllST();
await setupST();
ProcessState.getInstance().reset();
});

afterEach(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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading