Skip to content

Commit 786508c

Browse files
committed
update: mfa.factorscreen.totp tests use core apps
1 parent 80e6115 commit 786508c

File tree

1 file changed

+124
-112
lines changed

1 file changed

+124
-112
lines changed

test/end-to-end/mfa.factorscreen.totp.test.js

Lines changed: 124 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,30 @@
1818
*/
1919

2020
import assert from "assert";
21-
import puppeteer from "puppeteer";
2221
import {
2322
clearBrowserCookiesWithoutAffectingConsole,
24-
setInputValues,
25-
submitForm,
2623
waitForSTElement,
2724
screenshotOnFailure,
28-
backendBeforeEach,
2925
getTestEmail,
30-
getPasswordlessDevice,
3126
waitFor,
32-
getFactorChooserOptions,
3327
isMFASupported,
34-
setAccountLinkingConfig,
3528
waitForUrl,
3629
setupBrowser,
30+
backendHook,
31+
setupCoreApp,
32+
setupST
3733
} from "../helpers";
38-
import fetch from "isomorphic-fetch";
39-
import { CREATE_CODE_API, CREATE_TOTP_DEVICE_API, MFA_INFO_API } from "../constants";
34+
import { CREATE_TOTP_DEVICE_API, MFA_INFO_API } from "../constants";
4035

