Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Improving WebAuthn integ tests #3940

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -19,9 +19,6 @@ final class AuthWebAuthnAppUITests: XCTestCase {
private var deleteButton: XCUIElement!
private var deleteUserButton: XCUIElement!
private var springboard: XCUIApplication!
private var continueButton: XCUIElement! {
springboard.otherElements["ASAuthorizationControllerContinueButton"]
}

private lazy var deviceIdentifier: String = {
let paths = Bundle.main.bundleURL.pathComponents
@@ -81,35 +78,36 @@ final class AuthWebAuthnAppUITests: XCTestCase {
}

guard associateAttempt else {
XCTFail("Failed to trigger the Associate WebAuthn Credential workflow")
XCTFail("Failed to trigger the Associate WebAuthn Credential workflow: \(lastResult)")
return
}

// Wait for the "Continue" button to appear in the FaceID popover and tap it
guard continueButton.waitForExistence(timeout: timeout) else {
XCTFail("Failed to find 'Continue' button")
let associateContinueButton = springboard.otherElements["ASAuthorizationControllerContinueButton"]
guard associateContinueButton.waitForExistence(timeout: timeout) else {
XCTFail("Failed to find the 'Continue' button to Associate new WebAuthn credential")
return
}
continueButton.tap()
associateContinueButton.tap()

// Trigger a matching face
try await matchBiometrics()
guard waitForResult("WebAuthn credential was associated") else {
XCTFail("Failed to associate credential")
XCTFail("Failed to associate credential: \(lastResult)")
return
}

// 2. List existing credentials
listButton.tap()
guard waitForResult("WebAuthn Credentials: 1") else {
XCTFail("Failed to list credentials")
XCTFail("Failed to list credentials: \(lastResult)")
return
}

// 3. Sign Out
signOutButton.tap()
guard waitForResult("User is signed out"), signInButton.exists else {
XCTFail("Failed to sign out user")
XCTFail("Failed to sign out user: \(lastResult)")
return
}

@@ -120,13 +118,14 @@ final class AuthWebAuthnAppUITests: XCTestCase {
}

guard signInAttempt else {
XCTFail("Failed to trigger the Assert WebAuthn Credential workflow")
XCTFail("Failed to trigger the Assert WebAuthn Credential workflow: \(lastResult)")
return
}

// Wait for the "Continue" button to appear in the FaceID popover
guard continueButton.waitForExistence(timeout: timeout) else {
XCTFail("Failed to find 'Continue' button")
let signInContinueButton = springboard.otherElements["ASAuthorizationControllerContinueButton"]
guard signInContinueButton.waitForExistence(timeout: timeout) else {
XCTFail("Failed to find the 'Continue' button to Sign In with WebAuthn")
return
}

@@ -137,27 +136,27 @@ final class AuthWebAuthnAppUITests: XCTestCase {
}

// Tap the "Continue" button
continueButton.tap()
signInContinueButton.tap()

// Trigger a matching face
try await matchBiometrics()

guard waitForResult("User is signed in") else {
XCTFail("Failed to Sign In with WebAuthn")
XCTFail("Failed to Sign In with WebAuthn: \(lastResult)")
return
}

// 5. Delete credential
deleteButton.tap()
guard waitForResult("WebAuthn credential was deleted") else {
XCTFail("Failed to delete credential")
XCTFail("Failed to delete credential: \(lastResult)")
return
}

// 6. Verify deletion
listButton.tap()
guard waitForResult("WebAuthn Credentials: 0") else {
XCTFail("Failed to list credentials")
XCTFail("Failed to list credentials: \(lastResult)")
return
}
}
@@ -194,7 +193,7 @@ final class AuthWebAuthnAppUITests: XCTestCase {
return
}

username = usernameElement.label
username = usernameElement.label.lowercased()

// Once the Username label exists, all these button are expected to visible as well,
// so we don't wait for them and instead just check for their existence
@@ -240,7 +239,7 @@ final class AuthWebAuthnAppUITests: XCTestCase {
private func signUpAndSignInUser() {
signUpButton.tap()
guard waitForResult("User is signed in"), signOutButton.exists else {
XCTFail("Failed to Sign Up and Sign In")
XCTFail("Failed to Sign Up and Sign In: \(lastResult)")
return
}
}
@@ -253,7 +252,7 @@ final class AuthWebAuthnAppUITests: XCTestCase {
}
deleteUserButton.tap()
guard waitForResult("User was deleted"), signUpButton.exists else {
XCTFail("Failed to delete the user")
XCTFail("Failed to delete the user: \(lastResult)")
return
}
}
@@ -275,4 +274,8 @@ final class AuthWebAuthnAppUITests: XCTestCase {
}
return result
}

private var lastResult: String {
app.staticTexts["LastResult"].label
}
}

Unchanged files with check annotations Beta

///
/// - Parameter plugin: The plugin to add
/// - Tag: Amplify.add_plugin
public static func add<P: Plugin>(plugin: P) throws {

Check warning on line 82 in Amplify/Amplify.swift

GitHub Actions / run-swiftlint

Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)
log.debug("Adding plugin: \(plugin))")
switch plugin {
case let plugin as AnalyticsCategoryPlugin:
import Foundation
// swiftlint:disable cyclomatic_complexity

Check warning on line 10 in Amplify/Core/Configuration/Internal/Amplify+Reset.swift

GitHub Actions / run-swiftlint

The disabled 'cyclomatic_complexity' rule should be re-enabled before the end of the file (blanket_disable_command)
extension Amplify {
/// Resets the state of the Amplify framework.
ModelListDecoderRegistry.reset()
ModelProviderRegistry.reset()
log.verbose("Resetting ModelRegistry, ModelListDecoderRegistry, ModelProviderRegistry finished")

Check warning on line 54 in Amplify/Core/Configuration/Internal/Amplify+Reset.swift

GitHub Actions / run-swiftlint

Lines should not have trailing whitespace (trailing_whitespace)
#if os(iOS) && !os(visionOS)
await MainActor.run {
devMenu = nil
/// - Parameter configuration: The AmplifyConfiguration for specified Categories
///
/// - Tag: Amplify.configure
public static func configure(_ configuration: AmplifyConfiguration? = nil) throws {

Check warning on line 112 in Amplify/Core/Configuration/AmplifyConfiguration.swift

GitHub Actions / run-swiftlint

Function should have complexity 10 or less; currently complexity is 13 (cyclomatic_complexity)
log.info("Configuring")
log.debug("Configuration: \(String(describing: configuration))")
guard !isConfigured else {
}
}
public class AmplifyInProcessReportingOperationTaskAdapter<Request: AmplifyOperationRequest,

Check warning on line 67 in Amplify/Core/Support/AmplifyTask+OperationTaskAdapters.swift

GitHub Actions / run-swiftlint

Type name 'AmplifyInProcessReportingOperationTaskAdapter' should be between 3 and 40 characters long (type_name)
InProcess,
Success,
Failure: AmplifyError>: AmplifyTask, AmplifyInProcessReportingTask {
/// - Tag: StorageListResult.items
public var items: [Item]

Check warning on line 35 in Amplify/Categories/Storage/Result/StorageListResult.swift

GitHub Actions / run-swiftlint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
/// Array of excluded subpaths in the Result.
/// This field is only populated when [`StorageListRequest.Options.subpathStrategy`](x-source-tag://StorageListRequestOptions.subpathStragegy) is set to [`.exclude()`](x-source-tag://SubpathStrategy.exclude).
///
///
/// - Tag: StorageDownloadFileRequest.path
public let path: (any StoragePath)?

Check warning on line 20 in Amplify/Categories/Storage/Operation/Request/StorageDownloadDataRequest.swift

GitHub Actions / run-swiftlint

Lines should not have trailing whitespace (trailing_whitespace)
/// The unique identifier for the object in storage
///
/// - Tag: StorageDownloadDataRequest.key
options: AuthConfirmSignInRequest.Options?
) async throws -> AuthSignInResult

Check warning on line 105 in Amplify/Categories/Auth/AuthCategoryBehavior.swift

GitHub Actions / run-swiftlint

Lines should not have trailing whitespace (trailing_whitespace)

Check warning on line 105 in Amplify/Categories/Auth/AuthCategoryBehavior.swift

GitHub Actions / run-swiftlint

Limit vertical whitespace to a single empty line; currently 2 (vertical_whitespace)
/// Auto signs in the user for passwordless sign up
func autoSignIn() async throws -> AuthSignInResult

Check warning on line 108 in Amplify/Categories/Auth/AuthCategoryBehavior.swift

GitHub Actions / run-swiftlint

Lines should not have trailing whitespace (trailing_whitespace)
/// Sign out the currently logged-in user.
///
/// - Parameters: