From 44a1171a5bfd8004d7195c22a8478682ee63a9c0 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <6162866+harsh62@users.noreply.github.com> Date: Wed, 2 Oct 2024 21:48:29 -0400 Subject: [PATCH] integration tests wave 2 --- .../AuthHostApp.xcodeproj/project.pbxproj | 7 +++ .../EmailMFATests/EmailMFAOnlyTests.swift | 48 +++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthHostApp.xcodeproj/project.pbxproj b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthHostApp.xcodeproj/project.pbxproj index 14a1cccaff..193420021f 100644 --- a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthHostApp.xcodeproj/project.pbxproj +++ b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthHostApp.xcodeproj/project.pbxproj @@ -68,6 +68,7 @@ 487C403F2CADE8DA009CF221 /* EmailMFAOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 487C403E2CADE88F009CF221 /* EmailMFAOnlyTests.swift */; }; 487C40402CADE8DA009CF221 /* EmailMFAOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 487C403E2CADE88F009CF221 /* EmailMFAOnlyTests.swift */; }; 487C40412CADE8DA009CF221 /* EmailMFAOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 487C403E2CADE88F009CF221 /* EmailMFAOnlyTests.swift */; }; + 487C40432CAE2905009CF221 /* AWSAPIPlugin in Frameworks */ = {isa = PBXBuildFile; productRef = 487C40422CAE2905009CF221 /* AWSAPIPlugin */; }; 48916F382A412B2800E3E1B1 /* TOTPSetupWhenAuthenticatedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48916F372A412B2800E3E1B1 /* TOTPSetupWhenAuthenticatedTests.swift */; }; 48916F3A2A412CEE00E3E1B1 /* TOTPHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48916F392A412CEE00E3E1B1 /* TOTPHelper.swift */; }; 48916F3C2A42333E00E3E1B1 /* MFAPreferenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48916F3B2A42333E00E3E1B1 /* MFAPreferenceTests.swift */; }; @@ -258,6 +259,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 487C40432CAE2905009CF221 /* AWSAPIPlugin in Frameworks */, 681B769A2A3CBA97004B59D9 /* Amplify in Frameworks */, 681B769C2A3CBA97004B59D9 /* AWSCognitoAuthPlugin in Frameworks */, ); @@ -598,6 +600,7 @@ packageProductDependencies = ( 681B76992A3CBA97004B59D9 /* Amplify */, 681B769B2A3CBA97004B59D9 /* AWSCognitoAuthPlugin */, + 487C40422CAE2905009CF221 /* AWSAPIPlugin */, ); productName = "AuthWatchApp Watch App"; productReference = 681B76802A3CB86B004B59D9 /* AuthWatchApp.app */; @@ -1510,6 +1513,10 @@ isa = XCSwiftPackageProductDependency; productName = AWSAPIPlugin; }; + 487C40422CAE2905009CF221 /* AWSAPIPlugin */ = { + isa = XCSwiftPackageProductDependency; + productName = AWSAPIPlugin; + }; 681B76992A3CBA97004B59D9 /* Amplify */ = { isa = XCSwiftPackageProductDependency; productName = Amplify; diff --git a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/MFATests/EmailMFATests/EmailMFAOnlyTests.swift b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/MFATests/EmailMFATests/EmailMFAOnlyTests.swift index b0f5e789d9..3ace817910 100644 --- a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/MFATests/EmailMFATests/EmailMFAOnlyTests.swift +++ b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/MFATests/EmailMFATests/EmailMFAOnlyTests.swift @@ -12,12 +12,12 @@ import AWSAPIPlugin // MFA Required // - Email -class EmailMFAOnlyTests: AWSAuthBaseTest { +class EmailMFARequiredTests: AWSAuthBaseTest { override func setUp() async throws { onlyUseGen2Configuration = true // Use a custom configuration these tests - amplifyOutputsFile = "testconfiguration/amplify_outputs" + amplifyOutputsFile = "testconfiguration/AWSCognitoEmailMFARequiredTests-amplify_outputs" let awsApiPlugin = AWSAPIPlugin() try Amplify.add(plugin: awsApiPlugin) @@ -38,15 +38,20 @@ class EmailMFAOnlyTests: AWSAuthBaseTest { /// - I invoke signIn with valid values /// - Then: /// - I should get a .continueSignInWithEmailMFASetup response - /// + /// - When: + /// - I invoke confirm signIn with valid values, + /// - Then: + /// - With series of challenges, sign in should succeed //Requires only Email MFA to be enabled - func disabled_testSuccessfulEmailMFASetupStep() async { + func testSuccessfulEmailMFASetupStep() async { do { + createMFASubscription() + let uniqueId = UUID().uuidString let username = "integTest\(uniqueId)" let password = "Pp123@\(uniqueId)" - + _ = try await AuthSignInHelper.signUpUserReturningResult( username: username, password: password) @@ -61,7 +66,40 @@ class EmailMFAOnlyTests: AWSAuthBaseTest { XCTFail("Result should be .continueSignInWithEmailMFASetup for next step, instead got: \(result.nextStep)") return } + + // Step 2: pass an email to setup + var confirmSignInResult = try await Amplify.Auth.confirmSignIn( + challengeResponse: username + "@integTest.com") + guard case .confirmSignInWithEmailMFACode(let deliveryDetails) = confirmSignInResult.nextStep else { + XCTFail("Result should be .continueSignInWithEmailMFASetup but got: \(confirmSignInResult.nextStep)") + return + } + if case .email(let destination) = deliveryDetails.destination { + XCTAssertNotNil(destination) + } else { + XCTFail("Destination should be email") + } + + XCTAssertFalse(result.isSignedIn, "Signin result should be complete") + + // step 3: confirm sign in + guard let mfaCode = try await waitForMFACode(for: username.lowercased()) else { + XCTFail("failed to retrieve the mfa code") + return + } + confirmSignInResult = try await Amplify.Auth.confirmSignIn( + challengeResponse: mfaCode, + options: .init()) + guard case .done = confirmSignInResult.nextStep else { + XCTFail("Result should be .done for next step") + return + } + XCTAssertTrue(confirmSignInResult.isSignedIn, "Signin result should NOT be complete") XCTAssertFalse(result.isSignedIn, "Signin result should be complete") + + // email should get added to the account + let attributes = try await Amplify.Auth.fetchUserAttributes() + XCTAssertEqual(attributes.first(where: { $0.key == .email})?.value, username + "@integTest.com") } catch { XCTFail("Received failure with error \(error)") }