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: kickoff release #3718

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -27,6 +27,8 @@ enum HostedUIError: Error {

case invalidContext

case unableToStartASWebAuthenticationSession

case unknown
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ extension HostedUIError: AuthErrorConvertible {
AuthPluginErrorConstants.hostedUIInvalidPresentation.errorDescription,
AuthPluginErrorConstants.hostedUIInvalidPresentation.recoverySuggestion)

case .unableToStartASWebAuthenticationSession:
return .service(
AuthPluginErrorConstants.hostedUIUnableToStartASWebAuthenticationSession.errorDescription,
AuthPluginErrorConstants.hostedUIUnableToStartASWebAuthenticationSession.recoverySuggestion)

case .serviceMessage(let message):
return .service(message, AuthPluginErrorConstants.serviceError)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ enum AuthPluginErrorConstants {
"Presentation context provided is invalid or not present",
"Retry by providing a presentation context to present the webUI")

static let hostedUIUnableToStartASWebAuthenticationSession: AuthPluginErrorString = (
"Unable to start a ASWebAuthenticationSession",
"Make sure that the app can present an ASWebAuthenticationSession")

static let hostedUISignInURI: AuthPluginErrorString = (
"SignIn URI could not be created",
"Check the configuration to make sure that HostedUI related information are present")
Expand All @@ -63,6 +67,7 @@ enum AuthPluginErrorConstants {
static let userInvalidError: AuthPluginErrorString = (
"Could not validate the user",
"Get the current user Auth.getCurrentUser() and make the request")

static let identityIdSignOutError: AuthPluginErrorString = (
"There is no user signed in to retreive identity id",
"Call Auth.signIn to sign in a user or enable unauthenticated access in AWS Cognito Identity Pool")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
}
if canStart {
aswebAuthenticationSession.start()
} else {
continuation.resume( throwing: HostedUIError.unableToStartASWebAuthenticationSession)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,21 @@ class HostedUIASWebAuthenticationSessionTests: XCTestCase {
XCTFail("Expected HostedUIError.unknown, got \(error)")
}
}


/// Given: A HostedUIASWebAuthenticationSession
/// When: showHostedUI is invoked and the session factory returns an error
/// Then: A HostedUIError.unableToStartASWebAuthenticationSession should be returned
func testShowHostedUI_withUnableToStartError_shouldReturnServiceError() async {
factory.mockCanStart = false
do {
_ = try await session.showHostedUI()
} catch let error as HostedUIError {
XCTAssertEqual(error, .unableToStartASWebAuthenticationSession)
} catch {
XCTFail("Expected HostedUIError.unknown, got \(error)")
}
}

private func createURL(queryItems: [URLQueryItem] = []) -> URL {
var components = URLComponents(string: "https://test.com")!
components.queryItems = queryItems
Expand All @@ -123,6 +137,7 @@ class HostedUIASWebAuthenticationSessionTests: XCTestCase {
class ASWebAuthenticationSessionFactory {
var mockedURL: URL?
var mockedError: Error?
var mockCanStart: Bool?

func createSession(
url URL: URL,
Expand All @@ -136,6 +151,7 @@ class ASWebAuthenticationSessionFactory {
)
session.mockedURL = mockedURL
session.mockedError = mockedError
session.mockCanStart = mockCanStart ?? true
return session
}
}
Expand All @@ -161,6 +177,11 @@ class MockASWebAuthenticationSession: ASWebAuthenticationSession {
callback(mockedURL, mockedError)
return presentationContextProvider?.presentationAnchor(for: self) != nil
}

var mockCanStart = true
override var canStart: Bool {
return mockCanStart
}
}

extension HostedUIASWebAuthenticationSession {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,22 @@ class AWSAuthHostedUISignInTests: XCTestCase {
await fulfillment(of: [expectation], timeout: networkTimeout)
}

func testUnableToStartASWebAuthenticationSession() async {
mockHostedUIResult = .failure(.unableToStartASWebAuthenticationSession)
let expectation = expectation(description: "SignIn operation should complete")
do {
_ = try await plugin.signInWithWebUI(presentationAnchor: ASPresentationAnchor(), options: nil)
XCTFail("Should not succeed")
} catch {
guard case AuthError.service = error else {
XCTFail("Should not fail with error = \(error)")
return
}
expectation.fulfill()
}
await fulfillment(of: [expectation], timeout: networkTimeout)
}

@MainActor
func testTokenParsingFailure() async {
mockHostedUIResult = .success([
Expand Down
Loading