@@ -122,6 +122,55 @@ describe('confirmSignIn API happy path cases', () => {
122
122
mockedGetCurrentUser . mockClear ( ) ;
123
123
} ) ;
124
124
125
+ test ( `confirmSignIn with EMAIL_OTP ChallengeName` , async ( ) => {
126
+ Amplify . configure ( {
127
+ Auth : authConfig ,
128
+ } ) ;
129
+
130
+ const handleUserSRPAuthflowSpy = jest
131
+ . spyOn ( signInHelpers , 'handleUserSRPAuthFlow' )
132
+ . mockImplementationOnce (
133
+ async ( ) : Promise < RespondToAuthChallengeCommandOutput > => ( {
134
+ ChallengeName : 'EMAIL_OTP' ,
135
+ Session : '1234234232' ,
136
+ $metadata : { } ,
137
+ ChallengeParameters : {
138
+ CODE_DELIVERY_DELIVERY_MEDIUM : 'EMAIL' ,
139
+ CODE_DELIVERY_DESTINATION : 'j***@a***' ,
140
+ } ,
141
+ } ) ,
142
+ ) ;
143
+
144
+ const signInResult = await signIn ( { username, password } ) ;
145
+
146
+ expect ( signInResult ) . toEqual ( {
147
+ isSignedIn : false ,
148
+ nextStep : {
149
+ signInStep : 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE' ,
150
+ codeDeliveryDetails : {
151
+ deliveryMedium : 'EMAIL' ,
152
+ destination : 'j***@a***' ,
153
+ } ,
154
+ } ,
155
+ } ) ;
156
+
157
+ const confirmSignInResult = await confirmSignIn ( {
158
+ challengeResponse : '123456' ,
159
+ } ) ;
160
+
161
+ expect ( confirmSignInResult ) . toEqual ( {
162
+ isSignedIn : true ,
163
+ nextStep : {
164
+ signInStep : 'DONE' ,
165
+ } ,
166
+ } ) ;
167
+
168
+ expect ( handleChallengeNameSpy ) . toHaveBeenCalledTimes ( 1 ) ;
169
+ expect ( handleUserSRPAuthflowSpy ) . toHaveBeenCalledTimes ( 1 ) ;
170
+
171
+ handleUserSRPAuthflowSpy . mockClear ( ) ;
172
+ } ) ;
173
+
125
174
test ( `confirmSignIn tests MFA_SETUP challengeName` , async ( ) => {
126
175
Amplify . configure ( {
127
176
Auth : authConfig ,
@@ -162,7 +211,7 @@ describe('confirmSignIn API happy path cases', () => {
162
211
handleUserSRPAuthflowSpy . mockClear ( ) ;
163
212
} ) ;
164
213
165
- test ( `confirmSignIn tests SELECT_MFA_TYPE challengeName ` , async ( ) => {
214
+ test ( `confirmSignIn with SELECT_MFA_TYPE challengeName and SMS response ` , async ( ) => {
166
215
Amplify . configure ( {
167
216
Auth : authConfig ,
168
217
} ) ;
@@ -175,7 +224,7 @@ describe('confirmSignIn API happy path cases', () => {
175
224
Session : '1234234232' ,
176
225
$metadata : { } ,
177
226
ChallengeParameters : {
178
- MFAS_CAN_CHOOSE : '["SMS_MFA","SOFTWARE_TOKEN_MFA"]' ,
227
+ MFAS_CAN_CHOOSE : '["SMS_MFA","SOFTWARE_TOKEN_MFA", "EMAIL_OTP" ]' ,
179
228
} ,
180
229
} ) ,
181
230
) ;
@@ -204,7 +253,7 @@ describe('confirmSignIn API happy path cases', () => {
204
253
isSignedIn : false ,
205
254
nextStep : {
206
255
signInStep : 'CONTINUE_SIGN_IN_WITH_MFA_SELECTION' ,
207
- allowedMFATypes : [ 'SMS' , 'TOTP' ] ,
256
+ allowedMFATypes : [ 'SMS' , 'TOTP' , 'EMAIL' ] ,
208
257
} ,
209
258
} ) ;
210
259
@@ -226,6 +275,121 @@ describe('confirmSignIn API happy path cases', () => {
226
275
handleUserSRPAuthflowSpy . mockClear ( ) ;
227
276
} ) ;
228
277
278
+ test ( `confirmSignIn with SELECT_MFA_TYPE challengeName and TOTP response` , async ( ) => {
279
+ Amplify . configure ( {
280
+ Auth : authConfig ,
281
+ } ) ;
282
+
283
+ const handleUserSRPAuthflowSpy = jest
284
+ . spyOn ( signInHelpers , 'handleUserSRPAuthFlow' )
285
+ . mockImplementationOnce (
286
+ async ( ) : Promise < RespondToAuthChallengeCommandOutput > => ( {
287
+ ChallengeName : 'SELECT_MFA_TYPE' ,
288
+ Session : '1234234232' ,
289
+ $metadata : { } ,
290
+ ChallengeParameters : {
291
+ MFAS_CAN_CHOOSE : '["SMS_MFA","SOFTWARE_TOKEN_MFA", "EMAIL_OTP"]' ,
292
+ } ,
293
+ } ) ,
294
+ ) ;
295
+
296
+ handleChallengeNameSpy . mockImplementationOnce (
297
+ async ( ) : Promise < RespondToAuthChallengeCommandOutput > => ( {
298
+ ChallengeName : 'SOFTWARE_TOKEN_MFA' ,
299
+ $metadata : { } ,
300
+ Session : '123456789' ,
301
+ ChallengeParameters : { } ,
302
+ } ) ,
303
+ ) ;
304
+
305
+ const signInResult = await signIn ( { username, password } ) ;
306
+
307
+ expect ( signInResult ) . toEqual ( {
308
+ isSignedIn : false ,
309
+ nextStep : {
310
+ signInStep : 'CONTINUE_SIGN_IN_WITH_MFA_SELECTION' ,
311
+ allowedMFATypes : [ 'SMS' , 'TOTP' , 'EMAIL' ] ,
312
+ } ,
313
+ } ) ;
314
+
315
+ const confirmSignInResult = await confirmSignIn ( {
316
+ challengeResponse : 'TOTP' ,
317
+ } ) ;
318
+
319
+ expect ( confirmSignInResult ) . toEqual ( {
320
+ isSignedIn : false ,
321
+ nextStep : {
322
+ signInStep : 'CONFIRM_SIGN_IN_WITH_TOTP_CODE' ,
323
+ } ,
324
+ } ) ;
325
+
326
+ expect ( handleChallengeNameSpy ) . toHaveBeenCalledTimes ( 1 ) ;
327
+ expect ( handleUserSRPAuthflowSpy ) . toHaveBeenCalledTimes ( 1 ) ;
328
+
329
+ handleUserSRPAuthflowSpy . mockClear ( ) ;
330
+ } ) ;
331
+
332
+ test ( `confirmSignIn with SELECT_MFA_TYPE challengeName and EMAIL response` , async ( ) => {
333
+ Amplify . configure ( {
334
+ Auth : authConfig ,
335
+ } ) ;
336
+
337
+ const handleUserSRPAuthflowSpy = jest
338
+ . spyOn ( signInHelpers , 'handleUserSRPAuthFlow' )
339
+ . mockImplementationOnce (
340
+ async ( ) : Promise < RespondToAuthChallengeCommandOutput > => ( {
341
+ ChallengeName : 'SELECT_MFA_TYPE' ,
342
+ Session : '1234234232' ,
343
+ $metadata : { } ,
344
+ ChallengeParameters : {
345
+ MFAS_CAN_CHOOSE : '["SMS_MFA","SOFTWARE_TOKEN_MFA", "EMAIL_OTP"]' ,
346
+ } ,
347
+ } ) ,
348
+ ) ;
349
+
350
+ handleChallengeNameSpy . mockImplementationOnce (
351
+ async ( ) : Promise < RespondToAuthChallengeCommandOutput > => ( {
352
+ ChallengeName : 'EMAIL_OTP' ,
353
+ $metadata : { } ,
354
+ Session : '1234234232' ,
355
+ ChallengeParameters : {
356
+ CODE_DELIVERY_DELIVERY_MEDIUM : 'EMAIL' ,
357
+ CODE_DELIVERY_DESTINATION : 'j***@a***' ,
358
+ } ,
359
+ } ) ,
360
+ ) ;
361
+
362
+ const signInResult = await signIn ( { username, password } ) ;
363
+
364
+ expect ( signInResult ) . toEqual ( {
365
+ isSignedIn : false ,
366
+ nextStep : {
367
+ signInStep : 'CONTINUE_SIGN_IN_WITH_MFA_SELECTION' ,
368
+ allowedMFATypes : [ 'SMS' , 'TOTP' , 'EMAIL' ] ,
369
+ } ,
370
+ } ) ;
371
+
372
+ const confirmSignInResult = await confirmSignIn ( {
373
+ challengeResponse : 'EMAIL' ,
374
+ } ) ;
375
+
376
+ expect ( confirmSignInResult ) . toEqual ( {
377
+ isSignedIn : false ,
378
+ nextStep : {
379
+ signInStep : 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE' ,
380
+ codeDeliveryDetails : {
381
+ deliveryMedium : 'EMAIL' ,
382
+ destination : 'j***@a***' ,
383
+ } ,
384
+ } ,
385
+ } ) ;
386
+
387
+ expect ( handleChallengeNameSpy ) . toHaveBeenCalledTimes ( 1 ) ;
388
+ expect ( handleUserSRPAuthflowSpy ) . toHaveBeenCalledTimes ( 1 ) ;
389
+
390
+ handleUserSRPAuthflowSpy . mockClear ( ) ;
391
+ } ) ;
392
+
229
393
test ( 'handleChallengeName should be called with clientMetadata and usersub' , async ( ) => {
230
394
Amplify . configure ( {
231
395
Auth : authConfig ,
0 commit comments