Skip to content

Commit

Permalink
test(auth): add additional integration test cases (#3243)
Browse files Browse the repository at this point in the history
* test(auth): add test for user attribute confirmation

* test(auth): add Auth UI integration tests

* test integration workflow

* reset integ workflow

* update unit test comment
  • Loading branch information
phantumcode authored Sep 29, 2023
1 parent 12cd18c commit 74f6f83
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 75 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/integ_test_auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
B41080E2291ACF7E00297354 /* AuthHostedUIAppUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthHostedUIAppUITestsLaunchTests.swift; sourceTree = "<group>"; };
B41080EA291ACFDB00297354 /* amplify-swift */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "amplify-swift"; path = ../../../..; sourceTree = "<group>"; };
B41080F4291AD10700297354 /* ConfigurationHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigurationHelper.swift; sourceTree = "<group>"; };
B41080F7291AD4D600297354 /* HostedUISignInTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostedUISignInTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,8 +82,6 @@
B4B978CB291C9C07005B465D /* UITestCase.swift */,
B4B978CA291C9BE5005B465D /* Screen */,
B41080F6291AD4C200297354 /* AuthenticationTest */,
B41080E0291ACF7E00297354 /* AuthHostedUIAppUITests.swift */,
B41080E2291ACF7E00297354 /* AuthHostedUIAppUITestsLaunchTests.swift */,
);
path = AuthHostedUIAppUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B4EB96A7291ACF4400B73755"
BuildableName = "AuthHostedUIApp.app"
BlueprintName = "AuthHostedUIApp"
ReferencedContainer = "container:AuthHostedUIApp.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B41080DD291ACF7E00297354"
BuildableName = "AuthHostedUIAppUITests.xctest"
BlueprintName = "AuthHostedUIAppUITests"
ReferencedContainer = "container:AuthHostedUIApp.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B4EB96A7291ACF4400B73755"
BuildableName = "AuthHostedUIApp.app"
BlueprintName = "AuthHostedUIApp"
ReferencedContainer = "container:AuthHostedUIApp.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "B4EB96A7291ACF4400B73755"
BuildableName = "AuthHostedUIApp.app"
BlueprintName = "AuthHostedUIApp"
ReferencedContainer = "container:AuthHostedUIApp.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 74f6f83

Please sign in to comment.