diff --git a/.github/workflows/integ_test_auth.yml b/.github/workflows/integ_test_auth.yml index e08a497376..1a76717c21 100644 --- a/.github/workflows/integ_test_auth.yml +++ b/.github/workflows/integ_test_auth.yml @@ -88,3 +88,28 @@ jobs: destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest sdk: watchsimulator xcode_path: '/Applications/Xcode_14.3.app' + + auth-ui-integration-test-iOS: + runs-on: macos-12 + environment: IntegrationTest + steps: + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b + with: + persist-credentials: false + + - name: Make directory + run: mkdir -p ~/.aws-amplify/amplify-ios/testconfiguration/ + + - name: Copy integration test resouces + uses: ./.github/composite_actions/download_test_configuration + with: + resource_subfolder: auth + aws_role_to_assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} + aws_region: ${{ secrets.AWS_REGION }} + aws_s3_bucket: ${{ secrets.AWS_S3_BUCKET_INTEG_V2 }} + + - name: Run Integration test + uses: ./.github/composite_actions/run_xcodebuild_test + with: + project_path: ./AmplifyPlugins/Auth/Tests/AuthHostedUIApp/ + scheme: AuthHostedUIApp diff --git a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/AuthUserAttributesTests/AuthUserAttributesTests.swift b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/AuthUserAttributesTests/AuthUserAttributesTests.swift index ba5d8d1dcd..f8695e2000 100644 --- a/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/AuthUserAttributesTests/AuthUserAttributesTests.swift +++ b/AmplifyPlugins/Auth/Tests/AuthHostApp/AuthIntegrationTests/AuthUserAttributesTests/AuthUserAttributesTests.swift @@ -124,6 +124,44 @@ class AuthUserAttributesTests: AWSAuthBaseTest { XCTFail("name attribute not found") } } + + /// - Given: A confirmed user + /// - When: + /// - I invoke Amplify.Auth.update with email attribute and then confirm the email attribute with an invalid code + /// - Then: + /// - The confirmation request should fail with a Auth service error + /// + func testSuccessfulUserAttributesConfirmation() async throws { + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + let updatedEmail = "\(username)@amazon.com" + + let didSucceed = try await AuthSignInHelper.registerAndSignInUser(username: username, + password: password, + email: defaultTestEmail) + XCTAssertTrue(didSucceed, "SignIn operation failed") + + let pluginOptions = AWSAuthUpdateUserAttributeOptions(metadata: ["mydata": "myvalue"]) + let options = AuthUpdateUserAttributeRequest.Options(pluginOptions: pluginOptions) + let updateResult = try await Amplify.Auth.update(userAttribute: AuthUserAttribute(.email, value: updatedEmail), options: options) + + switch updateResult.nextStep { + case .confirmAttributeWithCode(let deliveryDetails, let info): + print("Confirm the attribute with details send to - \(deliveryDetails) \(String(describing: info))") + case .done: + print("Update completed") + } + + do { + try await Amplify.Auth.confirm(userAttribute: .email, confirmationCode: "123") + XCTFail("User attribute confirmation unexpectedly succeeded") + } catch { + guard case AuthError.service(_, _, _) = error else { + XCTFail("Should throw service error") + return + } + } + } /// Test resending code for the user's updated email attribute. /// Internally, Cognito's `GetUserAttributeVerificationCode` API will be called with metadata as clientMetadata. diff --git a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp.xcodeproj/project.pbxproj b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp.xcodeproj/project.pbxproj index e8bd62dacf..f99b0aa800 100644 --- a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp.xcodeproj/project.pbxproj +++ b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp.xcodeproj/project.pbxproj @@ -7,8 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - B41080E1291ACF7E00297354 /* AuthHostedUIAppUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B41080E0291ACF7E00297354 /* AuthHostedUIAppUITests.swift */; }; - B41080E3291ACF7E00297354 /* AuthHostedUIAppUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B41080E2291ACF7E00297354 /* AuthHostedUIAppUITestsLaunchTests.swift */; }; B41080ED291AD02500297354 /* Amplify in Frameworks */ = {isa = PBXBuildFile; productRef = B41080EC291AD02500297354 /* Amplify */; }; B41080EF291AD02500297354 /* AWSCognitoAuthPlugin in Frameworks */ = {isa = PBXBuildFile; productRef = B41080EE291AD02500297354 /* AWSCognitoAuthPlugin */; }; B41080F5291AD10700297354 /* ConfigurationHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B41080F4291AD10700297354 /* ConfigurationHelper.swift */; }; @@ -39,8 +37,6 @@ /* Begin PBXFileReference section */ B41080DE291ACF7E00297354 /* AuthHostedUIAppUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AuthHostedUIAppUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - B41080E0291ACF7E00297354 /* AuthHostedUIAppUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthHostedUIAppUITests.swift; sourceTree = ""; }; - B41080E2291ACF7E00297354 /* AuthHostedUIAppUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthHostedUIAppUITestsLaunchTests.swift; sourceTree = ""; }; B41080EA291ACFDB00297354 /* amplify-swift */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "amplify-swift"; path = ../../../..; sourceTree = ""; }; B41080F4291AD10700297354 /* ConfigurationHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationHelper.swift; sourceTree = ""; }; B41080F7291AD4D600297354 /* HostedUISignInTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostedUISignInTests.swift; sourceTree = ""; }; @@ -86,8 +82,6 @@ B4B978CB291C9C07005B465D /* UITestCase.swift */, B4B978CA291C9BE5005B465D /* Screen */, B41080F6291AD4C200297354 /* AuthenticationTest */, - B41080E0291ACF7E00297354 /* AuthHostedUIAppUITests.swift */, - B41080E2291ACF7E00297354 /* AuthHostedUIAppUITestsLaunchTests.swift */, ); path = AuthHostedUIAppUITests; sourceTree = ""; @@ -312,11 +306,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - B41080E1291ACF7E00297354 /* AuthHostedUIAppUITests.swift in Sources */, B4B978CE291C9C35005B465D /* SignInScreen.swift in Sources */, B4B978CC291C9C07005B465D /* UITestCase.swift in Sources */, B41080F8291AD4D600297354 /* HostedUISignInTests.swift in Sources */, - B41080E3291ACF7E00297354 /* AuthHostedUIAppUITestsLaunchTests.swift in Sources */, B4B978D0291CA085005B465D /* SignUpScreen.swift in Sources */, B4B978D4291DB1D1005B465D /* AuthenticatedScreen.swift in Sources */, ); diff --git a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp.xcodeproj/xcshareddata/xcschemes/AuthHostedUIApp.xcscheme b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp.xcodeproj/xcshareddata/xcschemes/AuthHostedUIApp.xcscheme new file mode 100644 index 0000000000..b919f7e960 --- /dev/null +++ b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp.xcodeproj/xcshareddata/xcschemes/AuthHostedUIApp.xcscheme @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp/Utils/ConfigurationHelper.swift b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp/Utils/ConfigurationHelper.swift index 10e34a347b..87613b4bdb 100644 --- a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp/Utils/ConfigurationHelper.swift +++ b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIApp/Utils/ConfigurationHelper.swift @@ -11,7 +11,6 @@ import Amplify class ConfigurationHelper { static func retrieveAmplifyConfiguration(forResource: String) throws -> AmplifyConfiguration { - let data = try retrieve(forResource: forResource) return try Self.decodeAmplifyConfiguration(from: data) } diff --git a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIAppUITests/AuthHostedUIAppUITests.swift b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIAppUITests/AuthHostedUIAppUITests.swift deleted file mode 100644 index 908e60b6f6..0000000000 --- a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIAppUITests/AuthHostedUIAppUITests.swift +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import XCTest - -final class AuthHostedUIAppUITests: XCTestCase { - - override func setUpWithError() throws { - continueAfterFailure = false - } - - override func tearDownWithError() throws { - } - - func testExample() throws { - // UI tests must launch the application that they test. - let app = XCUIApplication() - app.launch() - - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testLaunchPerformance() throws { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { - // This measures how long it takes to launch your application. - measure(metrics: [XCTApplicationLaunchMetric()]) { - XCUIApplication().launch() - } - } - } -} diff --git a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIAppUITests/AuthHostedUIAppUITestsLaunchTests.swift b/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIAppUITests/AuthHostedUIAppUITestsLaunchTests.swift deleted file mode 100644 index 9fcf793130..0000000000 --- a/AmplifyPlugins/Auth/Tests/AuthHostedUIApp/AuthHostedUIAppUITests/AuthHostedUIAppUITestsLaunchTests.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// -import XCTest - -final class AuthHostedUIAppUITestsLaunchTests: XCTestCase { - - override class var runsForEachTargetApplicationUIConfiguration: Bool { - true - } - - override func setUpWithError() throws { - continueAfterFailure = false - } - - func testLaunch() throws { - let app = XCUIApplication() - app.launch() - - // Insert steps here to perform after app launch but before taking a screenshot, - // such as logging into a test account or navigating somewhere in the app - - let attachment = XCTAttachment(screenshot: app.screenshot()) - attachment.name = "Launch Screen" - attachment.lifetime = .keepAlways - add(attachment) - } -}