@@ -24,7 +24,10 @@ import * as mockFetch from '../../../test/helpers/mock_fetch';
24
24
import { Endpoint } from '../../api' ;
25
25
import { MultiFactorSessionImpl } from '../../mfa/mfa_session' ;
26
26
import { StartTotpMfaEnrollmentResponse } from '../../api/account_management/mfa' ;
27
- import { FinalizeMfaResponse } from '../../api/authentication/mfa' ;
27
+ import {
28
+ FinalizeMfaResponse ,
29
+ StartTotpMfaSignInResponse
30
+ } from '../../api/authentication/mfa' ;
28
31
import {
29
32
TotpMultiFactorAssertionImpl ,
30
33
TotpMultiFactorGenerator ,
@@ -34,6 +37,7 @@ import { FactorId } from '../../model/public_types';
34
37
import { AuthErrorCode } from '../../core/errors' ;
35
38
import { AppName } from '../../model/auth' ;
36
39
import { _castAuth } from '../../core/auth/auth_impl' ;
40
+ import { MultiFactorAssertionImpl } from '../mfa_assertion' ;
37
41
38
42
use ( chaiAsPromised ) ;
39
43
@@ -208,6 +212,84 @@ describe('core/mfa/totp/assertions/TotpMultiFactorAssertionImpl', () => {
208
212
} ) ;
209
213
} ) ;
210
214
215
+ describe ( 'Testing signin Flow' , ( ) => {
216
+ let auth : TestAuth ;
217
+ let assertion : MultiFactorAssertionImpl ;
218
+ let totpSignInResponse : StartTotpMfaSignInResponse ;
219
+ let session : MultiFactorSessionImpl ;
220
+ beforeEach ( async ( ) => {
221
+ mockFetch . setUp ( ) ;
222
+ auth = await testAuth ( ) ;
223
+ session = MultiFactorSessionImpl . _fromMfaPendingCredential (
224
+ 'mfa-pending-credential'
225
+ ) ;
226
+ } ) ;
227
+ afterEach ( mockFetch . tearDown ) ;
228
+
229
+ it ( 'should finalize mfa signin for totp' , async ( ) => {
230
+ totpSignInResponse = {
231
+ verificationCode : '123456' ,
232
+ idToken : 'final-id-token' ,
233
+ refreshToken : 'refresh-token'
234
+ } as any ;
235
+ assertion = TotpMultiFactorGenerator . assertionForSignIn (
236
+ 'enrollment-id' ,
237
+ '123456'
238
+ ) as any ;
239
+
240
+ const mock = mockEndpoint (
241
+ Endpoint . FINALIZE_MFA_SIGN_IN ,
242
+ totpSignInResponse
243
+ ) ;
244
+
245
+ const response = await assertion . _process ( auth , session ) ;
246
+
247
+ expect ( response ) . to . eql ( totpSignInResponse ) ;
248
+
249
+ expect ( mock . calls [ 0 ] . request ) . to . eql ( {
250
+ mfaPendingCredential : 'mfa-pending-credential' ,
251
+ mfaEnrollmentId : 'enrollment-id' ,
252
+ totpVerificationInfo : {
253
+ verificationCode : '123456'
254
+ }
255
+ } ) ;
256
+ } ) ;
257
+
258
+ it ( 'should throw Firebase Error if enrollment-id is undefined' , async ( ) => {
259
+ let _response : FinalizeMfaResponse ;
260
+ totpSignInResponse = {
261
+ verificationCode : '123456' ,
262
+ idToken : 'final-id-token' ,
263
+ refreshToken : 'refresh-token'
264
+ } as any ;
265
+ assertion = TotpMultiFactorGenerator . assertionForSignIn (
266
+ undefined as any ,
267
+ '123456'
268
+ ) as any ;
269
+
270
+ await expect ( assertion . _process ( auth , session ) ) . to . be . rejectedWith (
271
+ 'auth/argument-error'
272
+ ) ;
273
+ } ) ;
274
+
275
+ it ( 'should throw Firebase Error if otp is undefined' , async ( ) => {
276
+ let _response : FinalizeMfaResponse ;
277
+ totpSignInResponse = {
278
+ verificationCode : '123456' ,
279
+ idToken : 'final-id-token' ,
280
+ refreshToken : 'refresh-token'
281
+ } as any ;
282
+ assertion = TotpMultiFactorGenerator . assertionForSignIn (
283
+ 'enrollment-id' ,
284
+ undefined as any
285
+ ) as any ;
286
+
287
+ await expect ( assertion . _process ( auth , session ) ) . to . be . rejectedWith (
288
+ 'auth/argument-error'
289
+ ) ;
290
+ } ) ;
291
+ } ) ;
292
+
211
293
describe ( 'core/mfa/assertions/totp/TotpSecret' , async ( ) => {
212
294
const serverResponse : StartTotpMfaEnrollmentResponse = {
213
295
totpSessionInfo : {
0 commit comments