Skip to content

Commit

Permalink
test: make tests more backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Sep 14, 2023
1 parent 20f4be5 commit e365725
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 161 deletions.
142 changes: 29 additions & 113 deletions test/end-to-end/multitenancy.dynamic_login_methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import {
clickOnProviderButton,
loginWithAuth0,
isMultitenancySupported,
isAccountLinkingSupported,
isMultitenancyManagementEndpointsSupported,
setupTenant,
} from "../helpers";
import {
TEST_CLIENT_BASE_URL,
Expand All @@ -56,7 +59,7 @@ describe("SuperTokens Multitenancy dynamic login methods", function () {
let pageCrashed;

before(async function () {
const isSupported = await isMultitenancySupported();
const isSupported = (await isMultitenancySupported()) && (await isMultitenancyManagementEndpointsSupported());
if (!isSupported) {
this.skip();
}
Expand Down Expand Up @@ -128,13 +131,18 @@ describe("SuperTokens Multitenancy dynamic login methods", function () {
page.waitForNavigation({ waitUntil: "networkidle0" }),
]);
const providers = await getProvidersLabels(page);
compareArrayContents(providers, [
"Continue with Github",
"Continue with Google",
"Continue with Facebook",
"Continue with Auth0",
"Continue with Mock Provider",
]);
compareArrayContents(
providers,
(await isAccountLinkingSupported())
? [
"Continue with Github",
"Continue with Google",
"Continue with Facebook",
"Continue with Auth0",
"Continue with Mock Provider",
]
: ["Continue with Github", "Continue with Google", "Continue with Facebook", "Continue with Auth0"]
);
const inputNames = await getInputNames(page);
assert.deepStrictEqual(inputNames, ["email", "password"]);
});
Expand Down Expand Up @@ -370,13 +378,18 @@ describe("SuperTokens Multitenancy dynamic login methods", function () {
]);

const providers = await getProvidersLabels(page);
compareArrayContents(providers, [
"Continue with Github",
"Continue with Google",
"Continue with Facebook",
"Continue with Auth0",
"Continue with Mock Provider",
]);
compareArrayContents(
providers,
(await isAccountLinkingSupported())
? [
"Continue with Github",
"Continue with Google",
"Continue with Facebook",
"Continue with Auth0",
"Continue with Mock Provider",
]
: ["Continue with Github", "Continue with Google", "Continue with Facebook", "Continue with Auth0"]
);
assert.strictEqual(await getProviderLogoCount(page), 3);
});

Expand Down Expand Up @@ -851,41 +864,7 @@ function clearDynamicLoginMethodsSettings(page) {
}

export async function enableDynamicLoginMethods(page, mockLoginMethods, tenantId = "public") {
let coreResp = await fetch(`${connectionURI}/recipe/multitenancy/tenant`, {
method: "PUT",
headers: new Headers([
["content-type", "application/json"],
["rid", "multitenancy"],
]),
body: JSON.stringify({
tenantId,
emailPasswordEnabled: mockLoginMethods.emailPassword?.enabled === true,
thirdPartyEnabled: mockLoginMethods.thirdParty?.enabled === true,
passwordlessEnabled: mockLoginMethods.passwordless?.enabled === true,
coreConfig: {},
}),
});
assert.strictEqual(coreResp.status, 200);

for (const provider of mockLoginMethods["thirdParty"]?.providers) {
coreResp = await fetch(`${connectionURI}/${tenantId}/recipe/multitenancy/config/thirdparty`, {
method: "PUT",
headers: new Headers([
["content-type", "application/json"],
["rid", "multitenancy"],
]),
body: JSON.stringify({
skipValidation: true,
config: {
...providerConfigs[provider.id.split("-")[0]],
thirdPartyId: provider.id,
name: provider.name,
},
}),
});

assert.strictEqual(coreResp.status, 200);
}
await setupTenant(tenantId, mockLoginMethods);

return page.evaluate(() => {
window.localStorage.setItem("usesDynamicLoginMethods", "true");
Expand All @@ -901,66 +880,3 @@ export async function enableDynamicLoginMethods(page, mockLoginMethods, tenantId
function compareArrayContents(actual, expected) {
return assert.deepStrictEqual(actual.sort(), expected.sort());
}

const providerConfigs = {
apple: {
clients: [
{
clientId: "4398792-io.supertokens.example.service",
additionalConfig: {
keyId: "7M48Y4RYDL",
privateKey:
"-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgu8gXs+XYkqXD6Ala9Sf/iJXzhbwcoG5dMh1OonpdJUmgCgYIKoZIzj0DAQehRANCAASfrvlFbFCYqn3I2zeknYXLwtH30JuOKestDbSfZYxZNMqhF/OzdZFTV0zc5u5s3eN+oCWbnvl0hM+9IW0UlkdA\n-----END PRIVATE KEY-----",
teamId: "YWQCXGJRJL",
},
},
],
},
github: {
clients: [
{
clientSecret: "e97051221f4b6426e8fe8d51486396703012f5bd",
clientId: "467101b197249757c71f",
},
],
},
google: {
clients: [
{
clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
clientSecret: "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",
},
],
},
auth0: {
// this contains info about forming the authorisation redirect URL without the state params and without the redirect_uri param
authorizationEndpoint: `https://${process.env.AUTH0_DOMAIN}/authorize`,
authorizationEndpointQueryParams: {
scope: "openid profile email email_verified",
},
jwksURI: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json`,
tokenEndpoint: `https://${process.env.AUTH0_DOMAIN}/oauth/token`,
clients: [
{
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
},
],
userInfoMap: {
fromIdTokenPayload: {
userId: "sub",
email: "email",
emailVerified: "email_verified",
},
},
},
test: {
// We add a client since it's required
clients: [
{
clientId: "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
clientSecret: "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",
},
],
},
};
54 changes: 6 additions & 48 deletions test/end-to-end/multitenancy.tenant_interactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ import {
getTextByDataSupertokens,
getVerificationEmailErrorTitle,
isMultitenancySupported,
isMultitenancyManagementEndpointsSupported,
setupTenant,
addUserToTenant,
removeUserFromTenant,
removeTenant,
} from "../helpers";
import {
TEST_CLIENT_BASE_URL,
Expand All @@ -59,7 +64,7 @@ describe("SuperTokens Multitenancy tenant interactions", function () {
let pageCrashed;

before(async function () {
const isSupported = await isMultitenancySupported();
const isSupported = (await isMultitenancySupported()) && (await isMultitenancyManagementEndpointsSupported());
if (!isSupported) {
this.skip();
}
Expand Down Expand Up @@ -1319,53 +1324,6 @@ export async function enableDynamicLoginMethods(page) {
});
}

async function setupTenant(tenantId, mockLoginMethods) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/setupTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
mockLoginMethods,
}),
});
assert.strictEqual(coreResp.status, 200);
}

async function addUserToTenant(tenantId, recipeUserId) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/addUserToTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
recipeUserId,
}),
});
assert.strictEqual(coreResp.status, 200);
}

