Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dashboard tests and fixes #914

Merged
merged 15 commits into from
Aug 23, 2024
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [20.0.3] - 2024-08-22

- Fixes issue with dashboard APIs `createOrUpdateThirdPartyConfig` and `deleteThirdPartyConfig` which did not take `includeInNonPublicTenantsByDefault` into account for non-public tenants.
- Updates test server to support dashboard tests.

## [20.0.2] - 2024-08-08

- Fixes an issue where `shouldDoAutomaticAccountLinking` was called without a primary user when linking in some cases.
Expand Down
3 changes: 2 additions & 1 deletion examples/aws/with-emailpassword/backend/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import EmailPassword from "supertokens-node/recipe/emailpassword";

export const getBackendConfig = () => {
return {
debug: true,
framework: "awsLambda",
supertokens: {
connectionURI: "https://try.supertokens.com",
},
appInfo: {
appName: "SuperTokens Demo",
apiDomain: "https://0ez3j5libc.execute-api.ap-south-1.amazonaws.com",
apiDomain: "https://zcbgp7k8ti.execute-api.ap-south-1.amazonaws.com",
websiteDomain: "http://localhost:3000",
apiBasePath: "/auth",
apiGatewayPath: "/prod",
Expand Down
2 changes: 1 addition & 1 deletion examples/aws/with-emailpassword/frontend/src/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Session from "supertokens-auth-react/recipe/session";
export function getApiDomain() {
// const apiPort = process.env.REACT_APP_API_PORT || 3001;
// const apiUrl = process.env.REACT_APP_API_URL || `http://localhost:${apiPort}`;
return "https://0ez3j5libc.execute-api.ap-south-1.amazonaws.com";
return "https://zcbgp7k8ti.execute-api.ap-south-1.amazonaws.com";
}

export function getWebsiteDomain() {
Expand Down
2 changes: 1 addition & 1 deletion examples/express/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ describe("SuperTokens Example Basic tests", function () {
{ name: "password", value: testPW },
]);
await submitForm(page);
const callApiBtn = await page.waitForSelector(".sessionButton");
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
page.on("dialog", async (dialog) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ describe("SuperTokens Example Basic tests", function () {
{ name: "password", value: testPW },
]);
await submitForm(page);
const callApiBtn = await page.waitForSelector(".sessionButton");
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
page.on("dialog", async (dialog) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/koa/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ describe("SuperTokens Example Basic tests", function () {
{ name: "password", value: testPW },
]);
await submitForm(page);
const callApiBtn = await page.waitForSelector(".sessionButton");
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
page.on("dialog", async (dialog) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const recipe_1 = __importDefault(require("../../../multitenancy/recipe"));
const normalisedURLDomain_1 = __importDefault(require("../../../../normalisedURLDomain"));
const normalisedURLPath_1 = __importDefault(require("../../../../normalisedURLPath"));
const utils_1 = require("../../../thirdparty/providers/utils");
const constants_1 = require("../../../multitenancy/constants");
async function createOrUpdateThirdPartyConfig(_, tenantId, options, userContext) {
var _a;
const requestBody = await options.req.getJSONBody();
Expand All @@ -29,7 +30,8 @@ async function createOrUpdateThirdPartyConfig(_, tenantId, options, userContext)
? _a
: [];
for (const provider of staticProviders.filter(
(provider) => provider.includeInNonPublicTenantsByDefault === true
(provider) =>
provider.includeInNonPublicTenantsByDefault === true || tenantId === constants_1.DEFAULT_TENANT_ID
)) {
await multitenancy_1.default.createOrUpdateThirdPartyConfig(
tenantId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const multitenancy_1 = __importDefault(require("../../../multitenancy"));
const recipe_1 = __importDefault(require("../../../multitenancy/recipe"));
const error_1 = __importDefault(require("../../../../error"));
const multifactorauth_1 = require("../../../multifactorauth");
const constants_1 = require("../../../multitenancy/constants");
async function deleteThirdPartyConfig(_, tenantId, options, userContext) {
var _a;
const thirdPartyId = options.req.getKeyValueFromQuery("thirdPartyId");
Expand All @@ -33,8 +34,11 @@ async function deleteThirdPartyConfig(_, tenantId, options, userContext) {
_a !== void 0
? _a
: [];
let staticProviderIds = staticProviders.map((provider) => provider.config.thirdPartyId);
for (const providerId of staticProviderIds) {
for (const provider of staticProviders.filter(
(provider) =>
provider.includeInNonPublicTenantsByDefault === true || tenantId === constants_1.DEFAULT_TENANT_ID
)) {
const providerId = provider.config.thirdPartyId;
await multitenancy_1.default.createOrUpdateThirdPartyConfig(
tenantId,
{
Expand Down
2 changes: 1 addition & 1 deletion lib/build/version.d.ts

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { UserContext } from "../../../../types";
import NormalisedURLDomain from "../../../../normalisedURLDomain";
import NormalisedURLPath from "../../../../normalisedURLPath";
import { doPostRequest } from "../../../thirdparty/providers/utils";
import { DEFAULT_TENANT_ID } from "../../../multitenancy/constants";

export type Response =
| {
Expand Down Expand Up @@ -50,7 +51,7 @@ export default async function createOrUpdateThirdPartyConfig(
const mtRecipe = MultitenancyRecipe.getInstance();
const staticProviders = mtRecipe?.staticThirdPartyProviders ?? [];
for (const provider of staticProviders.filter(
(provider) => provider.includeInNonPublicTenantsByDefault === true
(provider) => provider.includeInNonPublicTenantsByDefault === true || tenantId === DEFAULT_TENANT_ID
)) {
await Multitenancy.createOrUpdateThirdPartyConfig(
tenantId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import MultitenancyRecipe from "../../../multitenancy/recipe";
import SuperTokensError from "../../../../error";
import { FactorIds } from "../../../multifactorauth";
import { UserContext } from "../../../../types";
import { DEFAULT_TENANT_ID } from "../../../multitenancy/constants";

export type Response =
| {
Expand Down Expand Up @@ -56,9 +57,11 @@ export default async function deleteThirdPartyConfig(
// this means that the tenant was using the static list of providers, we need to add them all before deleting one
const mtRecipe = MultitenancyRecipe.getInstance();
const staticProviders = mtRecipe?.staticThirdPartyProviders ?? [];
let staticProviderIds = staticProviders.map((provider) => provider.config.thirdPartyId);

for (const providerId of staticProviderIds) {
for (const provider of staticProviders.filter(
(provider) => provider.includeInNonPublicTenantsByDefault === true || tenantId === DEFAULT_TENANT_ID
)) {
const providerId = provider.config.thirdPartyId;
await Multitenancy.createOrUpdateThirdPartyConfig(
tenantId,
{
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const version = "20.0.2";
export const version = "20.0.3";

export const cdiSupported = ["5.1"];

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

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-node",
"version": "20.0.2",
"version": "20.0.3",
"description": "NodeJS driver for SuperTokens core",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 14 additions & 2 deletions test/test-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import TOTPRoutes from "./totp";
import { getFunc, resetOverrideParams, getOverrideParams } from "./testFunctionMapper";
import OverrideableBuilder from "supertokens-js-override";
import { resetOverrideLogs, logOverrideEvent, getOverrideLogs } from "./overrideLogging";
import Dashboard from "../../../recipe/dashboard";
import DashboardRecipe from "../../../lib/build/recipe/dashboard/recipe";

const { logDebugMessage } = logger("com.supertokens:node-test-server");

Expand All @@ -63,7 +65,12 @@ function defaultSTInit() {
supertokens: {
connectionURI: process.env.ST_CONNECTION_URI || "http://localhost:8080",
},
recipeList: [Session.init()],
recipeList: [
Session.init(),
Dashboard.init({
apiKey: "test",
}),
],
});
}

Expand All @@ -85,12 +92,17 @@ function STReset() {
MultiFactorAuthRecipe.reset();
TOTPRecipe.reset();
SuperTokensRecipe.reset();
DashboardRecipe.reset();
}

function initST(config: any) {
STReset();

const recipeList: RecipeListFunction[] = [];
const recipeList: RecipeListFunction[] = [
Dashboard.init({
apiKey: "test",
}),
];

const parsedConfig = JSON.parse(config);
const init = {
Expand Down
48 changes: 34 additions & 14 deletions test/test-server/src/thirdparty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,43 @@ import { logger } from "./logger";
const namespace = "com.supertokens:node-test-server:thirdparty";
const { logDebugMessage } = logger(namespace);

const router = Router().post("/manuallycreateorupdateuser", async (req, res, next) => {
try {
logDebugMessage("ThirdParty:manuallyCreateOrUpdateUser %j", req.body);
let session = req.body.session && (await convertRequestSessionToSessionObject(req.body.session));
const response = await ThirdParty.manuallyCreateOrUpdateUser(
const router = Router()
.post("/manuallycreateorupdateuser", async (req, res, next) => {
try {
logDebugMessage("ThirdParty:manuallyCreateOrUpdateUser %j", req.body);
let session = req.body.session && (await convertRequestSessionToSessionObject(req.body.session));
const response = await ThirdParty.manuallyCreateOrUpdateUser(
req.body.tenantId || "public",
req.body.thirdPartyId,
req.body.thirdPartyUserId,
req.body.email,
req.body.isVerified,
session,
req.body.userContext
);
await serializeResponse(req, res, response);
} catch (e) {
next(e);
}
})
.post("/getprovider", async (req, res, next) => {
logDebugMessage("ThirdParty:getProvider %j", req.body);
let provider = await ThirdParty.getProvider(
req.body.tenantId || "public",
req.body.thirdPartyId,
req.body.thirdPartyUserId,
req.body.email,
req.body.isVerified,
session,
req.body.clientType,
req.body.userContext
);
await serializeResponse(req, res, response);
} catch (e) {
next(e);
}
});

if (provider === undefined) {
await serializeResponse(req, res, {});
return;
}

await serializeResponse(req, res, {
id: provider.id,
config: provider.config,
});
});

export default router;
Loading