1818 */
1919
2020import assert from "assert" ;
21- import puppeteer from "puppeteer" ;
2221import {
2322 clearBrowserCookiesWithoutAffectingConsole ,
24- setInputValues ,
25- submitForm ,
26- waitForSTElement ,
2723 screenshotOnFailure ,
28- backendBeforeEach ,
2924 getTestEmail ,
30- getPasswordlessDevice ,
31- waitFor ,
3225 getFactorChooserOptions ,
33- setAccountLinkingConfig ,
3426 isMFASupported ,
3527 setupBrowser ,
28+ backendHook ,
29+ setupCoreApp ,
30+ setupST
3631} from "../helpers" ;
37- import fetch from "isomorphic-fetch" ;
38- import { CREATE_CODE_API , CREATE_TOTP_DEVICE_API , MFA_INFO_API } from "../constants" ;
39-
40- import { TEST_CLIENT_BASE_URL , TEST_SERVER_BASE_URL } from "../constants" ;
32+ import { TEST_CLIENT_BASE_URL } from "../constants" ;
4133import { getTestPhoneNumber } from "../exampleTestHelpers" ;
4234import {
4335 setMFAInfo ,
4436 tryEmailPasswordSignUp ,
4537 waitForDashboard ,
4638 completeOTP ,
4739 setupOTP ,
48- logout ,
4940 tryEmailPasswordSignIn ,
5041 chooseFactor ,
51- tryPasswordlessSignInUp ,
5242 setupTOTP ,
5343 completeTOTP ,
54- setupUserWithAllFactors ,
5544 goToFactorChooser ,
56- waitForAccessDenied ,
57- waitForLoadingScreen ,
58- waitForBlockedScreen ,
5945} from "./mfa.helpers" ;
6046
6147/*
@@ -65,46 +51,31 @@ describe("SuperTokens SignIn w/ MFA", function () {
6551 let browser ;
6652 let page ;
6753 let consoleLogs = [ ] ;
68- let skipped ;
54+
55+ const appConfig = {
56+ accountLinkingConfig : {
57+ enabled : true ,
58+ shouldAutoLink : {
59+ shouldAutomaticallyLink : true ,
60+ shouldRequireVerification : false ,
61+ } ,
62+ } ,
63+ } ;
6964
7065 before ( async function ( ) {
7166 if ( ! ( await isMFASupported ( ) ) ) {
72- skipped = true ;
7367 this . skip ( ) ;
74- return ;
7568 }
76- await backendBeforeEach ( ) ;
77-
78- await fetch ( `${ TEST_SERVER_BASE_URL } /startst` , {
79- method : "POST" ,
80- } ) . catch ( console . error ) ;
81-
69+ await backendHook ( "before" ) ;
8270 browser = await setupBrowser ( ) ;
83- } ) ;
84-
85- after ( async function ( ) {
86- if ( skipped ) {
87- return ;
88- }
89- await browser . close ( ) ;
90-
91- await fetch ( `${ TEST_SERVER_BASE_URL } /after` , {
92- method : "POST" ,
93- } ) . catch ( console . error ) ;
9471
95- await fetch ( `${ TEST_SERVER_BASE_URL } /stopst` , {
96- method : "POST" ,
97- } ) . catch ( console . error ) ;
98- } ) ;
99-
100- afterEach ( async function ( ) {
101- await screenshotOnFailure ( this , browser ) ;
102- if ( page ) {
103- await page . close ( ) ;
104- }
72+ const coreUrl = await setupCoreApp ( ) ;
73+ appConfig . coreUrl = coreUrl ;
74+ await setupST ( appConfig ) ;
10575 } ) ;
10676
10777 beforeEach ( async function ( ) {
78+ await backendHook ( "beforeEach" ) ;
10879 page = await browser . newPage ( ) ;
10980 page . on ( "console" , ( consoleObj ) => {
11081 const log = consoleObj . text ( ) ;
@@ -121,18 +92,26 @@ describe("SuperTokens SignIn w/ MFA", function () {
12192 await page . evaluate ( ( ) => window . localStorage . setItem ( "enableAllRecipes" , "true" ) ) ;
12293 } ) ;
12394
95+ afterEach ( async function ( ) {
96+ await screenshotOnFailure ( this , browser ) ;
97+ await page ?. close ( ) ;
98+ await backendHook ( "afterEach" ) ;
99+ } ) ;
100+
101+ after ( async function ( ) {
102+ await browser ?. close ( ) ;
103+ await backendHook ( "after" ) ;
104+ } ) ;
105+
124106 describe ( "requirement handling" , ( ) => {
125107 let email , phoneNumber ;
126108 let secret ;
127109 before ( async ( ) => {
128- await setMFAInfo ( { } ) ;
129110 page = await browser . newPage ( ) ;
130111
131112 email = await getTestEmail ( ) ;
132113 phoneNumber = getTestPhoneNumber ( ) ;
133114
134- await setMFAInfo ( { } ) ;
135- await setAccountLinkingConfig ( true , true , false ) ;
136115 await Promise . all ( [
137116 page . goto ( `${ TEST_CLIENT_BASE_URL } /auth/?rid=emailpassword` ) ,
138117 page . waitForNavigation ( { waitUntil : "networkidle0" } ) ,
@@ -157,9 +136,11 @@ describe("SuperTokens SignIn w/ MFA", function () {
157136
158137 describe ( "multistep requirement list" , ( ) => {
159138 it ( "multistep requirements should happen in order (allOfInAnyOrder -> oneOf)" , async ( ) => {
160- await setMFAInfo ( {
139+
140+ appConfig . mfaInfo = {
161141 requirements : [ { allOfInAnyOrder : [ "otp-phone" , "totp" ] } , { oneOf : [ "otp-email" ] } ] ,
162- } ) ;
142+ } ;
143+ await setupST ( appConfig ) ;
163144
164145 await tryEmailPasswordSignIn ( page , email ) ;
165146 const factors1 = await getFactorChooserOptions ( page ) ;
@@ -172,9 +153,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
172153 } ) ;
173154
174155 it ( "multistep requirements should happen in order (oneOf -> allOfInAnyOrder)" , async ( ) => {
175- await setMFAInfo ( {
156+ appConfig . mfaInfo = {
176157 requirements : [ { oneOf : [ "otp-phone" , "totp" ] } , { allOfInAnyOrder : [ "totp" , "otp-email" ] } ] ,
177- } ) ;
158+ } ;
159+ await setupST ( appConfig ) ;
178160
179161 await tryEmailPasswordSignIn ( page , email ) ;
180162 const factors1 = await getFactorChooserOptions ( page ) ;
@@ -189,9 +171,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
189171 await waitForDashboard ( page ) ;
190172 } ) ;
191173 it ( "string requirements strictly set the order of the factor screens" , async ( ) => {
192- await setMFAInfo ( {
174+ appConfig . mfaInfo = {
193175 requirements : [ "otp-phone" , "totp" , "otp-email" ] ,
194- } ) ;
176+ } ;
177+ await setupST ( appConfig ) ;
195178
196179 await tryEmailPasswordSignIn ( page , email ) ;
197180 await completeOTP ( page , "PHONE" ) ;
@@ -203,9 +186,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
203186
204187 describe ( "allOfInAnyOrder" , ( ) => {
205188 it ( "should pass if all requirements are complete" , async ( ) => {
206- await setMFAInfo ( {
189+ appConfig . mfaInfo = {
207190 requirements : [ { allOfInAnyOrder : [ "otp-phone" , "totp" , "otp-email" ] } ] ,
208- } ) ;
191+ } ;
192+ await setupST ( appConfig ) ;
209193
210194 await tryEmailPasswordSignIn ( page , email ) ;
211195 const factors1 = await getFactorChooserOptions ( page ) ;
@@ -222,9 +206,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
222206 await waitForDashboard ( page ) ;
223207 } ) ;
224208 it ( "should pass if the array is empty" , async ( ) => {
225- await setMFAInfo ( {
209+ appConfig . mfaInfo = {
226210 requirements : [ { allOfInAnyOrder : [ ] } ] ,
227- } ) ;
211+ } ;
212+ await setupST ( appConfig ) ;
228213
229214 await tryEmailPasswordSignIn ( page , email ) ;
230215 await waitForDashboard ( page ) ;
@@ -233,9 +218,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
233218
234219 describe ( "oneOf" , ( ) => {
235220 it ( "should pass if one of the requirements are complete" , async ( ) => {
236- await setMFAInfo ( {
221+ appConfig . mfaInfo = {
237222 requirements : [ { oneOf : [ "otp-phone" , "totp" , "otp-email" ] } ] ,
238- } ) ;
223+ } ;
224+ await setupST ( appConfig ) ;
239225
240226 await tryEmailPasswordSignIn ( page , email ) ;
241227 const factors1 = await getFactorChooserOptions ( page ) ;
@@ -246,9 +232,10 @@ describe("SuperTokens SignIn w/ MFA", function () {
246232 await waitForDashboard ( page ) ;
247233 } ) ;
248234 it ( "should pass if the array is empty" , async ( ) => {
249- await setMFAInfo ( {
235+ appConfig . mfaInfo = {
250236 requirements : [ { oneOf : [ ] } ] ,
251- } ) ;
237+ } ;
238+ await setupST ( appConfig ) ;
252239
253240 await tryEmailPasswordSignIn ( page , email ) ;
254241 await waitForDashboard ( page ) ;
0 commit comments