@@ -419,4 +419,135 @@ class VerifyPasswordSRPTests: XCTestCase {
419
419
await waitForExpectations ( timeout: 0.1 )
420
420
}
421
421
422
+ // /// Test verify password retry on device not found
423
+ // ///
424
+ // /// - Given: VerifyPasswordSRP action with mocked cognito client and configuration
425
+ // /// - When:
426
+ // /// - I invoke the action with valid input and mock empty device not found error from Cognito
427
+ // /// - Then:
428
+ // /// - Should send an event with retryRespondPasswordVerifier
429
+ // ///
430
+ // func testPasswordVerifierWithDeviceNotFound() async {
431
+ //
432
+ // let identityProviderFactory: CognitoFactory = {
433
+ // MockIdentityProvider(
434
+ // mockRespondToAuthChallengeResponse: { _ in
435
+ // throw RespondToAuthChallengeOutputError.resourceNotFoundException(
436
+ // ResourceNotFoundException()
437
+ // )
438
+ // })
439
+ // }
440
+ //
441
+ // let environment = Defaults.makeDefaultAuthEnvironment(
442
+ // userPoolFactory: identityProviderFactory)
443
+ //
444
+ // let data = InitiateAuthOutputResponse.validTestData
445
+ // let action = VerifyPasswordSRP(stateData: SRPStateData.testData,
446
+ // authResponse: data)
447
+ //
448
+ // let passwordVerifierError = expectation(description: "passwordVerifierError")
449
+ //
450
+ // let dispatcher = MockDispatcher { event in
451
+ // defer { passwordVerifierError.fulfill() }
452
+ //
453
+ // guard let event = event as? SignInEvent else {
454
+ // XCTFail("Expected event to be SignInEvent but got \(event)")
455
+ // return
456
+ // }
457
+ //
458
+ // guard case .retryRespondPasswordVerifier = event.eventType
459
+ // else {
460
+ // XCTFail("Should receive retryRespondPasswordVerifier")
461
+ // return
462
+ // }
463
+ // }
464
+ //
465
+ // await action.execute(withDispatcher: dispatcher, environment: environment)
466
+ // await waitForExpectations(timeout: 0.1)
467
+ // }
468
+
469
+ /// Test successful response from the VerifyPasswordSRP for confirmDevice
470
+ ///
471
+ /// - Given: VerifyPasswordSRP action with mocked cognito client and configuration
472
+ /// - When:
473
+ /// - I invoke the action with valid input and mock new device
474
+ /// - Then:
475
+ /// - Should send an event confirmDevice
476
+ ///
477
+ func testRespondToAuthChallengeWithConfirmDevice( ) async {
478
+ let identityProviderFactory : CognitoFactory = {
479
+ MockIdentityProvider (
480
+ mockRespondToAuthChallengeResponse: { _ in
481
+ return RespondToAuthChallengeOutputResponse . testDataWithNewDevice ( )
482
+ } )
483
+ }
484
+
485
+ let environment = Defaults . makeDefaultAuthEnvironment (
486
+ userPoolFactory: identityProviderFactory)
487
+
488
+ let data = InitiateAuthOutputResponse . validTestData
489
+ let action = VerifyPasswordSRP ( stateData: SRPStateData . testData,
490
+ authResponse: data)
491
+
492
+ let passwordVerifierCompletion = expectation (
493
+ description: " passwordVerifierCompletion " )
494
+
495
+ let dispatcher = MockDispatcher { event in
496
+ guard let event = event as? SignInEvent else {
497
+ XCTFail ( " Expected event to be SignInEvent but got \( event) " )
498
+ return
499
+ }
500
+
501
+ if case . confirmDevice( let signedInData) = event. eventType {
502
+ XCTAssertNotNil ( signedInData)
503
+ passwordVerifierCompletion. fulfill ( )
504
+ }
505
+ }
506
+
507
+ await action. execute ( withDispatcher: dispatcher, environment: environment)
508
+ await waitForExpectations ( timeout: 0.1 )
509
+ }
510
+
511
+ /// Test successful response from the VerifyPasswordSRP for verifyDevice
512
+ ///
513
+ /// - Given: VerifyPasswordSRP action with mocked cognito client and configuration
514
+ /// - When:
515
+ /// - I invoke the action with valid input and mock verify device as response
516
+ /// - Then:
517
+ /// - Should send an event initiateDeviceSRP
518
+ ///
519
+ func testRespondToAuthChallengeWithVerifyDevice( ) async {
520
+ let identityProviderFactory : CognitoFactory = {
521
+ MockIdentityProvider (
522
+ mockRespondToAuthChallengeResponse: { _ in
523
+ return RespondToAuthChallengeOutputResponse . testDataWithVerifyDevice ( )
524
+ } )
525
+ }
526
+
527
+ let environment = Defaults . makeDefaultAuthEnvironment (
528
+ userPoolFactory: identityProviderFactory)
529
+
530
+ let data = InitiateAuthOutputResponse . validTestData
531
+ let action = VerifyPasswordSRP ( stateData: SRPStateData . testData,
532
+ authResponse: data)
533
+
534
+ let passwordVerifierCompletion = expectation (
535
+ description: " passwordVerifierCompletion " )
536
+
537
+ let dispatcher = MockDispatcher { event in
538
+ guard let event = event as? SignInEvent else {
539
+ XCTFail ( " Expected event to be SignInEvent but got \( event) " )
540
+ return
541
+ }
542
+
543
+ if case . initiateDeviceSRP( _, let response) = event. eventType {
544
+ XCTAssertNotNil ( response)
545
+ passwordVerifierCompletion. fulfill ( )
546
+ }
547
+ }
548
+
549
+ await action. execute ( withDispatcher: dispatcher, environment: environment)
550
+ await waitForExpectations ( timeout: 0.1 )
551
+ }
552
+
422
553
}
0 commit comments