Skip to content

Commit

Permalink
integration tests wave 2
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Oct 3, 2024
1 parent 18a8c70 commit 44a1171
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -258,6 +259,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
487C40432CAE2905009CF221 /* AWSAPIPlugin in Frameworks */,
681B769A2A3CBA97004B59D9 /* Amplify in Frameworks */,
681B769C2A3CBA97004B59D9 /* AWSCognitoAuthPlugin in Frameworks */,
);
Expand Down Expand Up @@ -598,6 +600,7 @@
packageProductDependencies = (
681B76992A3CBA97004B59D9 /* Amplify */,
681B769B2A3CBA97004B59D9 /* AWSCognitoAuthPlugin */,
487C40422CAE2905009CF221 /* AWSAPIPlugin */,
);
productName = "AuthWatchApp Watch App";
productReference = 681B76802A3CB86B004B59D9 /* AuthWatchApp.app */;
Expand Down Expand Up @@ -1510,6 +1513,10 @@
isa = XCSwiftPackageProductDependency;
productName = AWSAPIPlugin;
};
487C40422CAE2905009CF221 /* AWSAPIPlugin */ = {
isa = XCSwiftPackageProductDependency;
productName = AWSAPIPlugin;
};
681B76992A3CBA97004B59D9 /* Amplify */ = {
isa = XCSwiftPackageProductDependency;
productName = Amplify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)")
}
Expand Down

0 comments on commit 44a1171

Please sign in to comment.