Skip to content

Commit

Permalink
chore: kickoff release
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode authored May 22, 2024
2 parents 46ee130 + b6a0400 commit 31a0a6a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
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

0 comments on commit 31a0a6a

Please sign in to comment.