17
17
18
18
import { expect , use } from 'chai' ;
19
19
import chaiAsPromised from 'chai-as-promised' ;
20
- import * as sinon from 'sinon' ;
21
20
import sinonChai from 'sinon-chai' ;
22
21
23
22
//import { mockTotp } from '../../helpers/integration/helpers';
24
- import { Auth , createUserWithEmailAndPassword , multiFactor , signInWithEmailAndPassword , UserCredential , sendEmailVerification , applyActionCode , getMultiFactorResolver } from '@firebase/auth' ;
23
+ import { Auth , createUserWithEmailAndPassword , multiFactor , signInWithEmailAndPassword , UserCredential , getMultiFactorResolver } from '@firebase/auth' ;
25
24
import { FirebaseError , getApp } from '@firebase/app' ;
26
25
import {
27
26
cleanUpTestInstance ,
28
- code ,
29
27
getTestInstance ,
30
28
getTotpCode ,
31
29
delay ,
32
- randomEmail ,
33
- verifyEmail ,
34
30
email
35
31
} from '../../helpers/integration/helpers' ;
36
32
import { MultiFactorAssertionImpl } from '../../../src/mfa/mfa_assertion' ;
37
33
38
- import { MultiFactorSessionImpl } from '../../../src/mfa/mfa_session' ;
39
34
import { TotpMultiFactorGenerator , TotpSecret } from '../../../src/mfa/assertions/totp' ;
40
35
import * as MFA from '../../../src/api/account_management/mfa' ;
41
- import { async } from '@firebase/util' ;
42
- import { UserCredentialImpl } from '../../../src/core/user/user_credential_impl' ;
43
- import { resolve } from 'dns' ;
44
- import { UserCredentialInternal } from '../../../internal' ;
45
- import { verify } from 'crypto' ;
46
36
47
37
48
38
@@ -72,87 +62,45 @@ describe(' Integration tests: Mfa TOTP', () => {
72
62
73
63
it ( 'should not enroll if incorrect totp supplied' , async ( ) => {
74
64
let session ;
75
- console . log ( email ) ;
76
- console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
77
- console . log ( 'auth current User:' , auth . currentUser ) ;
78
-
79
- await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
65
+ //await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
80
66
81
67
const cr = await signInWithEmailAndPassword ( auth , email , 'password' ) ;
82
-
83
- console . log ( 'signed In for totp' ) ;
84
68
const mfaUser = multiFactor ( cr . user ) ;
85
-
86
- console . log ( 'session info for: ' ) ;
87
69
session = await mfaUser . getSession ( ) ;
88
- console . log ( JSON . stringify ( session ) ) ;
89
-
90
-
91
70
totpSecret = await TotpMultiFactorGenerator . generateSecret (
92
71
session
93
72
) ;
94
-
95
- console . log ( "**** totpSecret****" ) ;
96
- console . log ( totpSecret . secretKey ) ;
97
- console . log ( totpSecret . codeLength ) ;
98
- console . log ( totpSecret . codeIntervalSeconds ) ;
99
- console . log ( totpSecret . hashingAlgorithm ) ;
100
-
101
73
const totpVerificationCode = getTotpCode ( totpSecret . secretKey , totpSecret . codeIntervalSeconds , totpSecret . codeLength , totpSecret . hashingAlgorithm ) ;
102
74
103
75
const multiFactorAssertion = TotpMultiFactorGenerator . assertionForEnrollment (
104
76
totpSecret ,
105
77
totpVerificationCode + '0'
106
78
) ;
107
79
108
- console . log ( totpVerificationCode ) ;
109
80
await expect ( mfaUser . enroll ( multiFactorAssertion , displayName ) ) . to . be . rejectedWith ( 'auth/invalid-verification-code' ) ;
110
81
await auth . signOut ( ) ;
111
82
} )
112
83
it ( 'should enroll using correct otp' , async ( ) => {
113
84
114
85
let session ;
115
- console . log ( email ) ;
116
- console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
117
- console . log ( 'auth current User:' , auth . currentUser ) ;
118
- await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
86
+ //await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
119
87
const cr = await signInWithEmailAndPassword ( auth , email , 'password' ) ;
120
88
121
- console . log ( 'signed In for totp' ) ;
122
89
const mfaUser = multiFactor ( cr . user ) ;
123
-
124
- console . log ( 'session info for: ' ) ;
125
-
126
-
90
+
127
91
session = await mfaUser . getSession ( ) ;
128
92
129
93
130
- console . log ( 'session' ) ;
131
- console . log ( JSON . stringify ( session ) ) ;
132
-
133
-
134
94
totpSecret = await TotpMultiFactorGenerator . generateSecret (
135
95
session
136
96
) ;
137
-
138
- console . log ( "**** totpSecret****" ) ;
139
-
140
- console . log ( totpSecret . secretKey ) ;
141
- console . log ( totpSecret . codeLength ) ;
142
- console . log ( totpSecret . codeIntervalSeconds ) ;
143
- console . log ( totpSecret . hashingAlgorithm ) ;
144
-
145
-
146
-
147
97
148
98
const totpVerificationCode = getTotpCode ( totpSecret . secretKey , totpSecret . codeIntervalSeconds , totpSecret . codeLength , totpSecret . hashingAlgorithm ) ;
149
99
150
100
const multiFactorAssertion = TotpMultiFactorGenerator . assertionForEnrollment (
151
101
totpSecret ,
152
102
totpVerificationCode
153
103
) ;
154
- console . log ( totpVerificationCode ) ;
155
-
156
104
await expect ( mfaUser . enroll ( multiFactorAssertion , displayName ) ) . to . be . fulfilled ;
157
105
158
106
await auth . signOut ( ) ;
@@ -163,38 +111,28 @@ describe(' Integration tests: Mfa TOTP', () => {
163
111
let session ;
164
112
let cr ;
165
113
let resolver ;
166
- console . log ( email ) ;
167
- console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
168
- await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
114
+ //await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
169
115
// Added a delay so that getTotpCode() actually generates a new totp code
170
116
await delay ( 30 * 1000 ) ;
171
117
try {
172
118
173
119
const userCredential = await signInWithEmailAndPassword ( auth , email , 'password' ) ;
174
120
175
- console . log ( 'success: ' , userCredential ) ;
176
-
177
121
throw new Error ( 'Signin should not have been successful' ) ;
178
122
179
123
} catch ( error ) {
180
124
181
125
182
- console . log ( 'error occured: ' , ( error as any ) . code ) ;
183
126
expect ( ( error as any ) . code ) . to . eql ( 'auth/multi-factor-auth-required' ) ;
184
127
185
128
resolver = getMultiFactorResolver ( auth , error as any ) ;
186
- console . log ( resolver . hints , totpSecret . secretKey ) ;
187
129
expect ( resolver . hints ) . to . have . length ( 1 ) ;
188
130
189
131
const totpVerificationCode = getTotpCode ( totpSecret . secretKey , totpSecret . codeIntervalSeconds , totpSecret . codeLength , totpSecret . hashingAlgorithm ) ;
190
- console . log ( totpVerificationCode , resolver . hints [ 0 ] . uid )
191
132
const assertion = TotpMultiFactorGenerator . assertionForSignIn (
192
133
resolver . hints [ 0 ] . uid ,
193
134
totpVerificationCode + '0'
194
135
) ;
195
-
196
- console . log ( assertion ) ;
197
-
198
136
199
137
await expect ( resolver . resolveSignIn ( assertion ) ) . to . be . rejectedWith ( 'auth/invalid-verification-code' ) ;
200
138
@@ -209,40 +147,31 @@ describe(' Integration tests: Mfa TOTP', () => {
209
147
210
148
let resolver ;
211
149
212
- console . log ( email ) ;
213
- console . log ( 'session info for: ' , getApp ( ) . options . projectId ) ;
214
-
215
- await expect ( createUserWithEmailAndPassword ( auth , email , 'password' ) ) . to . be . rejectedWith ( 'auth/email-already-in-use' ) ;
216
- // Added a delay so that getTotpCode() actually generates a new totp code
217
150
await delay ( 30 * 1000 ) ;
151
+
152
+ //await expect(createUserWithEmailAndPassword(auth, email, 'password')).to.be.rejectedWith('auth/email-already-in-use');
153
+ // Added a delay so that getTotpCode() actually generates a new totp code
154
+
218
155
try {
219
156
220
157
const userCredential = await signInWithEmailAndPassword ( auth , email , 'password' ) ;
221
158
222
- console . log ( 'success: ' , userCredential ) ;
223
159
224
160
throw new Error ( 'Signin should not have been successful' ) ;
225
161
226
162
} catch ( error ) {
227
163
228
-
229
- console . log ( 'error occured: ' , ( error as any ) . code ) ;
164
+ expect ( error ) . to . be . an . instanceOf ( FirebaseError ) ;
230
165
expect ( ( error as any ) . code ) . to . eql ( 'auth/multi-factor-auth-required' ) ;
231
166
232
167
resolver = getMultiFactorResolver ( auth , error as any ) ;
233
- console . log ( resolver . hints , totpSecret . secretKey ) ;
234
168
expect ( resolver . hints ) . to . have . length ( 1 ) ;
235
169
236
170
const totpVerificationCode = getTotpCode ( totpSecret . secretKey , totpSecret . codeIntervalSeconds , totpSecret . codeLength , totpSecret . hashingAlgorithm ) ;
237
- console . log ( totpVerificationCode , resolver . hints [ 0 ] . uid )
238
171
const assertion = TotpMultiFactorGenerator . assertionForSignIn (
239
172
resolver . hints [ 0 ] . uid ,
240
173
totpVerificationCode
241
- ) ;
242
-
243
- console . log ( assertion ) ;
244
-
245
-
174
+ ) ;
246
175
const userCredential = await resolver . resolveSignIn ( assertion ) ;
247
176
248
177
const mfaUser = multiFactor ( userCredential . user ) ;
0 commit comments