Skip to content

Commit 202a0fd

Browse files
authored
chore: kickoff release
2 parents 95d8f16 + 65da44e commit 202a0fd

File tree

7 files changed

+120
-7
lines changed

7 files changed

+120
-7
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/HostedUI/ShowHostedUISignIn.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ShowHostedUISignIn: NSObject, Action {
3636

3737
guard let callbackURL = URL(string: hostedUIConfig.oauth.signInRedirectURI),
3838
let callbackURLScheme = callbackURL.scheme else {
39-
let event = SignInEvent(eventType: .throwAuthError(.hostedUI(.signInURI)))
39+
let event = HostedUIEvent(eventType: .throwError(.hostedUI(.signInURI)))
4040
logVerbose("\(#fileID) Sending event \(event)", environment: environment)
4141
await dispatcher.send(event)
4242
return

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Operations/AuthConfigureOperation.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class AuthConfigureOperation: ConfigureOperation {
3737
override public func main() {
3838
if isCancelled {
3939
finish()
40+
dispatch(result: .failure(AuthError.configuration(
41+
"Configuration operation was cancelled",
42+
"", nil)))
4043
return
4144
}
4245

@@ -51,6 +54,7 @@ class AuthConfigureOperation: ConfigureOperation {
5154
for await state in stateSequences {
5255
if case .configured = state {
5356
finish()
57+
dispatch(result: .success(()))
5458
break
5559
}
5660
}

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/SignIn/HostedUISignInState+Resolver.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extension HostedUISignInState {
3030

3131
case .showingUI:
3232
if case .throwError(let error) = event.isHostedUIEvent {
33-
// Remove this?
3433
let action = CancelSignIn()
3534
return .init(newState: .error(error), actions: [action])
3635
}

AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/ConfigurationTests/AWSCognitoAuthPluginConfigTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,45 @@ class AWSCognitoAuthPluginConfigTests: XCTestCase {
236236
}
237237
}
238238

239+
/// Test that the Auth plugin emits `InternalConfigureAuth` that is used by the Logging Category
240+
///
241+
/// - Given: Given a valid config
242+
/// - When:
243+
/// - I configure auth with the given configuration
244+
/// - Then:
245+
/// - I should receive `InternalConfigureAuth` Hub event
246+
///
247+
func testEmittingInternalConfigureAuthHubEvent() throws {
248+
let expectation = expectation(description: "conifguration should complete")
249+
let subscription = Amplify.Hub.publisher(for: .auth).sink { payload in
250+
251+
if payload.eventName == "InternalConfigureAuth" {
252+
expectation.fulfill()
253+
}
254+
}
255+
let plugin = AWSCognitoAuthPlugin()
256+
try Amplify.add(plugin: plugin)
257+
258+
let categoryConfig = AuthCategoryConfiguration(plugins: [
259+
"awsCognitoAuthPlugin": [
260+
"CredentialsProvider": [
261+
"CognitoIdentity": [
262+
"Default": [
263+
"PoolId": "cc",
264+
"Region": "us-east-1"
265+
]
266+
]
267+
]
268+
]
269+
])
270+
let amplifyConfig = AmplifyConfiguration(auth: categoryConfig)
271+
do {
272+
try Amplify.configure(amplifyConfig)
273+
} catch {
274+
XCTFail("Should not throw error. \(error)")
275+
}
276+
wait(for: [expectation], timeout: 5.0)
277+
subscription.cancel()
278+
}
279+
239280
}

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,43 @@ class AWSAuthHostedUISignInTests: XCTestCase {
4242
return URLSession(configuration: configuration)
4343
}
4444

45+
private func customPlugin(with cusotmConfiguration: HostedUIConfigurationData?) -> AWSCognitoAuthPlugin {
46+
let plugin = AWSCognitoAuthPlugin()
47+
mockJson = try! JSONSerialization.data(withJSONObject: mockTokenResult)
48+
MockURLProtocol.requestHandler = { _ in
49+
return (HTTPURLResponse(), self.mockJson)
50+
}
51+
52+
func sessionFactory() -> HostedUISessionBehavior {
53+
MockHostedUISession(result: mockHostedUIResult)
54+
}
55+
56+
func mockRandomString() -> RandomStringBehavior {
57+
return MockRandomStringGenerator(mockString: mockState, mockUUID: mockState)
58+
}
59+
60+
let environment = BasicHostedUIEnvironment(configuration: cusotmConfiguration ?? configuration,
61+
hostedUISessionFactory: sessionFactory,
62+
urlSessionFactory: urlSessionMock,
63+
randomStringFactory: mockRandomString)
64+
let authEnvironment = Defaults.makeDefaultAuthEnvironment(
65+
userPoolFactory: { self.mockIdentityProvider },
66+
hostedUIEnvironment: environment)
67+
let stateMachine = Defaults.authStateMachineWith(
68+
environment: authEnvironment,
69+
initialState: initialState
70+
)
71+
72+
plugin.configure(
73+
authConfiguration: Defaults.makeDefaultAuthConfigData(withHostedUI: configuration),
74+
authEnvironment: authEnvironment,
75+
authStateMachine: stateMachine,
76+
credentialStoreStateMachine: Defaults.makeDefaultCredentialStateMachine(),
77+
hubEventHandler: MockAuthHubEventBehavior(),
78+
analyticsHandler: MockAnalyticsHandler())
79+
return plugin
80+
}
81+
4582
override func setUp() {
4683
plugin = AWSCognitoAuthPlugin()
4784
mockJson = try! JSONSerialization.data(withJSONObject: mockTokenResult)
@@ -310,6 +347,41 @@ class AWSAuthHostedUISignInTests: XCTestCase {
310347
await fulfillment(of: [expectation], timeout: networkTimeout)
311348
}
312349

350+
@MainActor
351+
func testInvalidRedirectConfigurationFailure() async {
352+
let invalidRedirectConfig = HostedUIConfigurationData(clientId: "clientId", oauth: .init(
353+
domain: "cognitodomain",
354+
scopes: ["name"],
355+
signInRedirectURI: "@#$%junk1343",
356+
signOutRedirectURI: "@3451://"))
357+
let testPlugin = customPlugin(with: invalidRedirectConfig)
358+
359+
mockHostedUIResult = .success([
360+
.init(name: "state", value: mockState),
361+
.init(name: "code", value: mockProof)
362+
])
363+
mockTokenResult = [
364+
"refresh_token": AWSCognitoUserPoolTokens.testData.refreshToken,
365+
"expires_in": 10] as [String: Any]
366+
mockJson = try! JSONSerialization.data(withJSONObject: mockTokenResult)
367+
MockURLProtocol.requestHandler = { _ in
368+
return (HTTPURLResponse(), self.mockJson)
369+
}
370+
371+
let expectation = expectation(description: "SignIn operation should complete")
372+
do {
373+
_ = try await testPlugin.signInWithWebUI(presentationAnchor: ASPresentationAnchor(), options: nil)
374+
XCTFail("Should not succeed")
375+
} catch {
376+
guard case AuthError.configuration = error else {
377+
XCTFail("Should not fail with error = \(error)")
378+
return
379+
}
380+
expectation.fulfill()
381+
}
382+
await fulfillment(of: [expectation], timeout: networkTimeout)
383+
}
384+
313385

314386

315387
/// Test a signIn restart while another sign in is in progress

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingCategoryClient.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ final class AWSCloudWatchLoggingCategoryClient {
8787
enum CognitoEventName: String {
8888
case signInAPI = "Auth.signInAPI"
8989
case signOutAPI = "Auth.signOutAPI"
90+
case configured = "InternalConfigureAuth"
9091
}
9192
switch payload.eventName {
92-
case HubPayload.EventName.Auth.signedIn, CognitoEventName.signInAPI.rawValue:
93+
case HubPayload.EventName.Auth.signedIn, CognitoEventName.signInAPI.rawValue, CognitoEventName.configured.rawValue:
9394
takeUserIdentifierFromCurrentUser()
9495
case HubPayload.EventName.Auth.signedOut, CognitoEventName.signOutAPI.rawValue:
9596
self.userIdentifier = nil

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/AWSCloudWatchLoggingPlugin.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
154154
let localStore: LoggingConstraintsLocalStore = UserDefaults.standard
155155
localStore.reset()
156156
}
157-
158-
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
159-
self.loggingClient.takeUserIdentifierFromCurrentUser()
160-
}
161157
}
162158
}
163159

0 commit comments

Comments
 (0)