diff --git a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/URLSessionClient/URLSessionClient.swift b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/URLSessionClient/URLSessionClient.swift index d431b01b07..ee1d90b0e2 100644 --- a/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/URLSessionClient/URLSessionClient.swift +++ b/AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/URLSessionClient/URLSessionClient.swift @@ -26,7 +26,7 @@ public struct URLSessionClient: URLSessionClientBehavior { for request: URLRequest, delegate: (URLSessionTaskDelegate)?) async throws -> (Data, URLResponse) { - if #available(iOS 15.0, *) { + if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) { return try await self.urlSession.data( for: request, delegate: delegate @@ -57,7 +57,7 @@ public struct URLSessionClient: URLSessionClientBehavior { from url: URL, delegate: (URLSessionTaskDelegate)?) async throws -> (Data, URLResponse) { - if #available(iOS 15.0, *) { + if #available(iOS 15.0, macOS 12.0, tvOS 15.0, *) { return try await self.urlSession.data( from: url, delegate: delegate diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/DefaultConfig.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/DefaultConfig.swift index 1c7505fbec..175f60e441 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/DefaultConfig.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/Support/DefaultConfig.swift @@ -60,6 +60,12 @@ enum Defaults { static func makeCredentialStoreOperationBehavior() -> CredentialStoreStateBehavior { return MockCredentialStoreOperationClient() } + + static func makeURLSession() -> URLSession { + let configuration = URLSessionConfiguration.default + configuration.urlCache = nil + return URLSession(configuration: configuration) + } static func makeDefaultUserPool() throws -> CognitoUserPoolBehavior { return try CognitoIdentityProviderClient(region: regionString) @@ -162,6 +168,7 @@ enum Defaults { authenticationEnvironment: authenticationEnvironment, authorizationEnvironment: authZEnvironment ?? authorizationEnvironment, credentialsClient: makeCredentialStoreOperationBehavior(), + urlSessionClient: URLSessionClient(urlSession: makeURLSession()), logger: Amplify.Logging.logger(forCategory: "awsCognitoAuthPluginTest") ) Amplify.Logging.logLevel = .verbose diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInTaskTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInTaskTests.swift index da1a27739a..66090b4bd1 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInTaskTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/AWSAuthConfirmSignInTaskTests.swift @@ -494,6 +494,7 @@ class AuthenticationProviderConfirmSigninTests: BasePluginTest { authenticationEnvironment: nil, authorizationEnvironment: authorizationEnvironment, credentialsClient: Defaults.makeCredentialStoreOperationBehavior(), + urlSessionClient: nil, logger: Amplify.Logging.logger(forCategory: "awsCognitoAuthPluginTest") ) let stateMachine = Defaults.authStateMachineWith(environment: environment, diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInTOTPTaskTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInTOTPTaskTests.swift index 98849dce07..38d99bdf57 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInTOTPTaskTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInTOTPTaskTests.swift @@ -512,6 +512,7 @@ class ConfirmSignInTOTPTaskTests: BasePluginTest { authenticationEnvironment: nil, authorizationEnvironment: authorizationEnvironment, credentialsClient: Defaults.makeCredentialStoreOperationBehavior(), + urlSessionClient: nil, logger: Amplify.Logging.logger(forCategory: "awsCognitoAuthPluginTest") ) let stateMachine = Defaults.authStateMachineWith(environment: environment, diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithMFASelectionTaskTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithMFASelectionTaskTests.swift index da3e22fa6c..11805b3f4b 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithMFASelectionTaskTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithMFASelectionTaskTests.swift @@ -548,6 +548,7 @@ class ConfirmSignInWithMFASelectionTaskTests: BasePluginTest { authenticationEnvironment: nil, authorizationEnvironment: authorizationEnvironment, credentialsClient: Defaults.makeCredentialStoreOperationBehavior(), + urlSessionClient: nil, logger: Amplify.Logging.logger(forCategory: "awsCognitoAuthPluginTest") ) let stateMachine = Defaults.authStateMachineWith(environment: environment, diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithSetUpMFATaskTests.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithSetUpMFATaskTests.swift index b0ab9ad69a..f60723bdb7 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithSetUpMFATaskTests.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TaskTests/ClientBehaviorTests/SignIn/ConfirmSignInWithSetUpMFATaskTests.swift @@ -311,6 +311,7 @@ class ConfirmSignInWithSetUpMFATaskTests: BasePluginTest { authenticationEnvironment: nil, authorizationEnvironment: authorizationEnvironment, credentialsClient: Defaults.makeCredentialStoreOperationBehavior(), + urlSessionClient: nil, logger: Amplify.Logging.logger(forCategory: "awsCognitoAuthPluginTest") ) let stateMachine = Defaults.authStateMachineWith(environment: environment, diff --git a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/Mocks/MockedAuthCognitoPlugin.swift b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/Mocks/MockedAuthCognitoPlugin.swift index 12b744f71f..d084e53114 100644 --- a/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/Mocks/MockedAuthCognitoPlugin.swift +++ b/AmplifyPlugins/Auth/Tests/AWSCognitoAuthPluginUnitTests/TestHarness/Mocks/MockedAuthCognitoPlugin.swift @@ -124,6 +124,7 @@ struct MockedAuthCognitoPluginHelper { authenticationEnvironment: authenticationEnvironment, authorizationEnvironment: nil, credentialsClient: makeCredentialStoreClient(), + urlSessionClient: URLSessionClient(urlSession: makeURLSession()), logger: log) case .identityPools(let identityPoolConfigurationData): @@ -136,6 +137,7 @@ struct MockedAuthCognitoPluginHelper { authenticationEnvironment: nil, authorizationEnvironment: authorizationEnvironment, credentialsClient: makeCredentialStoreClient(), + urlSessionClient: URLSessionClient(urlSession: makeURLSession()), logger: log) case .userPoolsAndIdentityPools(let userPoolConfigurationData, @@ -151,6 +153,7 @@ struct MockedAuthCognitoPluginHelper { authenticationEnvironment: authenticationEnvironment, authorizationEnvironment: authorizationEnvironment, credentialsClient: makeCredentialStoreClient(), + urlSessionClient: URLSessionClient(urlSession: makeURLSession()), logger: log) } }