// // Copyright Amazon.com Inc. or its affiliates. // All Rights Reserved. // // SPDX-License-Identifier: Apache-2.0 // import Foundation import XCTest import AWSCognitoIdentity @testable import Amplify @testable import AWSCognitoAuthPlugin import AWSCognitoIdentityProvider class AWSCognitoAuthClientBehaviorTests: XCTestCase { let networkTimeout = TimeInterval(10) var mockIdentityProvider: CognitoUserPoolBehavior! var plugin: AWSCognitoAuthPlugin! var initialState: AuthState { AuthState.configured( AuthenticationState.signedIn( SignedInData( signedInDate: Date(), signInMethod: .apiBased(.userSRP), cognitoUserPoolTokens: AWSCognitoUserPoolTokens.testData)), AuthorizationState.sessionEstablished(AmplifyCredentials.testData)) } override func setUp() { plugin = AWSCognitoAuthPlugin() let getId: MockIdentity.MockGetIdResponse = { _ in return .init(identityId: "mockIdentityId") } let getCredentials: MockIdentity.MockGetCredentialsResponse = { _ in let credentials = CognitoIdentityClientTypes.Credentials(accessKeyId: "accessKey", expiration: Date(), secretKey: "secret", sessionToken: "session") return .init(credentials: credentials, identityId: "responseIdentityID") } let mockIdentity = MockIdentity( mockGetIdResponse: getId, mockGetCredentialsResponse: getCredentials) let environment = Defaults.makeDefaultAuthEnvironment( identityPoolFactory: { mockIdentity }, userPoolFactory: { self.mockIdentityProvider }) let statemachine = Defaults.makeDefaultAuthStateMachine( initialState: initialState, identityPoolFactory: { mockIdentity }, userPoolFactory: { self.mockIdentityProvider }) plugin?.configure( authConfiguration: Defaults.makeDefaultAuthConfigData(), authEnvironment: environment, authStateMachine: statemachine, credentialStoreStateMachine: Defaults.makeDefaultCredentialStateMachine(), hubEventHandler: MockAuthHubEventBehavior(), analyticsHandler: MockAnalyticsHandler()) } override func tearDown() async throws { plugin = nil await Amplify.reset() } }