Skip to content

Commit ffb7950

Browse files
Add fixes for tests upto signup
1 parent c8c9e45 commit ffb7950

File tree

7 files changed

+613
-1221
lines changed

7 files changed

+613
-1221
lines changed

test/end-to-end/emailverification.test.js

Lines changed: 334 additions & 23 deletions
Large diffs are not rendered by default.

test/end-to-end/passwordless.test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
} from "../helpers";
4343

4444
import { TEST_CLIENT_BASE_URL, SOMETHING_WENT_WRONG_ERROR } from "../constants";
45-
import { tryEmailPasswordSignUp, tryPasswordlessSignInUp } from "./mfa.helpers";
4645
import { randomUUID } from "crypto";
4746

4847
/*
@@ -97,7 +96,11 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
9796
await backendHook("before");
9897
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe));
9998
const coreUrl = await setupCoreApp();
100-
await setupST({ coreUrl, passwordlessFlowType: "USER_INPUT_CODE", passwordlessContactMethod: contactMethod });
99+
await setupST({
100+
coreUrl,
101+
passwordlessFlowType: "USER_INPUT_CODE",
102+
passwordlessContactMethod: contactMethod,
103+
});
101104
});
102105

103106
after(async function () {
@@ -357,9 +360,6 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
357360
});
358361

359362
({ browser, page } = await initBrowser(contactMethod, consoleLogs, authRecipe, undefined));
360-
if (authRecipe === "all") {
361-
await tryEmailPasswordSignUp(page, registeredEmailWithPass);
362-
}
363363
});
364364

365365
after(async function () {
@@ -458,7 +458,11 @@ export function getPasswordlessTestCases({ authRecipe, logId, generalErrorRecipe
458458
disablePhoneGuess: true,
459459
}));
460460
const coreUrl = await setupCoreApp();
461-
await setupST({ coreUrl, passwordlessFlowType: "USER_INPUT_CODE", passwordlessContactMethod: contactMethod });
461+
await setupST({
462+
coreUrl,
463+
passwordlessFlowType: "USER_INPUT_CODE",
464+
passwordlessContactMethod: contactMethod,
465+
});
462466
});
463467

464468
after(async function () {

test/end-to-end/resetpasswordusingtoken.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
setupCoreApp,
5151
setupST,
5252
waitForSTElement,
53+
getResetPasswordFormBackButton,
5354
} from "../helpers";
5455

5556
// Run the tests in a DOM environment.

test/end-to-end/signin.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ describe("SuperTokens SignIn", function () {
537537

538538
describe("Successful Sign In with redirect to, with EmailPasswordAuth", async function () {
539539
it("First sign in", async function () {
540+
await toggleSignInSignUp(page);
541+
await defaultSignUp(page);
540542
consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs);
541543
let cookies = await page.cookies();
542544
assert.deepStrictEqual(cookies.length, 1);
@@ -560,6 +562,17 @@ describe("SuperTokens SignIn", function () {
560562
const pathname = await page.evaluate(() => window.location.pathname);
561563
assert.deepStrictEqual(pathname, "/redirect-to-this-custom-path");
562564
assert.deepStrictEqual(consoleLogs, [
565+
"ST_LOGS EMAIL_PASSWORD OVERRIDE DOES_EMAIL_EXIST",
566+
"ST_LOGS EMAIL_PASSWORD PRE_API_HOOKS EMAIL_EXISTS",
567+
"ST_LOGS EMAIL_PASSWORD OVERRIDE SIGN_UP",
568+
"ST_LOGS EMAIL_PASSWORD PRE_API_HOOKS EMAIL_PASSWORD_SIGN_UP",
569+
"ST_LOGS SESSION ON_HANDLE_EVENT SESSION_CREATED",
570+
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
571+
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
572+
"ST_LOGS EMAIL_PASSWORD ON_HANDLE_EVENT SUCCESS",
573+
"ST_LOGS EMAIL_PASSWORD GET_REDIRECTION_URL SUCCESS",
574+
"ST_LOGS SESSION OVERRIDE GET_JWT_PAYLOAD_SECURELY",
575+
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
563576
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
564577
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
565578
"ST_LOGS SUPERTOKENS GET_REDIRECTION_URL TO_AUTH",

test/helpers.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ export async function waitFor(ms) {
6262
return new Promise((res) => setTimeout(res, ms));
6363
}
6464

65+
export function waitForUrl(page, url, onlyPath = true) {
66+
return page.waitForFunction(
67+
(pathname, onlyPath) => {
68+
return (
69+
(onlyPath
70+
? window.location.pathname
71+
: window.location.pathname + window.location.search + window.location.hash) === pathname
72+
);
73+
},
74+
{ polling: 50 },
75+
url,
76+
onlyPath
77+
);
78+
}
79+
6580
/*
6681
* Selectors and actions helpers.
6782
* Using Puppeteer within shadowDom https://github.com/puppeteer/puppeteer/issues/858#issuecomment-438540596

test/server/index.js

Lines changed: 27 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,16 @@ const UserRoles = require("supertokens-node/recipe/userroles");
6666
const MultitenancyRaw = require("supertokens-node/lib/build/recipe/multitenancy/recipe").default;
6767
const Multitenancy = require("supertokens-node/lib/build/recipe/multitenancy/index");
6868

69-
const AccountLinkingRaw = require("supertokens-node/lib/build/recipe/accountlinking/recipe").default;
70-
const AccountLinking = require("supertokens-node/recipe/accountlinking");
69+
let AccountLinking, AccountLinkingRaw, accountLinkingSupported;
70+
try {
71+
AccountLinkingRaw = require("supertokens-node/lib/build/recipe/accountlinking/recipe").default;
72+
AccountLinking = require("supertokens-node/recipe/accountlinking");
73+
accountLinkingSupported = true;
74+
} catch (ex) {
75+
accountLinkingSupported = false;
76+
}
7177

7278
const UserMetadataRaw = require("supertokens-node/lib/build/recipe/usermetadata/recipe").default;
73-
const UserMetadata = require("supertokens-node/recipe/usermetadata");
74-
75-
const MultiFactorAuthRaw = require("supertokens-node/lib/build/recipe/multifactorauth/recipe").default;
76-
const MultiFactorAuth = require("supertokens-node/recipe/multifactorauth");
77-
78-
const TOTPRaw = require("supertokens-node/lib/build/recipe/totp/recipe").default;
79-
const TOTP = require("supertokens-node/recipe/totp");
80-
81-
const OTPAuth = require("otpauth");
82-
83-
let generalErrorSupported;
8479

8580
if (maxVersion(nodeSDKVersion, "9.9.9") === "9.9.9") {
8681
// General error is only supported by 10.0.0 and above
@@ -196,10 +191,11 @@ function initST({
196191
UserRolesRaw.reset();
197192
PasswordlessRaw.reset();
198193
MultitenancyRaw.reset();
199-
AccountLinkingRaw.reset();
194+
195+
if (accountLinkingSupported) {
196+
AccountLinkingRaw.reset();
197+
}
200198
UserMetadataRaw.reset();
201-
MultiFactorAuthRaw.reset();
202-
TOTPRaw.reset();
203199

204200
EmailVerificationRaw.reset();
205201
EmailPasswordRaw.reset();
@@ -670,7 +666,7 @@ function initST({
670666
...accountLinkingConfig,
671667
};
672668

673-
if (accountLinkingConfig.enabled) {
669+
if (accountLinkingSupported && accountLinkingConfig.enabled) {
674670
recipeList.push([
675671
"accountlinking",
676672
AccountLinking.init({
@@ -680,74 +676,6 @@ function initST({
680676
}),
681677
]);
682678
}
683-
recipeList.push([
684-
"multifactorauth",
685-
MultiFactorAuth.init({
686-
firstFactors: mfaInfo.firstFactors,
687-
override: {
688-
functions: (oI) => ({
689-
...oI,
690-
getFactorsSetupForUser: async (input) => {
691-
const res = await oI.getFactorsSetupForUser(input);
692-
if (mfaInfo?.alreadySetup) {
693-
return mfaInfo.alreadySetup;
694-
}
695-
return res;
696-
},
697-
assertAllowedToSetupFactorElseThrowInvalidClaimError: async (input) => {
698-
if (mfaInfo?.allowedToSetup) {
699-
if (!mfaInfo.allowedToSetup.includes(input.factorId)) {
700-
throw new Session.Error({
701-
type: "INVALID_CLAIMS",
702-
message: "INVALID_CLAIMS",
703-
payload: [
704-
{
705-
id: "test",
706-
reason: "test override",
707-
},
708-
],
709-
});
710-
}
711-
} else {
712-
await oI.assertAllowedToSetupFactorElseThrowInvalidClaimError(input);
713-
}
714-
},
715-
getMFARequirementsForAuth: async (input) => {
716-
const res = await oI.getMFARequirementsForAuth(input);
717-
if (mfaInfo?.requirements) {
718-
return mfaInfo.requirements;
719-
}
720-
return res;
721-
},
722-
}),
723-
apis: (oI) => ({
724-
...oI,
725-
resyncSessionAndFetchMFAInfoPUT: async (input) => {
726-
const res = await oI.resyncSessionAndFetchMFAInfoPUT(input);
727-
728-
if (res.status === "OK") {
729-
if (mfaInfo.alreadySetup) {
730-
res.factors.alreadySetup = [...mfaInfo.alreadySetup];
731-
}
732-
}
733-
if (mfaInfo.noContacts) {
734-
res.emails = {};
735-
res.phoneNumbers = {};
736-
}
737-
return res;
738-
},
739-
}),
740-
},
741-
}),
742-
]);
743-
744-
recipeList.push([
745-
"totp",
746-
TOTP.init({
747-
defaultPeriod: 1,
748-
defaultSkew: 30,
749-
}),
750-
]);
751679

752680
SuperTokens.init({
753681
appInfo: {
@@ -859,7 +787,7 @@ app.get("/sessioninfo", verifySession(), async (req, res, next) => {
859787
res.send({
860788
sessionHandle: session.getHandle(),
861789
userId: session.getUserId(),
862-
recipeUserId: session.getRecipeUserId().getAsString(),
790+
recipeUserId: accountLinkingSupported ? session.getRecipeUserId().getAsString() : session.getUserId(),
863791
accessTokenPayload,
864792
sessionData,
865793
});
@@ -869,6 +797,11 @@ app.get("/sessioninfo", verifySession(), async (req, res, next) => {
869797
});
870798

871799
app.post("/deleteUser", async (req, res) => {
800+
if (!accountLinkingSupported) {
801+
const user = await EmailPassword.getUserByEmail("public", req.body.email);
802+
return res.send(await SuperTokens.deleteUser(user.id));
803+
}
804+
872805
const users = await SuperTokens.listUsersByAccountInfo("public", req.body);
873806
res.send(await SuperTokens.deleteUser(users[0].id));
874807
});
@@ -903,8 +836,8 @@ app.post("/changeEmail", async (req, res) => {
903836

904837
app.get("/unverifyEmail", verifySession(), async (req, res) => {
905838
let session = req.session;
906-
await EmailVerification.unverifyEmail(session.getRecipeUserId());
907-
await session.fetchAndSetClaim(EmailVerification.EmailVerificationClaim, {});
839+
await EmailVerification.unverifyEmail(accountLinkingSupported ? session.getRecipeUserId() : session.getUserId());
840+
await session.fetchAndSetClaim(EmailVerification.EmailVerificationClaim);
908841
res.send({ status: "OK" });
909842
});
910843

@@ -940,22 +873,6 @@ app.post(
940873
}
941874
);
942875

943-
app.post("/completeFactor", verifySession(), async (req, res) => {
944-
let session = req.session;
945-
946-
await MultiFactorAuth.markFactorAsCompleteInSession(session, req.body.id);
947-
948-
res.send({ status: "OK" });
949-
});
950-
951-
app.post("/addRequiredFactor", verifySession(), async (req, res) => {
952-
let session = req.session;
953-
954-
await MultiFactorAuth.addToRequiredSecondaryFactorsForUser(session.getUserId(), req.body.factorId);
955-
956-
res.send({ status: "OK" });
957-
});
958-
959876
app.post("/mergeIntoAccessTokenPayload", verifySession(), async (req, res) => {
960877
let session = req.session;
961878

@@ -972,18 +889,10 @@ app.get("/token", async (_, res) => {
972889

973890
app.post("/setupTenant", async (req, res) => {
974891
const { tenantId, loginMethods, coreConfig } = req.body;
975-
let firstFactors = [];
976-
if (loginMethods.emailPassword?.enabled === true) {
977-
firstFactors.push("emailpassword");
978-
}
979-
if (loginMethods.passwordless?.enabled === true) {
980-
firstFactors.push("otp-phone", "otp-email", "link-phone", "link-email");
981-
}
982-
if (loginMethods.thirdParty?.enabled === true) {
983-
firstFactors.push("thirdparty");
984-
}
985892
let coreResp = await Multitenancy.createOrUpdateTenant(tenantId, {
986-
firstFactors,
893+
emailPasswordEnabled: loginMethods.emailPassword?.enabled === true,
894+
thirdPartyEnabled: loginMethods.thirdParty?.enabled === true,
895+
passwordlessEnabled: loginMethods.passwordless?.enabled === true,
987896
coreConfig,
988897
});
989898

@@ -1020,10 +929,6 @@ app.get("/test/getDevice", (req, res) => {
1020929
res.send(deviceStore.get(req.query.preAuthSessionId));
1021930
});
1022931

1023-
app.post("/test/getTOTPCode", (req, res) => {
1024-
res.send(JSON.stringify({ totp: new OTPAuth.TOTP({ secret: req.body.secret, digits: 6, period: 1 }).generate() }));
1025-
});
1026-
1027932
app.get("/test/featureFlags", (req, res) => {
1028933
const available = [];
1029934

@@ -1038,10 +943,10 @@ app.get("/test/featureFlags", (req, res) => {
1038943
available.push("userroles");
1039944
available.push("multitenancy");
1040945
available.push("multitenancyManagementEndpoints");
1041-
available.push("accountlinking");
1042-
available.push("mfa");
946+
if (accountLinkingSupported) {
947+
available.push("accountlinking");
948+
}
1043949
available.push("recipeConfig");
1044-
available.push("oauth2");
1045950
available.push("accountlinking-fixes");
1046951

1047952
res.send({

0 commit comments

Comments
 (0)