@@ -29,7 +29,9 @@ import {
29
29
getTestInstance ,
30
30
getTotpCode ,
31
31
delay ,
32
- randomEmail
32
+ randomEmail ,
33
+ verifyEmail ,
34
+ email
33
35
} from '../../helpers/integration/helpers' ;
34
36
import { MultiFactorAssertionImpl } from '../../../src/mfa/mfa_assertion' ;
35
37
@@ -40,6 +42,7 @@ import { async } from '@firebase/util';
40
42
import { UserCredentialImpl } from '../../../src/core/user/user_credential_impl' ;
41
43
import { resolve } from 'dns' ;
42
44
import { UserCredentialInternal } from '../../../internal' ;
45
+ import { verify } from 'crypto' ;
43
46
44
47
45
48
@@ -53,35 +56,28 @@ describe(' Integration tests: Mfa TOTP', () => {
53
56
let idToken : string ;
54
57
let signUpCred : UserCredential ;
55
58
let totpSecret : TotpSecret ;
56
- let email : string ;
57
59
let assertion : MultiFactorAssertionImpl ;
58
60
let _request : MFA . StartTotpMfaEnrollmentRequest ;
59
61
let startMfaResponse : MFA . StartTotpMfaEnrollmentResponse ;
60
62
let displayName : string ;
61
63
beforeEach ( async ( ) => {
62
64
auth = getTestInstance ( ) ;
63
-
64
65
displayName = 'totp-integration-test' ;
65
-
66
- // signUpCred = await createUserWithEmailAndPassword(
67
-
68
- // auth,
69
- // email,
70
- // 'password'
71
- // );
72
- // await auth.signOut();
73
66
} ) ;
74
67
75
68
afterEach ( async ( ) => {
76
- await cleanUpTestInstance ( auth ) ;
77
-
69
+ await cleanUpTestInstance ( auth , 'totp' ) ;
70
+
78
71
} ) ;
79
72
80
73
it ( 'should not enroll if incorrect totp supplied' , async ( ) => {
81
74
let session ;
82
75
console . log ( email ) ;
83
76
console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
84
77
console . log ( 'auth current User:' , auth . currentUser ) ;
78
+
79
+ await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
80
+
85
81
const cr = await signInWithEmailAndPassword ( auth , email , 'password' ) ;
86
82
87
83
console . log ( 'signed In for totp' ) ;
@@ -119,16 +115,9 @@ describe(' Integration tests: Mfa TOTP', () => {
119
115
console . log ( email ) ;
120
116
console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
121
117
console . log ( 'auth current User:' , auth . currentUser ) ;
118
+ await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
122
119
const cr = await signInWithEmailAndPassword ( auth , email , 'password' ) ;
123
120
124
-
125
- // await sendEmailVerification(cr.user);
126
-
127
- // //Apply the email verification code
128
- // await applyActionCode(auth, (await code(email)).oobCode);
129
- // await cr.user.reload();
130
- // expect(cr.user.emailVerified).to.be.true;
131
-
132
121
console . log ( 'signed In for totp' ) ;
133
122
const mfaUser = multiFactor ( cr . user ) ;
134
123
@@ -168,11 +157,6 @@ describe(' Integration tests: Mfa TOTP', () => {
168
157
169
158
await auth . signOut ( ) ;
170
159
171
- //await expect(signInWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/multi-factor-auth-required');
172
-
173
-
174
- //await expect().to.be.rejectedWith(FirebaseError);
175
-
176
160
} )
177
161
178
162
it ( 'should not allow sign-in with incorrect totp' , async ( ) => {
@@ -181,8 +165,8 @@ describe(' Integration tests: Mfa TOTP', () => {
181
165
let resolver ;
182
166
console . log ( email ) ;
183
167
console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
184
-
185
- // Added a delay so that getTotpCode() actually generates a new totp code
168
+ await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
169
+ // Added a delay so that getTotpCode() actually generates a new totp code
186
170
await delay ( 30 * 1000 ) ;
187
171
try {
188
172
@@ -227,7 +211,8 @@ describe(' Integration tests: Mfa TOTP', () => {
227
211
228
212
console . log ( email ) ;
229
213
console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
230
-
214
+
215
+ await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
231
216
// Added a delay so that getTotpCode() actually generates a new totp code
232
217
await delay ( 30 * 1000 ) ;
233
218
try {
@@ -263,8 +248,9 @@ describe(' Integration tests: Mfa TOTP', () => {
263
248
const mfaUser = multiFactor ( userCredential . user ) ;
264
249
265
250
await expect ( mfaUser . unenroll ( resolver . hints [ 0 ] . uid ) ) . to . be . fulfilled ;
251
+
266
252
await auth . signOut ( ) ;
267
253
268
254
}
269
- } ) . timeout ( 31000 ) ;
255
+ } ) . timeout ( 35000 ) ;
270
256
} )
0 commit comments