async function removeUserFromTenant(tenantId, recipeUserId) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/removeUserFromTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
recipeUserId,
}),
});
assert.strictEqual(coreResp.status, 200);
}

async function removeTenant(tenantId) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/removeTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
}),
});
assert.strictEqual(coreResp.status, 200);
}

async function epSignUp(page, email, fieldErrors, generalError, emailVerificationRequired) {
const link = await getSignInOrSignUpSwitchLink(page);
const linkText = await link.evaluate((e) => e.textContent);
Expand Down
56 changes: 56 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,15 @@ export async function isMultitenancySupported() {
return true;
}

export async function isMultitenancyManagementEndpointsSupported() {
const features = await getFeatureFlags();
if (!features.includes("multitenancyManagementEndpoints")) {
return false;
}

return true;
}

export async function isAccountLinkingSupported() {
const features = await getFeatureFlags();
if (!features.includes("accountlinking")) {
Expand All @@ -867,3 +876,50 @@ export async function setGeneralErrorToLocalStorage(recipeName, action, page) {
export async function getTestEmail() {
return `john.doe+${Date.now()}@supertokens.io`;
}

export async function setupTenant(tenantId, mockLoginMethods) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/setupTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
mockLoginMethods,
}),
});
assert.strictEqual(coreResp.status, 200);
}

export async function addUserToTenant(tenantId, recipeUserId) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/addUserToTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
recipeUserId,
}),
});
assert.strictEqual(coreResp.status, 200);
}

export async function removeUserFromTenant(tenantId, recipeUserId) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/removeUserFromTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
recipeUserId,
}),
});
assert.strictEqual(coreResp.status, 200);
}

export async function removeTenant(tenantId) {
let coreResp = await fetch(`${TEST_APPLICATION_SERVER_BASE_URL}/removeTenant`, {
method: "POST",
headers: new Headers([["content-type", "application/json"]]),
body: JSON.stringify({
tenantId,
}),
});
assert.strictEqual(coreResp.status, 200);
}
1 change: 1 addition & 0 deletions test/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ app.get("/test/featureFlags", (req, res) => {

if (multitenancySupported) {
available.push("multitenancy");
available.push("multitenancyManagementEndpoints");
}

if (accountLinkingSupported) {
Expand Down

0 comments on commit e365725

Please sign in to comment.