Skip to content

Commit 31a0a6a

Browse files
authored
chore: kickoff release
2 parents 46ee130 + b6a0400 commit 31a0a6a

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Errors/HostedUIError.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ enum HostedUIError: Error {
2727

2828
case invalidContext
2929

30+
case unableToStartASWebAuthenticationSession
31+
3032
case unknown
3133
}
3234

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/ErrorMapping/SignInError+Helper.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ extension HostedUIError: AuthErrorConvertible {
104104
AuthPluginErrorConstants.hostedUIInvalidPresentation.errorDescription,
105105
AuthPluginErrorConstants.hostedUIInvalidPresentation.recoverySuggestion)
106106

107+
case .unableToStartASWebAuthenticationSession:
108+
return .service(
109+
AuthPluginErrorConstants.hostedUIUnableToStartASWebAuthenticationSession.errorDescription,
110+
AuthPluginErrorConstants.hostedUIUnableToStartASWebAuthenticationSession.recoverySuggestion)
111+
107112
case .serviceMessage(let message):
108113
return .service(message, AuthPluginErrorConstants.serviceError)
109114

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Constants/AuthPluginErrorConstants.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ enum AuthPluginErrorConstants {
4040
"Presentation context provided is invalid or not present",
4141
"Retry by providing a presentation context to present the webUI")
4242

43+
static let hostedUIUnableToStartASWebAuthenticationSession: AuthPluginErrorString = (
44+
"Unable to start a ASWebAuthenticationSession",
45+
"Make sure that the app can present an ASWebAuthenticationSession")
46+
4347
static let hostedUISignInURI: AuthPluginErrorString = (
4448
"SignIn URI could not be created",
4549
"Check the configuration to make sure that HostedUI related information are present")
@@ -63,6 +67,7 @@ enum AuthPluginErrorConstants {
6367
static let userInvalidError: AuthPluginErrorString = (
6468
"Could not validate the user",
6569
"Get the current user Auth.getCurrentUser() and make the request")
70+
6671
static let identityIdSignOutError: AuthPluginErrorString = (
6772
"There is no user signed in to retreive identity id",
6873
"Call Auth.signIn to sign in a user or enable unauthenticated access in AWS Cognito Identity Pool")

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/HostedUI/HostedUIASWebAuthenticationSession.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class HostedUIASWebAuthenticationSession: NSObject, HostedUISessionBehavior {
6767
}
6868
if canStart {
6969
aswebAuthenticationSession.start()
70+
} else {
71+
continuation.resume( throwing: HostedUIError.unableToStartASWebAuthenticationSession)
7072
}
7173
}
7274
}

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/HostedUIASWebAuthenticationSessionTests.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,21 @@ class HostedUIASWebAuthenticationSessionTests: XCTestCase {
112112
XCTFail("Expected HostedUIError.unknown, got \(error)")
113113
}
114114
}
115-
115+
116+
/// Given: A HostedUIASWebAuthenticationSession
117+
/// When: showHostedUI is invoked and the session factory returns an error
118+
/// Then: A HostedUIError.unableToStartASWebAuthenticationSession should be returned
119+
func testShowHostedUI_withUnableToStartError_shouldReturnServiceError() async {
120+
factory.mockCanStart = false
121+
do {
122+
_ = try await session.showHostedUI()
123+
} catch let error as HostedUIError {
124+
XCTAssertEqual(error, .unableToStartASWebAuthenticationSession)
125+
} catch {
126+
XCTFail("Expected HostedUIError.unknown, got \(error)")
127+
}
128+
}
129+
116130
private func createURL(queryItems: [URLQueryItem] = []) -> URL {
117131
var components = URLComponents(string: "https://test.com")!
118132
components.queryItems = queryItems
@@ -123,6 +137,7 @@ class HostedUIASWebAuthenticationSessionTests: XCTestCase {
123137
class ASWebAuthenticationSessionFactory {
124138
var mockedURL: URL?
125139
var mockedError: Error?
140+
var mockCanStart: Bool?
126141

127142
func createSession(
128143
url URL: URL,
@@ -136,6 +151,7 @@ class ASWebAuthenticationSessionFactory {
136151
)
137152
session.mockedURL = mockedURL
138153
session.mockedError = mockedError
154+
session.mockCanStart = mockCanStart ?? true
139155
return session
140156
}
141157
}
@@ -161,6 +177,11 @@ class MockASWebAuthenticationSession: ASWebAuthenticationSession {
161177
callback(mockedURL, mockedError)
162178
return presentationContextProvider?.presentationAnchor(for: self) != nil
163179
}
180+
181+
var mockCanStart = true
182+
override var canStart: Bool {
183+
return mockCanStart
184+
}
164185
}
165186

166187
extension HostedUIASWebAuthenticationSession {

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/HostedUITests/AWSAuthHostedUISignInTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ class AWSAuthHostedUISignInTests: XCTestCase {
229229
await fulfillment(of: [expectation], timeout: networkTimeout)
230230
}
231231

232+
func testUnableToStartASWebAuthenticationSession() async {
233+
mockHostedUIResult = .failure(.unableToStartASWebAuthenticationSession)
234+
let expectation = expectation(description: "SignIn operation should complete")
235+
do {
236+
_ = try await plugin.signInWithWebUI(presentationAnchor: ASPresentationAnchor(), options: nil)
237+
XCTFail("Should not succeed")
238+
} catch {
239+
guard case AuthError.service = error else {
240+
XCTFail("Should not fail with error = \(error)")
241+
return
242+
}
243+
expectation.fulfill()
244+
}
245+
await fulfillment(of: [expectation], timeout: networkTimeout)
246+
}
247+
232248
@MainActor
233249
func testTokenParsingFailure() async {
234250
mockHostedUIResult = .success([

0 commit comments

Comments
 (0)