From eace9bfe9fc8e9aaf43214daa9afae0d5e9cdb45 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 23 Aug 2024 13:33:27 +0530 Subject: [PATCH] fix: remove dashboard multitenancy tests --- .../createOrUpdateThirdPartyConfig.test.js | 112 ---------- test/dashboard/deleteTenant.test.js | 140 ------------ test/dashboard/deleteThirdPartyConfig.test.js | 154 ------------- test/dashboard/getTenantInfo.test.js | 211 ------------------ test/dashboard/listTenants.test.js | 91 -------- 5 files changed, 708 deletions(-) delete mode 100644 test/dashboard/createOrUpdateThirdPartyConfig.test.js delete mode 100644 test/dashboard/deleteTenant.test.js delete mode 100644 test/dashboard/deleteThirdPartyConfig.test.js delete mode 100644 test/dashboard/getTenantInfo.test.js delete mode 100644 test/dashboard/listTenants.test.js diff --git a/test/dashboard/createOrUpdateThirdPartyConfig.test.js b/test/dashboard/createOrUpdateThirdPartyConfig.test.js deleted file mode 100644 index 24a2379be..000000000 --- a/test/dashboard/createOrUpdateThirdPartyConfig.test.js +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -const { ProcessState } = require("../../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startSTWithMultitenancy } = require("../utils"); -let STExpress = require("../../"); -let Dashboard = require("../../recipe/dashboard"); -let Multitenancy = require("../../recipe/multitenancy"); -let EmailPassword = require("../../recipe/emailpassword"); -const express = require("express"); -let { middleware, errorHandler } = require("../../framework/express"); -const request = require("supertest"); -let Session = require("../../recipe/session"); -let assert = require("assert"); - -describe(`User Dashboard createOrUpdateThirdPartyConfig: ${printPath( - "[test/dashboard/createOrUpdateThirdPartyConfig.test.js]" -)}`, () => { - beforeEach(async () => { - await killAllST(); - await setupST(); - ProcessState.getInstance().reset(); - }); - - after(async function () { - await killAllST(); - await cleanST(); - }); - - it("Test that API creates a new third party config for the given tenant", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const tenantName = "tenant1"; - - await Multitenancy.createOrUpdateTenant(tenantName, { - firstFactors: ["emailpassword", "thirdparty"], - }); - - const createThirdPartyConfigURL = `/auth/${tenantName}/dashboard/api/thirdparty/config`; - - let thirdPartyConfigResponse = await new Promise((res) => { - request(app) - .put(createThirdPartyConfigURL) - .set("Authorization", "Bearer testapikey") - .set("Content-Type", "application/json") - .send( - JSON.stringify({ - providerConfig: { - thirdPartyId: "google", - name: "google", - clients: [ - { - clientId: "GOOGLE_CLIENT_ID", - clientSecret: "GOOGLE_CLIENT_SECRET", - }, - ], - }, - }) - ) - .end((err, response) => { - if (err) { - console.log(err); - res(undefined); - } else { - console.log(response.text); - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(thirdPartyConfigResponse.status, "OK"); - assert.strictEqual(thirdPartyConfigResponse.createdNew, true); - - const tenant = await Multitenancy.getTenant(tenantName); - assert.strictEqual(tenant.thirdParty.providers.length, 1); - assert.strictEqual(tenant.thirdParty.providers[0].thirdPartyId, "google"); - }); -}); diff --git a/test/dashboard/deleteTenant.test.js b/test/dashboard/deleteTenant.test.js deleted file mode 100644 index 6a5477dd9..000000000 --- a/test/dashboard/deleteTenant.test.js +++ /dev/null @@ -1,140 +0,0 @@ -/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -const { ProcessState } = require("../../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startSTWithMultitenancy } = require("../utils"); -let STExpress = require("../../"); -let Dashboard = require("../../recipe/dashboard"); -let Multitenancy = require("../../recipe/multitenancy"); -let EmailPassword = require("../../recipe/emailpassword"); -const express = require("express"); -let { middleware, errorHandler } = require("../../framework/express"); -const request = require("supertest"); -let Session = require("../../recipe/session"); -let assert = require("assert"); - -describe(`User Dashboard deleteTenant: ${printPath("[test/dashboard/deleteTenant.test.js]")}`, () => { - beforeEach(async () => { - await killAllST(); - await setupST(); - ProcessState.getInstance().reset(); - }); - - after(async function () { - await killAllST(); - await cleanST(); - }); - - it("Test that API successfully deletes a tenant", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const tenantName = "tenant1"; - - await Multitenancy.createOrUpdateTenant(tenantName, { - firstFactors: ["emailpassword", "thirdparty"], - }); - - const deleteTenantURL = `/auth/${tenantName}/dashboard/api/tenant`; - - let tenantInfoResponse = await new Promise((res) => { - request(app) - .delete(deleteTenantURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(tenantInfoResponse.status, "OK"); - assert.strictEqual(tenantInfoResponse.didExist, true); - - const tenantsRes = await Multitenancy.listAllTenants(); - assert.strictEqual(tenantsRes.tenants.length, 1); - assert.strictEqual(tenantsRes.tenants[0].tenantId, "public"); - }); - - it("Test that API throws error when tenantId is missing", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const deleteTenantURL = `/auth/dashboard/api/tenant`; - - let responseStatus = 200; - let tenantInfoResponse = await new Promise((res) => { - request(app) - .delete(deleteTenantURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - responseStatus = response.statusCode; - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(responseStatus, 200); - assert.strictEqual(tenantInfoResponse.status, "CANNOT_DELETE_PUBLIC_TENANT_ERROR"); - }); -}); diff --git a/test/dashboard/deleteThirdPartyConfig.test.js b/test/dashboard/deleteThirdPartyConfig.test.js deleted file mode 100644 index cbc7316a8..000000000 --- a/test/dashboard/deleteThirdPartyConfig.test.js +++ /dev/null @@ -1,154 +0,0 @@ -/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -const { ProcessState } = require("../../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startSTWithMultitenancy } = require("../utils"); -let STExpress = require("../../"); -let Dashboard = require("../../recipe/dashboard"); -let Multitenancy = require("../../recipe/multitenancy"); -let EmailPassword = require("../../recipe/emailpassword"); -const express = require("express"); -let { middleware, errorHandler } = require("../../framework/express"); -const request = require("supertest"); -let Session = require("../../recipe/session"); -let assert = require("assert"); - -describe(`User Dashboard deleteThirdPartyConfig: ${printPath( - "[test/dashboard/deleteThirdPartyConfig.test.js]" -)}`, () => { - beforeEach(async () => { - await killAllST(); - await setupST(); - ProcessState.getInstance().reset(); - }); - - after(async function () { - await killAllST(); - await cleanST(); - }); - - it("Test that API successfully deletes third party config for a tenant", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const tenantName = "tenant1"; - - await Multitenancy.createOrUpdateTenant(tenantName, { - firstFactors: ["emailpassword", "thirdparty"], - }); - - await Multitenancy.createOrUpdateThirdPartyConfig(tenantName, { - thirdPartyId: "google", - name: "google", - clients: [ - { - clientId: "GOOGLE_CLIENT_ID", - clientSecret: "GOOGLE_CLIENT_SECRET", - }, - ], - }); - - const deleteThirdPartyConfigURL = `/auth/${tenantName}/dashboard/api/thirdparty/config?thirdPartyId=google`; - - let tenantInfoResponse = await new Promise((res) => { - request(app) - .delete(deleteThirdPartyConfigURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(tenantInfoResponse.status, "OK"); - - const tenantsRes = await Multitenancy.getTenant(tenantName); - assert.strictEqual(tenantsRes.thirdParty.providers.length, 0); - }); - - it("Test that API throws error when tenantId or thirdPartyId is missing", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const deleteThirdPartyConfigURL = `/auth/dashboard/api/thirdparty/config`; - - let responseStatus = 200; - let deleteThirdPartyConfigResponse = await new Promise((res) => { - request(app) - .delete(deleteThirdPartyConfigURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - responseStatus = response.statusCode; - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(responseStatus, 400); - assert.strictEqual( - deleteThirdPartyConfigResponse.message, - "Missing required parameter 'tenantId' or 'thirdPartyId'" - ); - }); -}); diff --git a/test/dashboard/getTenantInfo.test.js b/test/dashboard/getTenantInfo.test.js deleted file mode 100644 index f3736c0fd..000000000 --- a/test/dashboard/getTenantInfo.test.js +++ /dev/null @@ -1,211 +0,0 @@ -/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -const { ProcessState } = require("../../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startSTWithMultitenancy } = require("../utils"); -let STExpress = require("../../"); -let Dashboard = require("../../recipe/dashboard"); -let Multitenancy = require("../../recipe/multitenancy"); -let ThirdParty = require("../../lib/build/recipe/thirdparty"); -let EmailPassword = require("../../lib/build/recipe/emailpassword"); -const express = require("express"); -let { middleware, errorHandler } = require("../../framework/express"); -const request = require("supertest"); -let Session = require("../../recipe/session"); -let assert = require("assert"); - -describe(`User Dashboard getTenantInfo: ${printPath("[test/dashboard/getTenantInfo.test.js]")}`, () => { - beforeEach(async () => { - await killAllST(); - await setupST(); - ProcessState.getInstance().reset(); - }); - - after(async function () { - await killAllST(); - await cleanST(); - }); - - it("Test that API returns all the info for the given tenant id", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - ThirdParty.init(), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const tenantName = "tenant1"; - - await Multitenancy.createOrUpdateTenant(tenantName, { - firstFactors: ["emailpassword", "thirdparty"], - }); - - await Multitenancy.createOrUpdateThirdPartyConfig(tenantName, { - thirdPartyId: "google", - name: "google", - clients: [ - { - clientId: "GOOGLE_CLIENT_ID", - clientSecret: "GOOGLE_CLIENT_SECRET", - }, - ], - }); - - await EmailPassword.signUp(tenantName, "test@supertokens.com", "abcd1235"); - - const getTenantInfoURL = `/auth/${tenantName}/dashboard/api/tenant`; - - let tenantInfoResponse = await new Promise((res) => { - request(app) - .get(getTenantInfoURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(tenantInfoResponse.status, "OK"); - assert.strictEqual(tenantInfoResponse.tenant.tenantId, "tenant1"); - assert.strictEqual(tenantInfoResponse.tenant.thirdParty.providers.length, 1); - assert.strictEqual(tenantInfoResponse.tenant.thirdParty.providers.length, 1); - assert.strictEqual(tenantInfoResponse.tenant.thirdParty.providers[0].thirdPartyId, "google"); - assert.strictEqual(tenantInfoResponse.tenant.userCount, 1); - assert.strictEqual(tenantInfoResponse.tenant.firstFactors.length, 2); - assert.strictEqual(tenantInfoResponse.tenant.firstFactors.includes("emailpassword"), true); - assert.strictEqual(tenantInfoResponse.tenant.firstFactors.includes("thirdparty"), true); - }); - - it("Test that API returns error if tenant does not exist", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - ThirdParty.init(), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const tenantName = "tenant1"; - - const getTenantInfoURL = `/auth/${tenantName}/dashboard/api/tenant`; - - let tenantInfoResponse = await new Promise((res) => { - request(app) - .get(getTenantInfoURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(tenantInfoResponse.status, "UNKNOWN_TENANT_ERROR"); - }); - - it("Test that API returns public tenant if tenant id is not provided", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - ThirdParty.init(), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const getTenantInfoURL = `/auth/dashboard/api/tenant`; - - let responseStatus = 200; - let tenantInfoResponse = await new Promise((res) => { - request(app) - .get(getTenantInfoURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - responseStatus = response.statusCode; - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(responseStatus, 200); - assert.strictEqual(tenantInfoResponse.status, "OK"); - assert.strictEqual(tenantInfoResponse.tenant.tenantId, "public"); - assert.strictEqual(tenantInfoResponse.tenant.thirdParty.providers.length, 0); - assert.strictEqual(tenantInfoResponse.tenant.firstFactors.length, 2); - assert.strictEqual(tenantInfoResponse.tenant.firstFactors.includes("emailpassword"), true); - assert.strictEqual(tenantInfoResponse.tenant.firstFactors.includes("thirdparty"), true); - }); -}); diff --git a/test/dashboard/listTenants.test.js b/test/dashboard/listTenants.test.js deleted file mode 100644 index b034cc948..000000000 --- a/test/dashboard/listTenants.test.js +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved. - * - * This software is licensed under the Apache License, Version 2.0 (the - * "License") as published by the Apache Software Foundation. - * - * You may not use this file except in compliance with the License. You may - * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -const { ProcessState } = require("../../lib/build/processState"); -const { printPath, killAllST, setupST, cleanST, startSTWithMultitenancy } = require("../utils"); -let STExpress = require("../.."); -let Dashboard = require("../../recipe/dashboard"); -let Multitenancy = require("../../recipe/multitenancy"); -let EmailPassword = require("../../recipe/emailpassword"); -const express = require("express"); -let { middleware, errorHandler } = require("../../framework/express"); -const request = require("supertest"); -let Session = require("../../recipe/session"); -let assert = require("assert"); - -describe(`User Dashboard listTenants: ${printPath("[test/dashboard/listTenants.test.js]")}`, () => { - beforeEach(async () => { - await killAllST(); - await setupST(); - ProcessState.getInstance().reset(); - }); - - after(async function () { - await killAllST(); - await cleanST(); - }); - - it("Test that API returns all the tenants", async () => { - const connectionURI = await startSTWithMultitenancy(); - STExpress.init({ - supertokens: { - connectionURI, - }, - appInfo: { - apiDomain: "api.supertokens.io", - appName: "SuperTokens", - websiteDomain: "supertokens.io", - }, - recipeList: [ - Dashboard.init({ - apiKey: "testapikey", - }), - EmailPassword.init(), - Session.init(), - ], - }); - - const app = express(); - - app.use(middleware()); - - app.use(errorHandler()); - - const tenantName = "tenant1"; - - await Multitenancy.createOrUpdateTenant(tenantName, { - firstFactors: ["emailpassword", "thirdparty"], - }); - - const listAllTenantsURL = "/auth/dashboard/api/tenants"; - - let tenantInfoResponse = await new Promise((res) => { - request(app) - .get(listAllTenantsURL) - .set("Authorization", "Bearer testapikey") - .end((err, response) => { - if (err) { - res(undefined); - } else { - res(JSON.parse(response.text)); - } - }); - }); - - assert.strictEqual(tenantInfoResponse.status, "OK"); - assert.strictEqual(tenantInfoResponse.tenants.length, 2); - - const tenant1 = tenantInfoResponse.tenants.find((tenant) => tenant.tenantId === tenantName); - }); -});