41-
import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL } from "../constants";
42-
import { getTestPhoneNumber } from "../exampleTestHelpers";
36+
import { TEST_CLIENT_BASE_URL } from "../constants";
4337
import {
44-
setMFAInfo,
4538
tryEmailPasswordSignUp,
4639
waitForDashboard,
47-
completeOTP,
48-
setupOTP,
49-
logout,
5040
tryEmailPasswordSignIn,
5141
chooseFactor,
52-
tryPasswordlessSignInUp,
5342
setupTOTP,
5443
getTOTPSecret,
5544
completeTOTP,
56-
setupUserWithAllFactors,
57-
goToFactorChooser,
5845
waitForAccessDenied,
5946
waitForLoadingScreen,
6047
waitForBlockedScreen,
@@ -67,44 +54,26 @@ describe("SuperTokens SignIn w/ MFA", function () {
6754
let browser;
6855
let page;
6956
let consoleLogs = [];
70-
let skipped = false;
57+
58+
const appConfig = {
59+
accountLinkingConfig: {
60+
enabled: true,
61+
shouldAutoLink: {
62+
shouldAutomaticallyLink: true,
63+
shouldRequireVerification: false,
64+
},
65+
},
66+
};
7167

7268
before(async function () {
7369
if (!(await isMFASupported())) {
74-
skipped = true;
7570
this.skip();
76-
return;
7771
}
78-
await backendBeforeEach();
79-
80-
await fetch(`${TEST_SERVER_BASE_URL}/startst`, {
81-
method: "POST",
82-
}).catch(console.error);
83-
await setAccountLinkingConfig(true, true, false);
84-
72+
await backendHook("before");
8573
browser = await setupBrowser();
86-
});
87-
88-
after(async function () {
89-
if (skipped) {
90-
return;
91-
}
92-
await browser.close();
93-
94-
await fetch(`${TEST_SERVER_BASE_URL}/after`, {
95-
method: "POST",
96-
}).catch(console.error);
97-
98-
await fetch(`${TEST_SERVER_BASE_URL}/stopst`, {
99-
method: "POST",
100-
}).catch(console.error);
101-
});
102-
103-
afterEach(async function () {
104-
await screenshotOnFailure(this, browser);
105-
if (page) {
106-
await page.close();
107-
}
74+
const coreUrl = await setupCoreApp();
75+
appConfig.coreUrl = coreUrl;
76+
await setupST(appConfig);
10877
});
10978

11079
beforeEach(async function () {
@@ -124,14 +93,27 @@ describe("SuperTokens SignIn w/ MFA", function () {
12493
await page.evaluate(() => window.localStorage.setItem("enableAllRecipes", "true"));
12594
});
12695

96+
afterEach(async function () {
97+
await screenshotOnFailure(this, browser);
98+
await page?.close();
99+
await backendHook("afterEach");
100+
});
101+
102+
after(async function () {
103+
await browser?.close();
104+
await backendHook("after");
105+
});
106+
127107
describe("factor screens", () => {
128108
describe("totp", () => {
129109
const factorId = "totp";
130110

131111
let email, phoneNumber;
132112
before(async () => {
133-
await setMFAInfo({
134-
allowedToSetup: ["totp"],
113+
await setupST({
114+
mfaInfo: {
115+
allowedToSetup: ["totp"],
116+
}
135117
});
136118
page = await browser.newPage();
137119

@@ -156,10 +138,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
156138
});
157139

158140
it("should respect redirectToPath", async () => {
159-
await setMFAInfo({
160-
requirements: [],
161-
alreadySetup: [factorId],
162-
allowedToSetup: [factorId],
141+
await setupST({
142+
mfaInfo: {
143+
requirements: [],
144+
alreadySetup: [factorId],
145+
allowedToSetup: [factorId],
146+
}
163147
});
164148

165149
await tryEmailPasswordSignIn(page, email);
@@ -179,10 +163,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
179163
});
180164

181165
it("should show access denied if the app navigates to the setup page but the user it is not allowed to set up the factor", async () => {
182-
await setMFAInfo({
183-
requirements: [],
184-
alreadySetup: [factorId],
185-
allowedToSetup: [],
166+
await setupST({
167+
mfaInfo: {
168+
requirements: [],
169+
alreadySetup: [factorId],
170+
allowedToSetup: [],
171+
}
186172
});
187173

188174
await tryEmailPasswordSignIn(page, email);
@@ -196,10 +182,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
196182
});
197183

198184
it("should show access denied if setup is not allowed but the factor is not set up", async () => {
199-
await setMFAInfo({
200-
requirements: [factorId],
201-
alreadySetup: [],
202-
allowedToSetup: [],
185+
await setupST({
186+
mfaInfo: {
187+
requirements: [factorId],
188+
alreadySetup: [],
189+
allowedToSetup: [],
190+
}
203191
});
204192

205193
await tryEmailPasswordSignIn(page, email);
@@ -212,10 +200,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
212200
});
213201

214202
it("should show loading screen", async () => {
215-
await setMFAInfo({
216-
requirements: [factorId],
217-
alreadySetup: [factorId],
218-
allowedToSetup: [],
203+
await setupST({
204+
mfaInfo: {
205+
requirements: [factorId],
206+
alreadySetup: [factorId],
207+
allowedToSetup: [],
208+
}
219209
});
220210

221211
await tryEmailPasswordSignIn(page, email);
@@ -243,10 +233,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
243233
});
244234

245235
it("should show blocked screen after too many retries", async () => {
246-
await setMFAInfo({
247-
requirements: [factorId],
248-
alreadySetup: [factorId],
249-
allowedToSetup: [],
236+
await setupST({
237+
mfaInfo: {
238+
requirements: [factorId],
239+
alreadySetup: [factorId],
240+
allowedToSetup: [],
241+
}
250242
});
251243

252244
await tryEmailPasswordSignIn(page, email);
@@ -257,10 +249,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
257249
});
258250

259251
it("should handle mfa info api failures gracefully", async () => {
260-
await setMFAInfo({
261-
requirements: [factorId],
262-
alreadySetup: [factorId],
263-
allowedToSetup: [],
252+
await setupST({
253+
mfaInfo: {
254+
requirements: [factorId],
255+
alreadySetup: [factorId],
256+
allowedToSetup: [],
257+
}
264258
});
265259

266260
await tryEmailPasswordSignIn(page, email);
@@ -296,10 +290,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
296290
});
297291

298292
it("should handle createDevice failures gracefully", async () => {
299-
await setMFAInfo({
300-
requirements: [factorId],
301-
alreadySetup: [],
302-
allowedToSetup: [factorId],
293+
await setupST({
294+
mfaInfo: {
295+
requirements: [factorId],
296+
alreadySetup: [],
297+
allowedToSetup: [factorId],
298+
}
303299
});
304300

305301
await page.setRequestInterception(true);
@@ -330,10 +326,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
330326
});
331327

332328
it("should redirect back if visited after sign in without stepUp param", async () => {
333-
await setMFAInfo({
334-
requirements: [],
335-
alreadySetup: [factorId],
336-
allowedToSetup: [],
329+
await setupST({
330+
mfaInfo: {
331+
requirements: [],
332+
alreadySetup: [factorId],
333+
allowedToSetup: [],
334+
}
337335
});
338336

339337
await tryEmailPasswordSignIn(page, email);
@@ -346,10 +344,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
346344
});
347345

348346
it("should show a link redirecting back if visited after sign in - force setup", async () => {
349-
await setMFAInfo({
350-
requirements: [],
351-
alreadySetup: [factorId],
352-
allowedToSetup: [factorId],
347+
await setupST({
348+
mfaInfo: {
349+
requirements: [],
350+
alreadySetup: [factorId],
351+
allowedToSetup: [factorId],
352+
}
353353
});
354354

355355
await tryEmailPasswordSignIn(page, email);
@@ -364,10 +364,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
364364
});
365365

366366
it("should show a link redirecting back if visited after sign in - setup in stepUp", async () => {
367-
await setMFAInfo({
368-
requirements: [],
369-
alreadySetup: [],
370-
allowedToSetup: [factorId],
367+
await setupST({
368+
mfaInfo: {
369+
requirements: [],
370+
alreadySetup: [],
371+
allowedToSetup: [factorId],
372+
}
371373
});
372374

373375
await tryEmailPasswordSignIn(page, email);
@@ -382,10 +384,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
382384
});
383385

384386
it("should show a link redirecting back if visited after sign in - verification in stepUp", async () => {
385-
await setMFAInfo({
386-
requirements: [],
387-
alreadySetup: [factorId],
388-
allowedToSetup: [],
387+
await setupST({
388+
mfaInfo: {
389+
requirements: [],
390+
alreadySetup: [factorId],
391+
allowedToSetup: [],
392+
}
389393
});
390394

391395
await tryEmailPasswordSignIn(page, email);
@@ -400,10 +404,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
400404
});
401405

402406
it("should show a back button redirecting to the chooser screen if other options are available during sign in - setup", async () => {
403-
await setMFAInfo({
404-
requirements: [{ oneOf: [factorId, "otp-email"] }],
405-
alreadySetup: ["otp-email"],
406-
allowedToSetup: [factorId],
407+
await setupST({
408+
mfaInfo: {
409+
requirements: [{ oneOf: [factorId, "otp-email"] }],
410+
alreadySetup: ["otp-email"],
411+
allowedToSetup: [factorId],
412+
}
407413
});
408414

409415
await tryEmailPasswordSignIn(page, email);
@@ -419,10 +425,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
419425
});
420426

421427
it("should show a back button redirecting to the chooser screen if other options are available during sign in - verification", async () => {
422-
await setMFAInfo({
423-
requirements: [{ oneOf: [factorId, "otp-email"] }],
424-
alreadySetup: [factorId, "otp-email"],
425-
allowedToSetup: [],
428+
await setupST({
429+
mfaInfo: {
430+
requirements: [{ oneOf: [factorId, "otp-email"] }],
431+
alreadySetup: [factorId, "otp-email"],
432+
allowedToSetup: [],
433+
}
426434
});
427435

428436
await tryEmailPasswordSignIn(page, email);
@@ -437,10 +445,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
437445
});
438446

439447
it("should show a logout link - setup", async () => {
440-
await setMFAInfo({
441-
requirements: [factorId],
442-
alreadySetup: [],
443-
allowedToSetup: [factorId],
448+
await setupST({
449+
mfaInfo: {
450+
requirements: [factorId],
451+
alreadySetup: [],
452+
allowedToSetup: [factorId],
453+
}
444454
});
445455

446456
await tryEmailPasswordSignIn(page, email);
@@ -456,10 +466,12 @@ describe("SuperTokens SignIn w/ MFA", function () {
456466
});
457467

458468
it("should show a logout link - verify", async () => {
459-
await setMFAInfo({
460-
requirements: [factorId],
461-
alreadySetup: [factorId],
462-
allowedToSetup: [],
469+
await setupST({
470+
mfaInfo: {
471+
requirements: [factorId],
472+
alreadySetup: [factorId],
473+
allowedToSetup: [],
474+
}
463475
});
464476

465477
await tryEmailPasswordSignIn(page, email);

0 commit comments

Comments
 (0)