diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt index 2b06e0001..decb5721c 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/RealAWSCognitoAuthPlugin.kt @@ -965,7 +965,8 @@ internal class RealAWSCognitoAuthPlugin( username = challengeState.challenge.username, session = challengeState.challenge.session, parameters = challengeState.challenge.parameters - ) + ), + signInMethod = challengeState.signInMethod ) ) authStateMachine.send(event) @@ -980,7 +981,8 @@ internal class RealAWSCognitoAuthPlugin( username = challengeState.challenge.username, session = challengeState.challenge.session, parameters = challengeState.challenge.parameters - ) + ), + signInMethod = challengeState.signInMethod ) ) authStateMachine.send(event) @@ -1035,15 +1037,16 @@ internal class RealAWSCognitoAuthPlugin( is SignInState.ResolvingTOTPSetup -> { when (signInState.setupTOTPState) { is SetupTOTPState.WaitingForAnswer -> { - val setupData = - (signInState.setupTOTPState as SetupTOTPState.WaitingForAnswer).signInTOTPSetupData + val setupTOTPState = + (signInState.setupTOTPState as SetupTOTPState.WaitingForAnswer) val event = SetupTOTPEvent( SetupTOTPEvent.EventType.VerifyChallengeAnswer( challengeResponse, - setupData.username, - setupData.session, - awsCognitoConfirmSignInOptions?.friendlyDeviceName + setupTOTPState.signInTOTPSetupData.username, + setupTOTPState.signInTOTPSetupData.session, + awsCognitoConfirmSignInOptions?.friendlyDeviceName, + setupTOTPState.signInMethod ) ) authStateMachine.send(event) @@ -1053,13 +1056,16 @@ internal class RealAWSCognitoAuthPlugin( (signInState.setupTOTPState as SetupTOTPState.Error).username val session = (signInState.setupTOTPState as SetupTOTPState.Error).session + val signInMethod = + (signInState.setupTOTPState as SetupTOTPState.Error).signInMethod val event = SetupTOTPEvent( SetupTOTPEvent.EventType.VerifyChallengeAnswer( challengeResponse, username, session, - awsCognitoConfirmSignInOptions?.friendlyDeviceName + awsCognitoConfirmSignInOptions?.friendlyDeviceName, + signInMethod ) ) authStateMachine.send(event) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SRPCognitoActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SRPCognitoActions.kt index 6217be9d9..6ceb2a7e7 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SRPCognitoActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SRPCognitoActions.kt @@ -32,6 +32,7 @@ import com.amplifyframework.statemachine.Action import com.amplifyframework.statemachine.codegen.actions.SRPActions import com.amplifyframework.statemachine.codegen.data.CredentialType import com.amplifyframework.statemachine.codegen.data.DeviceMetadata +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.events.AuthenticationEvent import com.amplifyframework.statemachine.codegen.events.SRPEvent import com.amplifyframework.statemachine.codegen.events.SignInEvent @@ -245,7 +246,8 @@ internal object SRPCognitoActions : SRPActions { override fun verifyPasswordSRPAction( challengeParameters: Map, metadata: Map, - session: String? + session: String?, + signInMethod: SignInMethod ) = Action("VerifyPasswordSRP") { id, dispatcher -> logger.verbose("$id Starting execution") @@ -292,7 +294,8 @@ internal object SRPCognitoActions : SRPActions { challengeNameType = response.challengeName, session = response.session, challengeParameters = response.challengeParameters, - authenticationResult = response.authenticationResult + authenticationResult = response.authenticationResult, + signInMethod = signInMethod ) } else { throw ServiceException( @@ -311,7 +314,7 @@ internal object SRPCognitoActions : SRPActions { ) ) ) - SRPEvent(SRPEvent.EventType.RetryRespondPasswordVerifier(challengeParams, metadata, session)) + SRPEvent(SRPEvent.EventType.RetryRespondPasswordVerifier(challengeParams, metadata, session, signInMethod)) } else { val errorEvent = SRPEvent(SRPEvent.EventType.ThrowPasswordVerifierError(e)) logger.verbose("$id Sending event ${errorEvent.type}") diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActions.kt index 8ac25e8cb..dd403cf08 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActions.kt @@ -46,14 +46,16 @@ internal object SetupTOTPCognitoActions : SetupTOTPActions { session = response.session, username = eventType.totpSetupDetails.username ), - challengeParams = eventType.challengeParams + challengeParams = eventType.challengeParams, + signInMethod = eventType.signInMethod ) ) } ?: SetupTOTPEvent( SetupTOTPEvent.EventType.ThrowAuthError( Exception("Software token setup failed"), eventType.totpSetupDetails.username, - eventType.totpSetupDetails.session + eventType.totpSetupDetails.session, + eventType.signInMethod ) ) } catch (e: Exception) { @@ -61,7 +63,8 @@ internal object SetupTOTPCognitoActions : SetupTOTPActions { SetupTOTPEvent.EventType.ThrowAuthError( e, eventType.totpSetupDetails.username, - eventType.totpSetupDetails.session + eventType.totpSetupDetails.session, + eventType.signInMethod ) ) } @@ -87,7 +90,8 @@ internal object SetupTOTPCognitoActions : SetupTOTPActions { SetupTOTPEvent( SetupTOTPEvent.EventType.RespondToAuthChallenge( eventType.username, - it.session + it.session, + eventType.signInMethod ) ) } @@ -99,7 +103,8 @@ internal object SetupTOTPCognitoActions : SetupTOTPActions { recoverySuggestion = AmplifyException.TODO_RECOVERY_SUGGESTION ), eventType.username, - eventType.session + eventType.session, + eventType.signInMethod ) ) } @@ -108,7 +113,8 @@ internal object SetupTOTPCognitoActions : SetupTOTPActions { SetupTOTPEvent.EventType.ThrowAuthError( Exception("Software token verification failed"), eventType.username, - eventType.session + eventType.session, + eventType.signInMethod ) ) } catch (exception: Exception) { @@ -116,7 +122,8 @@ internal object SetupTOTPCognitoActions : SetupTOTPActions { SetupTOTPEvent.EventType.ThrowAuthError( exception, eventType.username, - eventType.session + eventType.session, + eventType.signInMethod ) ) } @@ -152,18 +159,22 @@ internal object SetupTOTPCognitoActions : SetupTOTPActions { challengeNameType = response.challengeName, session = response.session, challengeParameters = response.challengeParameters, - authenticationResult = response.authenticationResult + authenticationResult = response.authenticationResult, + signInMethod = eventType.signInMethod ) } ?: SetupTOTPEvent( SetupTOTPEvent.EventType.ThrowAuthError( Exception("Software token verification failed"), eventType.username, - eventType.session + eventType.session, + eventType.signInMethod ) ) } catch (exception: Exception) { SetupTOTPEvent( - SetupTOTPEvent.EventType.ThrowAuthError(exception, eventType.username, eventType.session) + SetupTOTPEvent.EventType.ThrowAuthError( + exception, eventType.username, eventType.session, eventType.signInMethod + ) ) } dispatcher.send(evt) diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActions.kt index 898f4ba38..c187baebf 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActions.kt @@ -29,6 +29,7 @@ import com.amplifyframework.statemachine.Action import com.amplifyframework.statemachine.codegen.actions.SignInChallengeActions import com.amplifyframework.statemachine.codegen.data.AuthChallenge import com.amplifyframework.statemachine.codegen.data.CredentialType +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.challengeNameType import com.amplifyframework.statemachine.codegen.events.CustomSignInEvent import com.amplifyframework.statemachine.codegen.events.SignInChallengeEvent @@ -41,7 +42,8 @@ internal object SignInChallengeCognitoActions : SignInChallengeActions { answer: String, metadata: Map, attributes: List, - challenge: AuthChallenge + challenge: AuthChallenge, + signInMethod: SignInMethod ): Action = Action("VerifySignInChallenge") { id, dispatcher -> logger.verbose("$id Starting execution") val evt = try { @@ -55,7 +57,8 @@ internal object SignInChallengeCognitoActions : SignInChallengeActions { challengeNameType = ChallengeNameType.MfaSetup, session = challenge.session, challengeParameters = mapOf("MFAS_CAN_SETUP" to answer), - authenticationResult = null + authenticationResult = null, + signInMethod = signInMethod ) logger.verbose("$id Sending event ${event.type}") dispatcher.send(event) @@ -102,7 +105,8 @@ internal object SignInChallengeCognitoActions : SignInChallengeActions { challengeNameType = response.challengeName, session = response.session, challengeParameters = response.challengeParameters, - authenticationResult = response.authenticationResult + authenticationResult = response.authenticationResult, + signInMethod = signInMethod ) } ?: CustomSignInEvent( CustomSignInEvent.EventType.ThrowAuthError( diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInCognitoActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInCognitoActions.kt index 059f26a39..d4b884a32 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInCognitoActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/SignInCognitoActions.kt @@ -108,7 +108,9 @@ internal object SignInCognitoActions : SignInActions { override fun initResolveChallenge(event: SignInEvent.EventType.ReceivedChallenge) = Action("InitResolveChallenge") { id, dispatcher -> logger.verbose("$id Starting execution") - val evt = SignInChallengeEvent(SignInChallengeEvent.EventType.WaitForAnswer(event.challenge, true)) + val evt = SignInChallengeEvent( + SignInChallengeEvent.EventType.WaitForAnswer(event.challenge, event.signInMethod, true) + ) logger.verbose("$id Sending event ${evt.type}") dispatcher.send(evt) } @@ -167,7 +169,8 @@ internal object SignInCognitoActions : SignInActions { val evt = SetupTOTPEvent( SetupTOTPEvent.EventType.SetupTOTP( totpSetupDetails = event.signInTOTPSetupData, - challengeParams = event.challengeParams + challengeParams = event.challengeParams, + signInMethod = event.signInMethod ) ) logger.verbose("$id Sending event ${evt.type}") diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/WebAuthnSignInCognitoActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/WebAuthnSignInCognitoActions.kt index bad7c9780..c6a2e8605 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/WebAuthnSignInCognitoActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/actions/WebAuthnSignInCognitoActions.kt @@ -62,7 +62,8 @@ internal object WebAuthnSignInCognitoActions : WebAuthnSignInActions { session = response.session, challengeParameters = response.challengeParameters, authenticationResult = response.authenticationResult, - callingActivity = signInContext.callingActivity + callingActivity = signInContext.callingActivity, + signInMethod = SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_AUTH) ) } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthFlowTypeHelper.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthFlowTypeHelper.kt index ae9f2e188..0deba8b11 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthFlowTypeHelper.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/AuthFlowTypeHelper.kt @@ -16,6 +16,7 @@ package com.amplifyframework.auth.cognito.helpers import aws.sdk.kotlin.services.cognitoidentityprovider.model.AuthFlowType as CognitoAuthFlowType import com.amplifyframework.auth.cognito.options.AuthFlowType +import com.amplifyframework.statemachine.codegen.data.SignInMethod internal fun AuthFlowType.toCognitoType() = when (this) { AuthFlowType.USER_SRP_AUTH -> CognitoAuthFlowType.UserSrpAuth @@ -25,3 +26,12 @@ internal fun AuthFlowType.toCognitoType() = when (this) { AuthFlowType.USER_PASSWORD_AUTH -> CognitoAuthFlowType.UserPasswordAuth AuthFlowType.USER_AUTH -> CognitoAuthFlowType.UserAuth } + +internal fun AuthFlowType.toSignInMethod() = when (this) { + AuthFlowType.USER_SRP_AUTH -> SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) + AuthFlowType.CUSTOM_AUTH -> SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.CUSTOM_AUTH) + AuthFlowType.CUSTOM_AUTH_WITH_SRP -> SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.CUSTOM_AUTH) + AuthFlowType.CUSTOM_AUTH_WITHOUT_SRP -> SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.CUSTOM_AUTH) + AuthFlowType.USER_PASSWORD_AUTH -> SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_PASSWORD_AUTH) + AuthFlowType.USER_AUTH -> SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_AUTH) +} diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/SignInChallengeHelper.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/SignInChallengeHelper.kt index 1e22f4b02..f2c1e4970 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/SignInChallengeHelper.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/auth/cognito/helpers/SignInChallengeHelper.kt @@ -55,7 +55,7 @@ internal object SignInChallengeHelper { availableChallenges: List? = null, authenticationResult: AuthenticationResultType?, callingActivity: WeakReference = WeakReference(null), - signInMethod: SignInMethod = SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) + signInMethod: SignInMethod ): StateMachineEvent = when { authenticationResult != null -> { authenticationResult.let { @@ -96,17 +96,17 @@ internal object SignInChallengeHelper { challengeNameType is ChallengeNameType.EmailOtp -> { val challenge = AuthChallenge(challengeNameType.value, username, session, challengeParameters) - SignInEvent(SignInEvent.EventType.ReceivedChallenge(challenge)) + SignInEvent(SignInEvent.EventType.ReceivedChallenge(challenge, signInMethod)) } challengeNameType is ChallengeNameType.MfaSetup -> { val allowedMFASetupTypes = getAllowedMFASetupTypesFromChallengeParameters(challengeParameters) val challenge = AuthChallenge(challengeNameType.value, username, session, challengeParameters) if (allowedMFASetupTypes.contains(MFAType.EMAIL)) { - SignInEvent(SignInEvent.EventType.ReceivedChallenge(challenge)) + SignInEvent(SignInEvent.EventType.ReceivedChallenge(challenge, signInMethod)) } else if (allowedMFASetupTypes.contains(MFAType.TOTP)) { val setupTOTPData = SignInTOTPSetupData("", session, username) - SignInEvent(SignInEvent.EventType.InitiateTOTPSetup(setupTOTPData, challenge.parameters)) + SignInEvent(SignInEvent.EventType.InitiateTOTPSetup(setupTOTPData, challenge.parameters, signInMethod)) } else { SignInEvent( SignInEvent.EventType.ThrowError( @@ -127,7 +127,8 @@ internal object SignInChallengeHelper { session = session, parameters = null, availableChallenges = availableChallenges - ) + ), + signInMethod ) ) } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SRPActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SRPActions.kt index 467ab8b1a..b872fda60 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SRPActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SRPActions.kt @@ -16,6 +16,7 @@ package com.amplifyframework.statemachine.codegen.actions import com.amplifyframework.statemachine.Action +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.events.SRPEvent internal interface SRPActions { @@ -24,6 +25,7 @@ internal interface SRPActions { fun verifyPasswordSRPAction( challengeParameters: Map, metadata: Map, - session: String? + session: String?, + signInMethod: SignInMethod ): Action } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SignInChallengeActions.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SignInChallengeActions.kt index 8793d217d..242434c65 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SignInChallengeActions.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/actions/SignInChallengeActions.kt @@ -18,12 +18,14 @@ package com.amplifyframework.statemachine.codegen.actions import com.amplifyframework.auth.AuthUserAttribute import com.amplifyframework.statemachine.Action import com.amplifyframework.statemachine.codegen.data.AuthChallenge +import com.amplifyframework.statemachine.codegen.data.SignInMethod internal interface SignInChallengeActions { fun verifyChallengeAuthAction( answer: String, metadata: Map, userAttributes: List, - challenge: AuthChallenge + challenge: AuthChallenge, + signInMethod: SignInMethod ): Action } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SRPEvent.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SRPEvent.kt index 9769519fb..e8abd4664 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SRPEvent.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SRPEvent.kt @@ -18,6 +18,7 @@ package com.amplifyframework.statemachine.codegen.events import com.amplifyframework.auth.cognito.options.AuthFlowType import com.amplifyframework.statemachine.StateMachineEvent import com.amplifyframework.statemachine.codegen.data.AuthChallenge +import com.amplifyframework.statemachine.codegen.data.SignInMethod import java.util.Date internal class SRPEvent(val eventType: EventType, override val time: Date? = null) : @@ -44,7 +45,8 @@ internal class SRPEvent(val eventType: EventType, override val time: Date? = nul data class RetryRespondPasswordVerifier( val challengeParameters: Map, val metadata: Map, - val session: String? + val session: String?, + val signInMethod: SignInMethod ) : EventType() data class ThrowAuthError(val exception: Exception) : EventType() diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SetupTOTPEvent.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SetupTOTPEvent.kt index f0abd5017..897b62cc8 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SetupTOTPEvent.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SetupTOTPEvent.kt @@ -15,6 +15,7 @@ package com.amplifyframework.statemachine.codegen.events import com.amplifyframework.statemachine.StateMachineEvent +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.SignInTOTPSetupData import java.util.Date @@ -24,22 +25,34 @@ internal class SetupTOTPEvent(val eventType: EventType, override val time: Date? sealed class EventType { data class SetupTOTP( val totpSetupDetails: SignInTOTPSetupData, - val challengeParams: Map? + val challengeParams: Map?, + val signInMethod: SignInMethod ) : EventType() data class WaitForAnswer( val totpSetupDetails: SignInTOTPSetupData, - val challengeParams: Map? + val challengeParams: Map?, + val signInMethod: SignInMethod + ) : EventType() + data class ThrowAuthError( + val exception: Exception, + val username: String, + val session: String?, + val signInMethod: SignInMethod ) : EventType() - data class ThrowAuthError(val exception: Exception, val username: String, val session: String?) : EventType() data class VerifyChallengeAnswer( val answer: String, val username: String, val session: String?, - val friendlyDeviceName: String? + val friendlyDeviceName: String?, + val signInMethod: SignInMethod ) : EventType() - data class RespondToAuthChallenge(val username: String, val session: String?) : EventType() + data class RespondToAuthChallenge( + val username: String, + val session: String?, + val signInMethod: SignInMethod + ) : EventType() data class Verified(val id: String = "") : EventType() } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInChallengeEvent.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInChallengeEvent.kt index 6c1a27b57..4576190db 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInChallengeEvent.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInChallengeEvent.kt @@ -18,11 +18,16 @@ package com.amplifyframework.statemachine.codegen.events import com.amplifyframework.auth.AuthUserAttribute import com.amplifyframework.statemachine.StateMachineEvent import com.amplifyframework.statemachine.codegen.data.AuthChallenge +import com.amplifyframework.statemachine.codegen.data.SignInMethod import java.util.Date internal class SignInChallengeEvent(val eventType: EventType, override val time: Date? = null) : StateMachineEvent { sealed class EventType { - data class WaitForAnswer(val challenge: AuthChallenge, val hasNewResponse: Boolean = false) : EventType() + data class WaitForAnswer( + val challenge: AuthChallenge, + val signInMethod: SignInMethod, + val hasNewResponse: Boolean = false + ) : EventType() data class VerifyChallengeAnswer( val answer: String, val metadata: Map, diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInEvent.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInEvent.kt index 3822c0ad4..2416ea342 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInEvent.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/events/SignInEvent.kt @@ -22,6 +22,7 @@ import com.amplifyframework.statemachine.StateMachineEvent import com.amplifyframework.statemachine.codegen.data.AuthChallenge import com.amplifyframework.statemachine.codegen.data.DeviceMetadata import com.amplifyframework.statemachine.codegen.data.SignInData +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.SignInTOTPSetupData import com.amplifyframework.statemachine.codegen.data.SignedInData import com.amplifyframework.statemachine.codegen.data.WebAuthnSignInContext @@ -61,11 +62,12 @@ internal class SignInEvent(val eventType: EventType, override val time: Date? = data class ConfirmDevice(val deviceMetadata: DeviceMetadata.Metadata, val signedInData: SignedInData) : EventType() data class FinalizeSignIn(val id: String = "") : EventType() - data class ReceivedChallenge(val challenge: AuthChallenge) : EventType() + data class ReceivedChallenge(val challenge: AuthChallenge, val signInMethod: SignInMethod) : EventType() data class ThrowError(val exception: Exception) : EventType() data class InitiateTOTPSetup( val signInTOTPSetupData: SignInTOTPSetupData, - val challengeParams: Map? + val challengeParams: Map?, + val signInMethod: SignInMethod ) : EventType() data class InitiateUserAuth( diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SRPSignInState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SRPSignInState.kt index 92ef5b7f6..5f7b7b1dd 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SRPSignInState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SRPSignInState.kt @@ -15,16 +15,18 @@ package com.amplifyframework.statemachine.codegen.states +import com.amplifyframework.auth.cognito.helpers.toSignInMethod import com.amplifyframework.statemachine.State import com.amplifyframework.statemachine.StateMachineEvent import com.amplifyframework.statemachine.StateMachineResolver import com.amplifyframework.statemachine.StateResolution import com.amplifyframework.statemachine.codegen.actions.SRPActions +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.events.SRPEvent internal sealed class SRPSignInState : State { data class NotStarted(val id: String = "") : SRPSignInState() - data class InitiatingSRPA(val id: String = "") : SRPSignInState() + data class InitiatingSRPA(val signInMethod: SignInMethod) : SRPSignInState() data class RespondingPasswordVerifier(val id: String = "") : SRPSignInState() data class SignedIn(val id: String = "") : SRPSignInState() data class Cancelling(val id: String = "") : SRPSignInState() @@ -44,18 +46,18 @@ internal sealed class SRPSignInState : State { is NotStarted -> when (srpEvent) { is SRPEvent.EventType.InitiateSRP -> { val action = srpActions.initiateSRPAuthAction(srpEvent) - StateResolution(InitiatingSRPA(), listOf(action)) + StateResolution(InitiatingSRPA(srpEvent.authFlowType.toSignInMethod()), listOf(action)) } is SRPEvent.EventType.InitiateSRPWithCustom -> { val action = srpActions.initiateSRPWithCustomAuthAction(srpEvent) - StateResolution(InitiatingSRPA(), listOf(action)) + StateResolution(InitiatingSRPA(SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.CUSTOM_AUTH)), listOf(action)) } else -> defaultResolution } is InitiatingSRPA -> when (srpEvent) { is SRPEvent.EventType.RespondPasswordVerifier -> { val action = srpActions.verifyPasswordSRPAction( - srpEvent.challengeParameters, srpEvent.metadata, srpEvent.session + srpEvent.challengeParameters, srpEvent.metadata, srpEvent.session, oldState.signInMethod ) StateResolution(RespondingPasswordVerifier(), listOf(action)) } @@ -66,7 +68,7 @@ internal sealed class SRPSignInState : State { is RespondingPasswordVerifier -> when (srpEvent) { is SRPEvent.EventType.RetryRespondPasswordVerifier -> { val action = srpActions.verifyPasswordSRPAction( - srpEvent.challengeParameters, srpEvent.metadata, srpEvent.session + srpEvent.challengeParameters, srpEvent.metadata, srpEvent.session, srpEvent.signInMethod ) StateResolution(RespondingPasswordVerifier(), listOf(action)) } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SetupTOTPState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SetupTOTPState.kt index e3ce55329..5468f399c 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SetupTOTPState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SetupTOTPState.kt @@ -19,6 +19,7 @@ import com.amplifyframework.statemachine.StateMachineEvent import com.amplifyframework.statemachine.StateMachineResolver import com.amplifyframework.statemachine.StateResolution import com.amplifyframework.statemachine.codegen.actions.SetupTOTPActions +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.SignInTOTPSetupData import com.amplifyframework.statemachine.codegen.events.SetupTOTPEvent @@ -28,7 +29,8 @@ internal sealed class SetupTOTPState : State { data class WaitingForAnswer( val signInTOTPSetupData: SignInTOTPSetupData, var hasNewResponse: Boolean = false, - val challengeParams: Map? + val challengeParams: Map?, + val signInMethod: SignInMethod ) : SetupTOTPState() data class Verifying(val id: String = "") : SetupTOTPState() data class RespondingToAuthChallenge(val id: String = "") : SetupTOTPState() @@ -37,7 +39,8 @@ internal sealed class SetupTOTPState : State { val exception: Exception, val username: String, val session: String?, - var hasNewResponse: Boolean = false + val signInMethod: SignInMethod, + var hasNewResponse: Boolean = false, ) : SetupTOTPState() class Resolver(private val setupTOTPActions: SetupTOTPActions) : StateMachineResolver { @@ -56,7 +59,7 @@ internal sealed class SetupTOTPState : State { } is SetupTOTPEvent.EventType.ThrowAuthError -> StateResolution( - Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session) + Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session, challengeEvent.signInMethod) ) else -> defaultResolution @@ -68,13 +71,14 @@ internal sealed class SetupTOTPState : State { WaitingForAnswer( signInTOTPSetupData = challengeEvent.totpSetupDetails, hasNewResponse = true, - challengeParams = challengeEvent.challengeParams + challengeParams = challengeEvent.challengeParams, + signInMethod = challengeEvent.signInMethod ) ) } is SetupTOTPEvent.EventType.ThrowAuthError -> StateResolution( - Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session) + Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session, challengeEvent.signInMethod) ) else -> defaultResolution @@ -89,7 +93,7 @@ internal sealed class SetupTOTPState : State { } is SetupTOTPEvent.EventType.ThrowAuthError -> StateResolution( - Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session) + Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session, challengeEvent.signInMethod) ) else -> defaultResolution @@ -108,7 +112,7 @@ internal sealed class SetupTOTPState : State { } is SetupTOTPEvent.EventType.ThrowAuthError -> StateResolution( - Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session, true) + Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session, challengeEvent.signInMethod, true) ) else -> defaultResolution @@ -122,7 +126,7 @@ internal sealed class SetupTOTPState : State { } is SetupTOTPEvent.EventType.ThrowAuthError -> StateResolution( - Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session) + Error(challengeEvent.exception, challengeEvent.username, challengeEvent.session, challengeEvent.signInMethod) ) else -> defaultResolution @@ -141,7 +145,8 @@ internal sealed class SetupTOTPState : State { WaitingForAnswer( signInTOTPSetupData = challengeEvent.totpSetupDetails, hasNewResponse = true, - challengeParams = challengeEvent.challengeParams + challengeParams = challengeEvent.challengeParams, + signInMethod = challengeEvent.signInMethod ) ) } diff --git a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignInChallengeState.kt b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignInChallengeState.kt index 600301acc..6db0779a5 100644 --- a/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignInChallengeState.kt +++ b/aws-auth-cognito/src/main/java/com/amplifyframework/statemachine/codegen/states/SignInChallengeState.kt @@ -21,19 +21,25 @@ import com.amplifyframework.statemachine.StateMachineResolver import com.amplifyframework.statemachine.StateResolution import com.amplifyframework.statemachine.codegen.actions.SignInChallengeActions import com.amplifyframework.statemachine.codegen.data.AuthChallenge +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.events.SignInChallengeEvent internal sealed class SignInChallengeState : State { data class NotStarted(val id: String = "") : SignInChallengeState() data class WaitingForAnswer( val challenge: AuthChallenge, + val signInMethod: SignInMethod, var hasNewResponse: Boolean = false ) : SignInChallengeState() - data class Verifying(val id: String = "") : SignInChallengeState() + data class Verifying( + val id: String = "", + val signInMethod: SignInMethod + ) : SignInChallengeState() data class Verified(val id: String = "") : SignInChallengeState() data class Error( val exception: Exception, val challenge: AuthChallenge, + val signInMethod: SignInMethod, var hasNewResponse: Boolean = false ) : SignInChallengeState() @@ -53,7 +59,7 @@ internal sealed class SignInChallengeState : State { return when (oldState) { is NotStarted -> when (challengeEvent) { is SignInChallengeEvent.EventType.WaitForAnswer -> { - StateResolution(WaitingForAnswer(challengeEvent.challenge)) + StateResolution(WaitingForAnswer(challengeEvent.challenge, challengeEvent.signInMethod)) } else -> defaultResolution } @@ -73,6 +79,7 @@ internal sealed class SignInChallengeState : State { session = oldState.challenge.session, parameters = oldState.challenge.parameters ), + signInMethod = oldState.signInMethod, hasNewResponse = true ) ) @@ -82,9 +89,16 @@ internal sealed class SignInChallengeState : State { challengeEvent.answer, challengeEvent.metadata, challengeEvent.userAttributes, - oldState.challenge + oldState.challenge, + oldState.signInMethod + ) + StateResolution( + Verifying( + oldState.challenge.challengeName, + oldState.signInMethod + ), + listOf(action) ) - StateResolution(Verifying(oldState.challenge.challengeName), listOf(action)) } else -> defaultResolution } @@ -93,7 +107,10 @@ internal sealed class SignInChallengeState : State { is SignInChallengeEvent.EventType.ThrowError -> { StateResolution( Error( - challengeEvent.exception, challengeEvent.challenge, true + challengeEvent.exception, + challengeEvent.challenge, + oldState.signInMethod, + true ), listOf() ) @@ -104,11 +121,25 @@ internal sealed class SignInChallengeState : State { challengeEvent.metadata, challengeEvent.userAttributes, challengeEvent.authChallenge, + oldState.signInMethod + ) + StateResolution( + Verifying( + challengeEvent.authChallenge.challengeName, + oldState.signInMethod + ), + listOf(action) ) - StateResolution(Verifying(challengeEvent.authChallenge.challengeName), listOf(action)) } is SignInChallengeEvent.EventType.WaitForAnswer -> { - StateResolution(WaitingForAnswer(challengeEvent.challenge, true), listOf()) + StateResolution( + WaitingForAnswer( + challengeEvent.challenge, + oldState.signInMethod, + true + ), + listOf() + ) } else -> defaultResolution @@ -121,11 +152,24 @@ internal sealed class SignInChallengeState : State { challengeEvent.metadata, challengeEvent.userAttributes, oldState.challenge, + oldState.signInMethod + ) + StateResolution( + Verifying( + oldState.challenge.challengeName, + oldState.signInMethod + ), + listOf(action) ) - StateResolution(Verifying(oldState.challenge.challengeName), listOf(action)) } is SignInChallengeEvent.EventType.WaitForAnswer -> { - StateResolution(WaitingForAnswer(challengeEvent.challenge), listOf()) + StateResolution( + WaitingForAnswer( + challengeEvent.challenge, + oldState.signInMethod + ), + listOf() + ) } else -> defaultResolution } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt index 8f8921d86..4c0d5c39b 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginFeatureTest.kt @@ -202,11 +202,13 @@ class AWSCognitoAuthPluginFeatureTest(private val testCase: FeatureTestCase) { } is ExpectationShapes.State -> { val getStateLatch = CountDownLatch(1) - authStateMachine.getCurrentState { authState -> - assertEquals(getState(validation.expectedState), authState) + var authState: AuthState? = null + authStateMachine.getCurrentState { + authState = it getStateLatch.countDown() } getStateLatch.await(10, TimeUnit.SECONDS) + assertEquals(getState(validation.expectedState), authState) } } } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt index c6049ef76..5f196bf16 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/AWSCognitoAuthPluginTest.kt @@ -776,7 +776,7 @@ class AWSCognitoAuthPluginTest { fun listWebAuthnCredentials() { val useCase = authPlugin.useCaseFactory.listWebAuthnCredentials() authPlugin.listWebAuthnCredentials({}, {}) - coVerify { + coVerify(timeout = CHANNEL_TIMEOUT) { useCase.execute(AuthListWebAuthnCredentialsOptions.defaults()) } } @@ -786,7 +786,7 @@ class AWSCognitoAuthPluginTest { val useCase = authPlugin.useCaseFactory.listWebAuthnCredentials() val options = AWSCognitoAuthListWebAuthnCredentialsOptions.builder().build() authPlugin.listWebAuthnCredentials(options, {}, {}) - coVerify { + coVerify(timeout = CHANNEL_TIMEOUT) { useCase.execute(options) } } @@ -796,7 +796,7 @@ class AWSCognitoAuthPluginTest { val useCase = authPlugin.useCaseFactory.deleteWebAuthnCredential() val credentialId = "someId" authPlugin.deleteWebAuthnCredential(credentialId, {}, {}) - coVerify { + coVerify(timeout = CHANNEL_TIMEOUT) { useCase.execute(credentialId, AuthDeleteWebAuthnCredentialOptions.defaults()) } } @@ -807,7 +807,7 @@ class AWSCognitoAuthPluginTest { val options: AuthDeleteWebAuthnCredentialOptions = mockk() val credentialId = "someId" authPlugin.deleteWebAuthnCredential(credentialId, options, {}, {}) - coVerify { + coVerify(timeout = CHANNEL_TIMEOUT) { useCase.execute(credentialId, options) } } diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt deleted file mode 100644 index 50706c9ab..000000000 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTestBase.kt +++ /dev/null @@ -1,524 +0,0 @@ -/* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amplifyframework.auth.cognito - -import aws.sdk.kotlin.services.cognitoidentityprovider.model.ChallengeNameType -import com.amplifyframework.auth.cognito.actions.DeleteUserCognitoActions -import com.amplifyframework.auth.cognito.options.AuthFlowType -import com.amplifyframework.statemachine.Action -import com.amplifyframework.statemachine.codegen.actions.AuthActions -import com.amplifyframework.statemachine.codegen.actions.AuthenticationActions -import com.amplifyframework.statemachine.codegen.actions.AuthorizationActions -import com.amplifyframework.statemachine.codegen.actions.CustomSignInActions -import com.amplifyframework.statemachine.codegen.actions.DeviceSRPSignInActions -import com.amplifyframework.statemachine.codegen.actions.FetchAuthSessionActions -import com.amplifyframework.statemachine.codegen.actions.HostedUIActions -import com.amplifyframework.statemachine.codegen.actions.MigrateAuthActions -import com.amplifyframework.statemachine.codegen.actions.SRPActions -import com.amplifyframework.statemachine.codegen.actions.SetupTOTPActions -import com.amplifyframework.statemachine.codegen.actions.SignInActions -import com.amplifyframework.statemachine.codegen.actions.SignInChallengeActions -import com.amplifyframework.statemachine.codegen.actions.SignOutActions -import com.amplifyframework.statemachine.codegen.actions.SignUpActions -import com.amplifyframework.statemachine.codegen.actions.UserAuthSignInActions -import com.amplifyframework.statemachine.codegen.actions.WebAuthnSignInActions -import com.amplifyframework.statemachine.codegen.data.AWSCredentials -import com.amplifyframework.statemachine.codegen.data.AmplifyCredential -import com.amplifyframework.statemachine.codegen.data.AuthChallenge -import com.amplifyframework.statemachine.codegen.data.CognitoUserPoolTokens -import com.amplifyframework.statemachine.codegen.data.DeviceMetadata -import com.amplifyframework.statemachine.codegen.data.LoginsMapProvider -import com.amplifyframework.statemachine.codegen.data.SignInMethod -import com.amplifyframework.statemachine.codegen.data.SignedInData -import com.amplifyframework.statemachine.codegen.data.SignedOutData -import com.amplifyframework.statemachine.codegen.events.AuthEvent -import com.amplifyframework.statemachine.codegen.events.AuthenticationEvent -import com.amplifyframework.statemachine.codegen.events.AuthorizationEvent -import com.amplifyframework.statemachine.codegen.events.CustomSignInEvent -import com.amplifyframework.statemachine.codegen.events.FetchAuthSessionEvent -import com.amplifyframework.statemachine.codegen.events.RefreshSessionEvent -import com.amplifyframework.statemachine.codegen.events.SRPEvent -import com.amplifyframework.statemachine.codegen.events.SignInChallengeEvent -import com.amplifyframework.statemachine.codegen.events.SignInEvent -import com.amplifyframework.statemachine.codegen.events.SignOutEvent -import java.util.Date -import org.mockito.Mock -import org.mockito.Mockito - -open class StateTransitionTestBase { - - internal object MockitoHelper { - fun anyObject(): T { - Mockito.any() - return uninitialized() - } - - @Suppress("UNCHECKED_CAST") - fun uninitialized(): T = null as T - } - - @Mock - internal lateinit var signedInData: SignedInData - - @Mock - internal lateinit var credentials: AmplifyCredential - - @Mock - internal lateinit var configuration: AuthConfiguration - - @Mock - internal lateinit var cognitoAuthService: AWSCognitoAuthService - - @Mock - internal lateinit var mockAuthActions: AuthActions - - @Mock - internal lateinit var mockAuthenticationActions: AuthenticationActions - - @Mock - internal lateinit var mockAuthorizationActions: AuthorizationActions - - @Mock - internal lateinit var mockSignInActions: SignInActions - - @Mock - internal lateinit var mockDeviceSRPSignInActions: DeviceSRPSignInActions - - @Mock - internal lateinit var mockSRPActions: SRPActions - - @Mock - internal lateinit var mockSignInChallengeActions: SignInChallengeActions - - @Mock - internal lateinit var mockSignInCustomActions: CustomSignInActions - - @Mock - internal lateinit var mockMigrateAuthActions: MigrateAuthActions - - @Mock - internal lateinit var mockHostedUIActions: HostedUIActions - - @Mock - internal lateinit var mockSignOutActions: SignOutActions - - @Mock - internal lateinit var mockFetchAuthSessionActions: FetchAuthSessionActions - - @Mock - internal lateinit var mockDeleteUserActions: DeleteUserCognitoActions - - @Mock - internal lateinit var mockSetupTOTPActions: SetupTOTPActions - - @Mock - internal lateinit var mockSignUpActions: SignUpActions - - @Mock - internal lateinit var mockUserAuthSignInActions: UserAuthSignInActions - - @Mock - internal lateinit var mockWebAuthnSignInActions: WebAuthnSignInActions - - private val dummyCredential = AmplifyCredential.UserAndIdentityPool( - SignedInData( - "userId", - "username", - Date(0), - SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH), - CognitoUserPoolTokens("idToken", "accessToken", "refreshToken", 123123L) - ), - "identityPool", - AWSCredentials( - "accessKeyId", - "secretAccessKey", - "sessionToken", - 123123L - ) - ) - - internal fun setupAuthActions() { - Mockito.`when`(mockAuthActions.initializeAuthConfigurationAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthEvent(AuthEvent.EventType.ConfigureAuthentication(configuration, credentials)) - ) - } - ) - - Mockito.`when`( - mockAuthActions.initializeAuthenticationConfigurationAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthenticationEvent( - AuthenticationEvent.EventType.Configure(configuration, credentials) - ) - ) - } - ) - - Mockito.`when`( - mockAuthActions.initializeAuthorizationConfigurationAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthorizationEvent(AuthorizationEvent.EventType.Configure) - ) - } - ) - } - - internal fun setupAuthNActions() { - Mockito.`when`( - mockAuthenticationActions.initiateSignOutAction( - MockitoHelper.anyObject(), - MockitoHelper.anyObject() - ) - ).thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignOutEvent(SignOutEvent.EventType.SignOutGlobally(signedInData)) - ) - } - ) - } - - internal fun setupSignInActionWithCustomAuth() { - Mockito.`when`(mockAuthenticationActions.initiateSignInAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignInEvent( - SignInEvent.EventType.InitiateSignInWithCustom( - "username", - mapOf() - ) - ) - ) - } - ) - } - - internal fun setupAuthZActions() { - Mockito.`when`(mockAuthorizationActions.configureAuthorizationAction()) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send(AuthEvent(AuthEvent.EventType.ConfiguredAuthorization)) - } - ) - - Mockito.`when`(mockAuthorizationActions.persistCredentials(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send(AuthEvent(AuthEvent.EventType.ReceivedCachedCredentials(credentials))) - } - ) - - Mockito.`when`( - mockAuthorizationActions.initializeFetchUnAuthSession() - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - FetchAuthSessionEvent( - FetchAuthSessionEvent.EventType.FetchIdentity(LoginsMapProvider.UnAuthLogins()) - ) - ) - } - ) - - Mockito.`when`( - mockAuthorizationActions.initializeFetchAuthSession(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - FetchAuthSessionEvent( - FetchAuthSessionEvent.EventType.FetchIdentity( - LoginsMapProvider.CognitoUserPoolLogins(",", "", "") - ) - ) - ) - } - ) - - Mockito.`when`( - mockAuthorizationActions.initiateRefreshSessionAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - RefreshSessionEvent( - RefreshSessionEvent.EventType.RefreshUserPoolTokens(dummyCredential.signedInData) - ) - ) - } - ) - } - - internal fun setupSignInActions() { - Mockito.`when`(mockSignInActions.startSRPAuthAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SRPEvent( - SRPEvent.EventType.InitiateSRP( - "username", - "password", - mapOf(), - AuthFlowType.USER_SRP_AUTH - ) - ) - ) - } - ) - - Mockito.`when`(mockSignInActions.startCustomAuthAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - CustomSignInEvent( - CustomSignInEvent.EventType.InitiateCustomSignIn( - "username", - mapOf() - ) - ) - ) - } - ) - Mockito.`when`(mockSignInActions.initResolveChallenge(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignInChallengeEvent( - SignInChallengeEvent.EventType.WaitForAnswer( - AuthChallenge( - ChallengeNameType.CustomChallenge.toString(), - "Test", - "session_mock_value", - mapOf() - ) - ) - ) - ) - } - ) - } - - fun setupCustomAuthActions() { - Mockito.`when`(mockSignInCustomActions.initiateCustomSignInAuthAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - val authChallenge = AuthChallenge( - ChallengeNameType.CustomChallenge.toString(), - "Test", - "session_mock_value", - mapOf() - ) - dispatcher.send( - SignInEvent(SignInEvent.EventType.ReceivedChallenge(authChallenge)) - ) - } - ) - - Mockito.`when`( - mockSignInChallengeActions.verifyChallengeAuthAction( - MockitoHelper.anyObject(), - MockitoHelper.anyObject(), - MockitoHelper.anyObject(), - MockitoHelper.anyObject() - ) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send(SignInChallengeEvent(SignInChallengeEvent.EventType.Verified())) - dispatcher.send(CustomSignInEvent(CustomSignInEvent.EventType.FinalizeSignIn())) - dispatcher.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignInCompleted( - signedInData, - DeviceMetadata.Empty - ) - ) - ) - } - ) - } - - internal fun setupSRPActions() { - Mockito.`when`(mockSRPActions.initiateSRPAuthAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SRPEvent( - SRPEvent.EventType.RespondPasswordVerifier( - mapOf(), - mapOf(), - "sample_session" - ) - ) - ) - } - ) - - Mockito.`when`( - mockSRPActions.verifyPasswordSRPAction( - MockitoHelper.anyObject(), - MockitoHelper.anyObject(), - MockitoHelper.anyObject() - ) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignInCompleted(signedInData, DeviceMetadata.Empty) - ) - ) - } - ) - } - - internal fun setupSignOutActions() { - Mockito.`when`(mockSignOutActions.localSignOutAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignOutEvent(SignOutEvent.EventType.SignedOutSuccess(SignedOutData(signedInData.username))) - ) - dispatcher.send( - AuthenticationEvent( - AuthenticationEvent.EventType.InitializedSignedOut( - SignedOutData(signedInData.username) - ) - ) - ) - } - ) - - Mockito.`when`(mockSignOutActions.globalSignOutAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignOutEvent(SignOutEvent.EventType.RevokeToken(signedInData)) - ) - } - ) - - Mockito.`when`(mockSignOutActions.revokeTokenAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignOutEvent(SignOutEvent.EventType.SignOutLocally(signedInData)) - ) - } - ) - } - - internal fun setupFetchAuthActions() { - Mockito.`when`( - mockFetchAuthSessionActions.refreshUserPoolTokensAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - RefreshSessionEvent( - RefreshSessionEvent.EventType.RefreshAuthSession( - dummyCredential.signedInData, - LoginsMapProvider.UnAuthLogins() - ) - ) - ) - } - ) - - Mockito.`when`( - mockFetchAuthSessionActions.refreshAuthSessionAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - FetchAuthSessionEvent( - FetchAuthSessionEvent.EventType.FetchIdentity(LoginsMapProvider.UnAuthLogins()) - ) - ) - } - ) - - Mockito.`when`( - mockFetchAuthSessionActions.fetchIdentityAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - FetchAuthSessionEvent( - FetchAuthSessionEvent.EventType.FetchAwsCredentials( - "identityId", - LoginsMapProvider.UnAuthLogins() - ) - ) - ) - } - ) - - Mockito.`when`( - mockFetchAuthSessionActions.fetchAWSCredentialsAction( - "identityId", - LoginsMapProvider.UnAuthLogins() - ) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - FetchAuthSessionEvent( - FetchAuthSessionEvent.EventType.Fetched("identityId", dummyCredential.credentials) - ) - ) - } - ) - - Mockito.`when`( - mockFetchAuthSessionActions.notifySessionEstablishedAction( - "identityId", - dummyCredential.credentials - ) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthorizationEvent( - AuthorizationEvent.EventType.Fetched("identityId", dummyCredential.credentials) - ) - ) - } - ) - - Mockito.`when`( - mockFetchAuthSessionActions.notifySessionRefreshedAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthorizationEvent(AuthorizationEvent.EventType.Refreshed(dummyCredential)) - ) - } - ) - } -} diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt deleted file mode 100644 index 55b361dc1..000000000 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/StateTransitionTests.kt +++ /dev/null @@ -1,797 +0,0 @@ -/* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amplifyframework.auth.cognito - -import aws.sdk.kotlin.services.cognitoidentityprovider.model.ChallengeNameType -import com.amplifyframework.auth.cognito.options.AuthFlowType -import com.amplifyframework.statemachine.Action -import com.amplifyframework.statemachine.StateChangeListenerToken -import com.amplifyframework.statemachine.codegen.data.AuthChallenge -import com.amplifyframework.statemachine.codegen.data.DeviceMetadata -import com.amplifyframework.statemachine.codegen.data.SignInData -import com.amplifyframework.statemachine.codegen.data.SignOutData -import com.amplifyframework.statemachine.codegen.data.SignedOutData -import com.amplifyframework.statemachine.codegen.events.AuthEvent -import com.amplifyframework.statemachine.codegen.events.AuthenticationEvent -import com.amplifyframework.statemachine.codegen.events.AuthorizationEvent -import com.amplifyframework.statemachine.codegen.events.SignInChallengeEvent -import com.amplifyframework.statemachine.codegen.events.SignInEvent -import com.amplifyframework.statemachine.codegen.events.SignOutEvent -import com.amplifyframework.statemachine.codegen.states.AuthState -import com.amplifyframework.statemachine.codegen.states.AuthenticationState -import com.amplifyframework.statemachine.codegen.states.AuthorizationState -import com.amplifyframework.statemachine.codegen.states.CustomSignInState -import com.amplifyframework.statemachine.codegen.states.DeleteUserState -import com.amplifyframework.statemachine.codegen.states.DeviceSRPSignInState -import com.amplifyframework.statemachine.codegen.states.FetchAuthSessionState -import com.amplifyframework.statemachine.codegen.states.HostedUISignInState -import com.amplifyframework.statemachine.codegen.states.MigrateSignInState -import com.amplifyframework.statemachine.codegen.states.RefreshSessionState -import com.amplifyframework.statemachine.codegen.states.SRPSignInState -import com.amplifyframework.statemachine.codegen.states.SetupTOTPState -import com.amplifyframework.statemachine.codegen.states.SignInChallengeState -import com.amplifyframework.statemachine.codegen.states.SignInState -import com.amplifyframework.statemachine.codegen.states.SignOutState -import com.amplifyframework.statemachine.codegen.states.SignUpState -import com.amplifyframework.statemachine.codegen.states.WebAuthnSignInState -import io.mockk.mockk -import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit -import kotlin.test.assertEquals -import kotlin.test.assertTrue -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.newSingleThreadContext -import kotlinx.coroutines.test.resetMain -import kotlinx.coroutines.test.setMain -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.MockitoJUnitRunner - -@RunWith(MockitoJUnitRunner::class) -class StateTransitionTests : StateTransitionTestBase() { - - private val mainThreadSurrogate = newSingleThreadContext("Main thread") - - internal lateinit var stateMachine: AuthStateMachine - - @Mock - private lateinit var storeClient: CredentialStoreClient - - @Before - fun setUp() { - setupAuthActions() - setupAuthNActions() - setupAuthZActions() - setupSignInActions() - setupSRPActions() - setupSignOutActions() - setupFetchAuthActions() - setupStateMachine() - Dispatchers.setMain(mainThreadSurrogate) - } - - private fun setupStateMachine() { - stateMachine = AuthStateMachine( - AuthState.Resolver( - AuthenticationState.Resolver( - SignInState.Resolver( - SRPSignInState.Resolver(mockSRPActions), - CustomSignInState.Resolver(mockSignInCustomActions), - MigrateSignInState.Resolver(mockMigrateAuthActions), - SignInChallengeState.Resolver(mockSignInChallengeActions), - HostedUISignInState.Resolver(mockHostedUIActions), - DeviceSRPSignInState.Resolver(mockDeviceSRPSignInActions), - SetupTOTPState.Resolver(mockSetupTOTPActions), - WebAuthnSignInState.Resolver(mockWebAuthnSignInActions, mockSignInActions), - mockUserAuthSignInActions, - mockSignInActions - ), - SignOutState.Resolver(mockSignOutActions), - mockAuthenticationActions - ), - AuthorizationState.Resolver( - FetchAuthSessionState.Resolver(mockFetchAuthSessionActions), - RefreshSessionState.Resolver( - FetchAuthSessionState.Resolver(mockFetchAuthSessionActions), - mockFetchAuthSessionActions - ), - DeleteUserState.Resolver(mockDeleteUserActions), - mockAuthorizationActions - ), - mockAuthActions, - SignUpState.Resolver(mockSignUpActions) - ), - AuthEnvironment(mockk(), configuration, cognitoAuthService, storeClient, null, null, mockk()) - ) - } - - private fun setupConfigureSignedIn() { - Mockito.`when`( - mockAuthenticationActions.configureAuthenticationAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthenticationEvent( - AuthenticationEvent.EventType.InitializedSignedIn(signedInData, DeviceMetadata.Empty) - ) - ) - dispatcher.send( - AuthEvent( - AuthEvent.EventType.ConfiguredAuthentication(configuration, credentials) - ) - ) - } - ) - - Mockito.`when`( - mockAuthActions.initializeAuthorizationConfigurationAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthorizationEvent(AuthorizationEvent.EventType.CachedCredentialsAvailable(credentials)) - ) - } - ) - } - - private fun setupConfigureSignedOut() { - Mockito.`when`( - mockAuthenticationActions.configureAuthenticationAction(MockitoHelper.anyObject()) - ) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - AuthenticationEvent(AuthenticationEvent.EventType.InitializedSignedOut(SignedOutData())) - ) - dispatcher.send( - AuthEvent(AuthEvent.EventType.ConfiguredAuthentication(configuration, credentials)) - ) - } - ) - } - - private fun setupRevokeTokenSignOut() { - Mockito.`when`( - mockAuthenticationActions.initiateSignOutAction( - MockitoHelper.anyObject(), - MockitoHelper.anyObject() - ) - ).thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignOutEvent( - SignOutEvent.EventType.RevokeToken(signedInData) - ) - ) - } - ) - } - - private fun setupLocalSignOut() { - Mockito.`when`( - mockAuthenticationActions.initiateSignOutAction( - MockitoHelper.anyObject(), - MockitoHelper.anyObject() - ) - ).thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignOutEvent( - SignOutEvent.EventType.SignOutLocally(signedInData) - ) - ) - } - ) - } - - @After - fun tearDown() { - // reset main dispatcher to the original Main dispatcher - Dispatchers.resetMain() - mainThreadSurrogate.close() - } - - @Test - fun getDefaultState() { - val testLatch = CountDownLatch(1) - stateMachine.getCurrentState { - assertEquals(AuthState.NotConfigured(""), it) - testLatch.countDown() - } - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testConfigureSignedOut() { - setupConfigureSignedOut() - val listenLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - if (it is AuthState.Configured && - it.authNState is AuthenticationState.SignedOut && - it.authZState is AuthorizationState.Configured - ) { - stateMachine.cancel(token) - listenLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - val configure = AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - stateMachine.send(configure) - - assertTrue { listenLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testConfigureSignedIn() { - setupConfigureSignedIn() - - val listenLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - if (it is AuthState.Configured && - it.authNState is AuthenticationState.SignedIn && - it.authZState is AuthorizationState.SessionEstablished - ) { - stateMachine.cancel(token) - listenLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - val configure = - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - stateMachine.send(configure) - - assertTrue { listenLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testSignInSRP() { - setupConfigureSignedOut() - - Mockito.`when`(mockAuthenticationActions.initiateSignInAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignInEvent( - SignInEvent.EventType.InitiateSignInWithSRP( - "username", - "password", - emptyMap(), - AuthFlowType.USER_SRP_AUTH - ) - ) - ) - } - ) - - val testLatch = CountDownLatch(1) - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedOut } - authState?.run { - configureLatch.countDown() - stateMachine.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignInRequested( - SignInData.SRPSignInData( - "username", - "password", - emptyMap(), - AuthFlowType.USER_SRP_AUTH - ) - ) - ) - ) - } - val authNState = it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedIn && it.authZState is AuthorizationState.SessionEstablished - } - authNState?.apply { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testSignInWithCustomWithRetry() { - setupConfigureSignedOut() - setupSignInActionWithCustomAuth() - setupCustomAuthActions() - - Mockito.`when`(mockAuthenticationActions.initiateSignInAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignInEvent( - SignInEvent.EventType.InitiateSignInWithCustom( - "username", - mapOf() - ) - ) - ) - } - ) - - val testLatch = CountDownLatch(1) - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedOut } - authState?.run { - configureLatch.countDown() - stateMachine.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignInRequested( - SignInData.CustomAuthSignInData( - "username", - emptyMap() - ) - ) - ) - ) - } - - val signInState = (it.authNState as? AuthenticationState.SigningIn)?.signInState - val challengeState = signInState?.challengeState.takeIf { signInChallengeState -> - signInChallengeState is SignInChallengeState.WaitingForAnswer - } - challengeState?.apply { - stateMachine.send( - SignInChallengeEvent( - SignInChallengeEvent.EventType.RetryVerifyChallengeAnswer( - "test", - emptyMap(), - emptyList(), - AuthChallenge( - ChallengeNameType.CustomChallenge.toString(), - "Test", - "session_mock_value", - emptyMap(), - ) - ) - ) - ) - stateMachine.send( - SignInChallengeEvent( - SignInChallengeEvent.EventType.VerifyChallengeAnswer( - "test", - emptyMap(), - emptyList() - ) - ) - ) - } - - val authNState = - it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedIn && it.authZState is AuthorizationState.SessionEstablished - } - authNState?.apply { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testSignInWithCustom() { - setupConfigureSignedOut() - setupSignInActionWithCustomAuth() - setupCustomAuthActions() - - Mockito.`when`(mockAuthenticationActions.initiateSignInAction(MockitoHelper.anyObject())) - .thenReturn( - Action { dispatcher, _ -> - dispatcher.send( - SignInEvent( - SignInEvent.EventType.InitiateSignInWithCustom( - "username", - mapOf() - ) - ) - ) - } - ) - - val testLatch = CountDownLatch(1) - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedOut } - authState?.run { - configureLatch.countDown() - stateMachine.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignInRequested( - SignInData.CustomAuthSignInData( - "username", - emptyMap() - ) - ) - ) - ) - } - - val signInState = (it.authNState as? AuthenticationState.SigningIn)?.signInState - val challengeState = signInState?.challengeState.takeIf { signInChallengeState -> - signInChallengeState is SignInChallengeState.WaitingForAnswer - } - challengeState?.apply { - stateMachine.send( - SignInChallengeEvent( - SignInChallengeEvent.EventType.VerifyChallengeAnswer("test", emptyMap(), emptyList()) - ) - ) - } - - val authNState = - it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedIn && it.authZState is AuthorizationState.SessionEstablished - } - authNState?.apply { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testLocalSignOut() { - setupConfigureSignedIn() - setupLocalSignOut() - - val testLatch = CountDownLatch(1) - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedIn } - authState?.run { - configureLatch.countDown() - stateMachine.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignOutRequested(SignOutData()) - ) - ) - } - - val authNState = it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedOut && it.authZState is AuthorizationState.Configured - } - authNState?.apply { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testRevokeTokenSignOut() { - setupConfigureSignedIn() - setupRevokeTokenSignOut() - - val testLatch = CountDownLatch(1) - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedIn } - authState?.run { - configureLatch.countDown() - stateMachine.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignOutRequested(SignOutData()) - ) - ) - } - - val authNState = it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedOut && it.authZState is AuthorizationState.Configured - } - authNState?.apply { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testGlobalSignOut() { - setupConfigureSignedIn() - - val testLatch = CountDownLatch(1) - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { - val authState = - it.takeIf { it is AuthState.Configured && it.authNState is AuthenticationState.SignedIn } - authState?.run { - configureLatch.countDown() - stateMachine.send( - AuthenticationEvent( - AuthenticationEvent.EventType.SignOutRequested(SignOutData()) - ) - ) - } - - val authNState = it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedOut && it.authZState is AuthorizationState.Configured - } - authNState?.apply { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testFetchAuthSessionSignedIn() { - setupConfigureSignedIn() - val configureLatch = CountDownLatch(1) - val testLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - configureLatch.countDown() - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { it -> - val authState = it.takeIf { - it is AuthState.Configured && it.authNState is AuthenticationState.SignedIn - } - authState?.run { - configureLatch.countDown() - stateMachine.send(AuthorizationEvent(AuthorizationEvent.EventType.FetchAuthSession)) - } - - val authNState = it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedIn && it.authZState is AuthorizationState.SessionEstablished - } - authNState?.run { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testFetchAuthSessionSignedOut() { - setupConfigureSignedOut() - val configureLatch = CountDownLatch(1) - val testLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - configureLatch.countDown() - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { it -> - val authState = it.takeIf { - it is AuthState.Configured && it.authNState is AuthenticationState.SignedOut - } - authState?.run { - configureLatch.countDown() - stateMachine.send(AuthorizationEvent(AuthorizationEvent.EventType.FetchUnAuthSession)) - } - - val authNState = it.authNState.takeIf { itN -> - itN is AuthenticationState.SignedOut && it.authZState is AuthorizationState.SessionEstablished - } - authNState?.run { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - } - - @Test - fun testRefreshUserPoolTokens() { - setupConfigureSignedIn() - val configureLatch = CountDownLatch(1) - val subscribeLatch = CountDownLatch(1) - val testLatch = CountDownLatch(1) - val token = StateChangeListenerToken() - stateMachine.listen( - token, - { it -> - val authState = it.takeIf { - it is AuthState.Configured && it.authNState is AuthenticationState.SignedIn - } - authState?.run { - configureLatch.countDown() - token?.let(stateMachine::cancel) - - stateMachine.send(AuthorizationEvent(AuthorizationEvent.EventType.RefreshSession(credentials))) - stateMachine.listen( - StateChangeListenerToken(), - { it2 -> - val authNState = it2.takeIf { - it2 is AuthState.Configured && - it2.authNState is AuthenticationState.SignedIn && - it2.authZState is AuthorizationState.SessionEstablished - } - authNState?.run { - stateMachine.cancel(token) - testLatch.countDown() - } - }, - null - ) - } - }, - { - subscribeLatch.countDown() - } - ) - - assertTrue { subscribeLatch.await(5, TimeUnit.SECONDS) } - - stateMachine.send( - AuthEvent(AuthEvent.EventType.ConfigureAuth(configuration)) - ) - - assertTrue { configureLatch.await(5, TimeUnit.SECONDS) } - assertTrue { testLatch.await(5, TimeUnit.SECONDS) } - } -} diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActionsTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActionsTest.kt index 636831178..3ceb8cb68 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActionsTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SetupTOTPCognitoActionsTest.kt @@ -30,6 +30,7 @@ import com.amplifyframework.auth.cognito.StoreClientBehavior import com.amplifyframework.logging.Logger import com.amplifyframework.statemachine.EventDispatcher import com.amplifyframework.statemachine.StateMachineEvent +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.SignInTOTPSetupData import com.amplifyframework.statemachine.codegen.events.SetupTOTPEvent import io.mockk.coEvery @@ -88,7 +89,8 @@ class SetupTOTPCognitoActionsTest { val initiateAction = SetupTOTPCognitoActions.initiateTOTPSetup( SetupTOTPEvent.EventType.SetupTOTP( SignInTOTPSetupData("", "SESSION", "USERNAME"), - mapOf("MFAS_CAN_SETUP" to "SOFTWARE_TOKEN_MFA") + mapOf("MFAS_CAN_SETUP" to "SOFTWARE_TOKEN_MFA"), + signInMethod = SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) initiateAction.execute(dispatcher, authEnvironment) @@ -96,7 +98,8 @@ class SetupTOTPCognitoActionsTest { val expectedEvent = SetupTOTPEvent( SetupTOTPEvent.EventType.WaitForAnswer( SignInTOTPSetupData(secretCode, session, username), - mapOf("MFAS_CAN_SETUP" to "SOFTWARE_TOKEN_MFA") + mapOf("MFAS_CAN_SETUP" to "SOFTWARE_TOKEN_MFA"), + signInMethod = SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) assertEquals( @@ -129,13 +132,19 @@ class SetupTOTPCognitoActionsTest { val initiateAction = SetupTOTPCognitoActions.initiateTOTPSetup( SetupTOTPEvent.EventType.SetupTOTP( SignInTOTPSetupData("", "SESSION", "USERNAME"), - mapOf("MFAS_CAN_SETUP" to "SOFTWARE_TOKEN_MFA") + mapOf("MFAS_CAN_SETUP" to "SOFTWARE_TOKEN_MFA"), + signInMethod = SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) initiateAction.execute(dispatcher, authEnvironment) val expectedEvent = SetupTOTPEvent( - SetupTOTPEvent.EventType.ThrowAuthError(serviceException, "USERNAME", "SESSION") + SetupTOTPEvent.EventType.ThrowAuthError( + serviceException, + "USERNAME", + "SESSION", + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) + ) ) assertEquals( expectedEvent.type, @@ -166,7 +175,9 @@ class SetupTOTPCognitoActionsTest { } } val expectedEvent = SetupTOTPEvent( - SetupTOTPEvent.EventType.RespondToAuthChallenge(username, session) + SetupTOTPEvent.EventType.RespondToAuthChallenge( + username, session, SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) + ) ) val verifyChallengeAnswerAction = SetupTOTPCognitoActions.verifyChallengeAnswer( @@ -174,7 +185,8 @@ class SetupTOTPCognitoActionsTest { answer, username, session, - friendlyDeviceName + friendlyDeviceName, + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) verifyChallengeAnswerAction.execute(dispatcher, authEnvironment) @@ -214,7 +226,8 @@ class SetupTOTPCognitoActionsTest { SetupTOTPEvent.EventType.ThrowAuthError( Exception("An unknown service error has occurred"), "USERNAME", - "SESSION" + "SESSION", + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) @@ -223,7 +236,8 @@ class SetupTOTPCognitoActionsTest { answer, username, session, - friendlyDeviceName + friendlyDeviceName, + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) verifyChallengeAnswerAction.execute(dispatcher, authEnvironment) @@ -260,7 +274,12 @@ class SetupTOTPCognitoActionsTest { throw serviceException } val expectedEvent = SetupTOTPEvent( - SetupTOTPEvent.EventType.ThrowAuthError(serviceException, "USERNAME", "SESSION") + SetupTOTPEvent.EventType.ThrowAuthError( + serviceException, + "USERNAME", + "SESSION", + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) + ) ) val verifyChallengeAnswerAction = SetupTOTPCognitoActions.verifyChallengeAnswer( @@ -268,7 +287,8 @@ class SetupTOTPCognitoActionsTest { answer, username, session, - friendlyDeviceName + friendlyDeviceName, + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) verifyChallengeAnswerAction.execute(dispatcher, authEnvironment) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActionsTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActionsTest.kt index 4657b61e1..88069b12a 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActionsTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/SignInChallengeCognitoActionsTest.kt @@ -29,6 +29,7 @@ import com.amplifyframework.statemachine.StateMachineEvent import com.amplifyframework.statemachine.codegen.data.AmplifyCredential import com.amplifyframework.statemachine.codegen.data.AuthChallenge import com.amplifyframework.statemachine.codegen.data.CredentialType +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.UserPoolConfiguration import io.mockk.coEvery import io.mockk.every @@ -104,8 +105,9 @@ class SignInChallengeCognitoActionsTest { "CONFIRM_SIGN_IN_WITH_NEW_PASSWORD", username = username, session = null, - parameters = null - ) + parameters = null, + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ).execute(dispatcher, authEnvironment) assertTrue(capturedRequest.isCaptured) @@ -135,7 +137,8 @@ class SignInChallengeCognitoActionsTest { username = username, session = null, parameters = null - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ).execute(dispatcher, authEnvironment) assertTrue(capturedRequest.isCaptured) @@ -164,7 +167,8 @@ class SignInChallengeCognitoActionsTest { username = username, session = null, parameters = null - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ).execute(dispatcher, authEnvironment) assertTrue(capturedRequest.isCaptured) @@ -194,7 +198,8 @@ class SignInChallengeCognitoActionsTest { username = username, session = null, parameters = null - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ).execute(dispatcher, authEnvironment) assertTrue(capturedRequest.isCaptured) @@ -224,7 +229,8 @@ class SignInChallengeCognitoActionsTest { username = username, session = null, parameters = null - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ).execute(dispatcher, authEnvironment) assertTrue(capturedRequest.isCaptured) @@ -255,7 +261,8 @@ class SignInChallengeCognitoActionsTest { username = username, session = null, parameters = null - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ).execute(dispatcher, authEnvironment) assertTrue(capturedRequest.isCaptured) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/UserAuthSignInCognitoActionsTest.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/UserAuthSignInCognitoActionsTest.kt index 2e24d85d8..a0fe387ab 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/UserAuthSignInCognitoActionsTest.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/actions/UserAuthSignInCognitoActionsTest.kt @@ -33,6 +33,7 @@ import com.amplifyframework.statemachine.codegen.data.AmplifyCredential import com.amplifyframework.statemachine.codegen.data.AuthChallenge import com.amplifyframework.statemachine.codegen.data.CredentialType import com.amplifyframework.statemachine.codegen.data.DeviceMetadata +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.UserPoolConfiguration import com.amplifyframework.statemachine.codegen.data.WebAuthnSignInContext import com.amplifyframework.statemachine.codegen.events.SignInEvent @@ -132,7 +133,8 @@ class UserAuthSignInCognitoActionsTest { session = dummySession, parameters = null, availableChallenges = availableChallenges - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) @@ -201,7 +203,8 @@ class UserAuthSignInCognitoActionsTest { session = dummySession, availableChallenges = null, parameters = challengeParams - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) @@ -269,8 +272,9 @@ class UserAuthSignInCognitoActionsTest { session = dummySession, availableChallenges = null, parameters = challengeParams - ) - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) + ), ) UserAuthSignInCognitoActions.initiateUserAuthSignIn( diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt index 840bdb997..077164899 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/SerializationTools.kt @@ -86,8 +86,10 @@ internal fun AuthState.exportJson() { val signUpState = authSignUpState?.let { signUpState -> if (signUpState !is SignUpState.NotStarted) { "_${signUpState.javaClass.simpleName}" + } else { + "" } - } + } ?: "" val fileName = "${authNState?.javaClass?.simpleName}_${authZState?.javaClass?.simpleName}$signUpState.json" writeFile(result, dirName, fileName) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt index 66270dc8b..e4d8c8bd0 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/authstategenerators/AuthStateJsonGenerator.kt @@ -105,8 +105,9 @@ object AuthStateJsonGenerator : SerializableProvider { parameters = mapOf( "CODE_DELIVERY_DELIVERY_MEDIUM" to "SMS", "CODE_DELIVERY_DESTINATION" to "+12345678900" - ) - ) + ), + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.USER_SRP_AUTH) ) ) ), @@ -205,7 +206,8 @@ object AuthStateJsonGenerator : SerializableProvider { "SRP_B" to "def", "USERNAME" to "username" ) - ) + ), + SignInMethod.ApiBased(SignInMethod.ApiBased.AuthType.CUSTOM_AUTH) ) ) ), diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/ConfirmSignInTestCaseGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/ConfirmSignInTestCaseGenerator.kt index b7f2c8eb2..b4653f72f 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/ConfirmSignInTestCaseGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/ConfirmSignInTestCaseGenerator.kt @@ -281,7 +281,7 @@ object ConfirmSignInTestCaseGenerator : SerializableProvider { description = "Test that confirmsignin secondary challenge processes the custom challenge returned", preConditions = PreConditions( "authconfiguration.json", - "SigningIn_SigningIn.json", + "SigningIn_SigningIn_Custom.json", mockedResponses = listOf( mockedRespondToAuthCustomChallengeResponse ) @@ -295,7 +295,7 @@ object ConfirmSignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedConfirmSignInSuccessWithChallengeExpectation, - ExpectationShapes.State("SigningIn_SigningIn.json") + ExpectationShapes.State("SigningIn_CustomChallenge.json") ) ) @@ -343,7 +343,7 @@ object ConfirmSignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInSuccessExpectation, - ExpectationShapes.State("SignedIn_SessionEstablished.json") + ExpectationShapes.State("SignedIn_SessionEstablished_User_Auth.json") ) ) @@ -413,7 +413,7 @@ object ConfirmSignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInSuccessExpectation, - ExpectationShapes.State("SignedIn_SessionEstablished.json") + ExpectationShapes.State("SignedIn_SessionEstablished_User_Auth.json") ) ) @@ -446,7 +446,9 @@ object ConfirmSignInTestCaseGenerator : SerializableProvider { "authconfiguration_userauth.json", "SigningIn_SelectChallenge.json", mockedResponses = listOf( - mockedRespondToAuthChallengeResponse + mockedRespondToAuthChallengeResponse, + mockedIdentityIdResponse, + mockedAWSCredentialsResponse ) ), api = API( @@ -458,7 +460,7 @@ object ConfirmSignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInSuccessExpectation, - ExpectationShapes.State("SignedIn_SessionEstablished.json") + ExpectationShapes.State("SignedIn_SessionEstablished_User_Auth.json") ) ) @@ -506,7 +508,7 @@ object ConfirmSignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInSuccessExpectation, - ExpectationShapes.State("SignedIn_SessionEstablished.json") + ExpectationShapes.State("SignedIn_SessionEstablished_User_Auth.json") ) ) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt index 5b8cfc1e8..5aefff792 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/generators/testcasegenerators/SignInTestCaseGenerator.kt @@ -560,7 +560,7 @@ object SignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInSuccessExpectation, - ExpectationShapes.State("SignedIn_SessionEstablished.json") + ExpectationShapes.State("SignedIn_SessionEstablished_User_Auth.json") ) ) @@ -601,7 +601,9 @@ object SignInTestCaseGenerator : SerializableProvider { "authconfiguration_userauth.json", "SignedOut_Configured.json", mockedResponses = listOf( - mockedInitiateAuthPasswordResponse + mockedInitiateAuthPasswordResponse, + mockedIdentityIdResponse, + mockedAWSCredentialsResponse ) ), api = API( @@ -621,7 +623,7 @@ object SignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInSuccessExpectation, - ExpectationShapes.State("SignedIn_SessionEstablished.json") + ExpectationShapes.State("SignedIn_SessionEstablished_User_Auth.json") ) ) @@ -865,7 +867,7 @@ object SignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInCustomAuthChallengeExpectation, - ExpectationShapes.State("CustomSignIn_SigningIn.json") + ExpectationShapes.State("CustomSignIn_SigningIn_Password_Challenge.json") ) ) @@ -892,7 +894,7 @@ object SignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInCustomAuthChallengeExpectationWithAlias, - ExpectationShapes.State("CustomSignIn_SigningIn.json") + ExpectationShapes.State("CustomSignIn_SigningIn_With_Alias.json") ) ) @@ -920,7 +922,7 @@ object SignInTestCaseGenerator : SerializableProvider { ), validations = listOf( mockedSignInCustomAuthChallengeExpectation, - ExpectationShapes.State("CustomSignIn_SigningIn.json") + ExpectationShapes.State("CustomSignIn_SigningIn_Password_Challenge.json") ) ) diff --git a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/serializers/AuthStatesSerializer.kt b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/serializers/AuthStatesSerializer.kt index 90b782474..64a333674 100644 --- a/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/serializers/AuthStatesSerializer.kt +++ b/aws-auth-cognito/src/test/java/com/amplifyframework/auth/cognito/featuretest/serializers/AuthStatesSerializer.kt @@ -22,6 +22,7 @@ import com.amplifyframework.auth.result.AuthSignUpResult import com.amplifyframework.statemachine.codegen.data.AmplifyCredential import com.amplifyframework.statemachine.codegen.data.AuthChallenge import com.amplifyframework.statemachine.codegen.data.DeviceMetadata +import com.amplifyframework.statemachine.codegen.data.SignInMethod import com.amplifyframework.statemachine.codegen.data.SignUpData import com.amplifyframework.statemachine.codegen.data.SignedInData import com.amplifyframework.statemachine.codegen.data.SignedOutData @@ -72,7 +73,9 @@ internal data class AuthStatesProxy( @Contextual val authChallenge: AuthChallenge? = null, @Contextual - val amplifyCredential: AmplifyCredential? = null + val amplifyCredential: AmplifyCredential? = null, + @Contextual + val signInMethod: SignInMethod? = null ) { internal fun toRealAuthState(): T { @@ -107,7 +110,7 @@ internal data class AuthStatesProxy( "AuthorizationState.SigningIn" -> AuthorizationState.SigningIn() as T "SignInState.ResolvingChallenge" -> SignInState.ResolvingChallenge(signInChallengeState) as T "SignInChallengeState.WaitingForAnswer" -> authChallenge?.let { - SignInChallengeState.WaitingForAnswer(it) + SignInChallengeState.WaitingForAnswer(it, signInMethod!!) } as T else -> { error("Cannot get real type!") @@ -210,7 +213,8 @@ internal data class AuthStatesProxy( is SignInChallengeState.Verifying -> TODO() is SignInChallengeState.WaitingForAnswer -> AuthStatesProxy( type = "SignInChallengeState.WaitingForAnswer", - authChallenge = authState.challenge + authChallenge = authState.challenge, + signInMethod = authState.signInMethod ) is SignInChallengeState.Error -> TODO() } diff --git a/aws-auth-cognito/src/test/java/featureTest/utilities/CognitoMockFactory.kt b/aws-auth-cognito/src/test/java/featureTest/utilities/CognitoMockFactory.kt index ab50a9b02..af49dfe80 100644 --- a/aws-auth-cognito/src/test/java/featureTest/utilities/CognitoMockFactory.kt +++ b/aws-auth-cognito/src/test/java/featureTest/utilities/CognitoMockFactory.kt @@ -114,7 +114,7 @@ class CognitoMockFactory( parseAvailableChallenges(it as JsonArray) } - this.session = responseObject["session"]?.toString() + this.session = (responseObject["session"] as? JsonPrimitive)?.content } } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json index e69e8f666..692838311 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn.json @@ -16,11 +16,18 @@ "SRP_B": "def", "USERNAME": "username" } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "CUSTOM_AUTH" } } } }, "AuthorizationState": { "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn_Password_Challenge.json b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn_Password_Challenge.json new file mode 100644 index 000000000..e48210645 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn_Password_Challenge.json @@ -0,0 +1,33 @@ +{ + "type": "AuthState.Configured", + "AuthenticationState": { + "type": "AuthenticationState.SigningIn", + "SignInState": { + "type": "SignInState.ResolvingChallenge", + "SignInChallengeState": { + "type": "SignInChallengeState.WaitingForAnswer", + "authChallenge": { + "challengeName": "CUSTOM_CHALLENGE", + "username": "username", + "session": "someSession", + "parameters": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def", + "USERNAME": "username" + } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "CUSTOM_AUTH" + } + } + } + }, + "AuthorizationState": { + "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" + } +} diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn_With_Alias.json b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn_With_Alias.json new file mode 100644 index 000000000..379da2c83 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/states/CustomSignIn_SigningIn_With_Alias.json @@ -0,0 +1,33 @@ +{ + "type": "AuthState.Configured", + "AuthenticationState": { + "type": "AuthenticationState.SigningIn", + "SignInState": { + "type": "SignInState.ResolvingChallenge", + "SignInChallengeState": { + "type": "SignInChallengeState.WaitingForAnswer", + "authChallenge": { + "challengeName": "CUSTOM_CHALLENGE", + "username": "username", + "session": "someSession", + "parameters": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def", + "USERNAME": "alternateUsername" + } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "CUSTOM_AUTH" + } + } + } + }, + "AuthorizationState": { + "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" + } +} diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SignedIn_SessionEstablished_User_Auth.json b/aws-auth-cognito/src/test/resources/feature-test/states/SignedIn_SessionEstablished_User_Auth.json new file mode 100644 index 000000000..7dffd662a --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SignedIn_SessionEstablished_User_Auth.json @@ -0,0 +1,52 @@ +{ + "type": "AuthState.Configured", + "AuthenticationState": { + "type": "AuthenticationState.SignedIn", + "signedInData": { + "userId": "userId", + "username": "username", + "signedInDate": 1707022800000, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "USER_AUTH" + }, + "cognitoUserPoolTokens": { + "idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "expiration": 300 + } + } + }, + "AuthorizationState": { + "type": "AuthorizationState.SessionEstablished", + "amplifyCredential": { + "type": "userAndIdentityPool", + "signedInData": { + "userId": "userId", + "username": "username", + "signedInDate": 1707022800000, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "USER_AUTH" + }, + "cognitoUserPoolTokens": { + "idToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "expiration": 300 + } + }, + "identityId": "someIdentityId", + "credentials": { + "accessKeyId": "someAccessKey", + "secretAccessKey": "someSecretKey", + "sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "expiration": 2342134 + } + } + }, + "SignUpState": { + "type": "SignUpState.NotStarted" + } +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_CustomChallenge.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_CustomChallenge.json new file mode 100644 index 000000000..02e9ec187 --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_CustomChallenge.json @@ -0,0 +1,32 @@ +{ + "type": "AuthState.Configured", + "AuthenticationState": { + "type": "AuthenticationState.SigningIn", + "SignInState": { + "type": "SignInState.ResolvingChallenge", + "SignInChallengeState": { + "type": "SignInChallengeState.WaitingForAnswer", + "authChallenge": { + "challengeName": "CUSTOM_CHALLENGE", + "username": "username", + "session": "someSession", + "parameters": { + "SALT": "abc", + "SECRET_BLOCK": "secretBlock", + "SRP_B": "def" + } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "CUSTOM_AUTH" + } + } + } + }, + "AuthorizationState": { + "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" + } +} diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_EmailOtp.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_EmailOtp.json index 4d463f3e3..4f54d6152 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_EmailOtp.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_EmailOtp.json @@ -14,11 +14,18 @@ "CODE_DELIVERY_DELIVERY_MEDIUM": "EMAIL", "CODE_DELIVERY_DESTINATION": "test@****.com" } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "USER_AUTH" } } } }, "AuthorizationState": { "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SelectChallenge.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SelectChallenge.json index ffcbf38f9..37fa70cbe 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SelectChallenge.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SelectChallenge.json @@ -10,13 +10,24 @@ "challengeName": "SELECT_CHALLENGE", "username": "username", "session": "someSession", - "parameters" : {}, - "availableChallenges": [ "PASSWORD", "WEB_AUTHN", "EMAIL_OTP" ] + "parameters": null, + "availableChallenges": [ + "PASSWORD", + "WEB_AUTHN", + "EMAIL_OTP" + ] + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "USER_AUTH" } } } }, "AuthorizationState": { "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" } -} +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json index 99bf4e5a7..825c3b411 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn.json @@ -14,6 +14,10 @@ "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", "CODE_DELIVERY_DESTINATION": "+12345678900" } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "USER_SRP_AUTH" } } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_Custom.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_Custom.json new file mode 100644 index 000000000..16d9ab91e --- /dev/null +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SigningIn_Custom.json @@ -0,0 +1,31 @@ +{ + "type": "AuthState.Configured", + "AuthenticationState": { + "type": "AuthenticationState.SigningIn", + "SignInState": { + "type": "SignInState.ResolvingChallenge", + "SignInChallengeState": { + "type": "SignInChallengeState.WaitingForAnswer", + "authChallenge": { + "challengeName": "SMS_MFA", + "username": "username", + "session": "someSession", + "parameters": { + "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", + "CODE_DELIVERY_DESTINATION": "+12345678900" + } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "CUSTOM_AUTH" + } + } + } + }, + "AuthorizationState": { + "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" + } +} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SmsOtp.json b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SmsOtp.json index 365d9d853..949e1b311 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SmsOtp.json +++ b/aws-auth-cognito/src/test/resources/feature-test/states/SigningIn_SmsOtp.json @@ -14,11 +14,18 @@ "CODE_DELIVERY_DELIVERY_MEDIUM": "SMS", "CODE_DELIVERY_DESTINATION": "+12345678900" } + }, + "signInMethod": { + "type": "SignInMethod.ApiBased", + "authType": "USER_AUTH" } } } }, "AuthorizationState": { "type": "AuthorizationState.SigningIn" + }, + "SignUpState": { + "type": "SignUpState.NotStarted" } } diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_confirmsignin_secondary_challenge_processes_the_custom_challenge_returned.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_confirmsignin_secondary_challenge_processes_the_custom_challenge_returned.json index c2eee5486..8769505e9 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_confirmsignin_secondary_challenge_processes_the_custom_challenge_returned.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_confirmsignin_secondary_challenge_processes_the_custom_challenge_returned.json @@ -2,7 +2,7 @@ "description": "Test that confirmsignin secondary challenge processes the custom challenge returned", "preConditions": { "amplify-configuration": "authconfiguration.json", - "state": "SigningIn_SigningIn.json", + "state": "SigningIn_SigningIn_Custom.json", "mockedResponses": [ { "type": "cognitoIdentityProvider", @@ -25,8 +25,7 @@ "params": { "challengeResponse": "000000" }, - "options": { - } + "options": {} }, "validations": [ { @@ -47,7 +46,7 @@ }, { "type": "state", - "expectedState": "SigningIn_SigningIn.json" + "expectedState": "SigningIn_CustomChallenge.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_SMS_OTP_code_signs_the_user_in.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_SMS_OTP_code_signs_the_user_in.json index 924dc954c..fe93a365f 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_SMS_OTP_code_signs_the_user_in.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_SMS_OTP_code_signs_the_user_in.json @@ -62,7 +62,7 @@ }, { "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" + "expectedState": "SignedIn_SessionEstablished_User_Auth.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_email_OTP_code_signs_the_user_in.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_email_OTP_code_signs_the_user_in.json index a8760d917..78a2d327a 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_email_OTP_code_signs_the_user_in.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_entering_the_correct_email_OTP_code_signs_the_user_in.json @@ -62,7 +62,7 @@ }, { "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" + "expectedState": "SignedIn_SessionEstablished_User_Auth.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_SRP_challenge_with_the_correct_password_succeeds.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_SRP_challenge_with_the_correct_password_succeeds.json index 2415a288e..4143f76f1 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_SRP_challenge_with_the_correct_password_succeeds.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_SRP_challenge_with_the_correct_password_succeeds.json @@ -77,7 +77,7 @@ }, { "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" + "expectedState": "SignedIn_SessionEstablished_User_Auth.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_challenge_with_the_correct_password_succeeds.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_challenge_with_the_correct_password_succeeds.json index 833cc6820..d9f3c614a 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_challenge_with_the_correct_password_succeeds.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/confirmSignIn/Test_that_selecting_the_PASSWORD_challenge_with_the_correct_password_succeeds.json @@ -16,6 +16,27 @@ "expiresIn": 300 } } + }, + { + "type": "cognitoIdentity", + "apiName": "getId", + "responseType": "success", + "response": { + "identityId": "someIdentityId" + } + }, + { + "type": "cognitoIdentity", + "apiName": "getCredentialsForIdentity", + "responseType": "success", + "response": { + "credentials": { + "accessKeyId": "someAccessKey", + "secretKey": "someSecretKey", + "sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "expiration": 2342134 + } + } } ] }, @@ -41,7 +62,7 @@ }, { "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" + "expectedState": "SignedIn_SessionEstablished_User_Auth.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_ResourceNotFoundException_and_then_received_proper_cognito_request_and_returns_password_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_ResourceNotFoundException_and_then_received_proper_cognito_request_and_returns_password_challenge.json index 701f4c11b..5ee2ca952 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_ResourceNotFoundException_and_then_received_proper_cognito_request_and_returns_password_challenge.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_ResourceNotFoundException_and_then_received_proper_cognito_request_and_returns_password_challenge.json @@ -77,7 +77,7 @@ }, { "type": "state", - "expectedState": "CustomSignIn_SigningIn.json" + "expectedState": "CustomSignIn_SigningIn_Password_Challenge.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json index 36e642f1f..566ba759b 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge.json @@ -68,7 +68,7 @@ }, { "type": "state", - "expectedState": "CustomSignIn_SigningIn.json" + "expectedState": "CustomSignIn_SigningIn_Password_Challenge.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge_when_alias_is_used.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge_when_alias_is_used.json index c83e9eae6..833530e9a 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge_when_alias_is_used.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_Custom_Auth_signIn_invokes_proper_cognito_request_and_returns_password_challenge_when_alias_is_used.json @@ -68,7 +68,7 @@ }, { "type": "state", - "expectedState": "CustomSignIn_SigningIn.json" + "expectedState": "CustomSignIn_SigningIn_With_Alias.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_invokes_proper_cognito_request_and_returns_success.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_invokes_proper_cognito_request_and_returns_success.json deleted file mode 100644 index 8e26d7fba..000000000 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_invokes_proper_cognito_request_and_returns_success.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "description": "Test that USER_AUTH signIn invokes proper cognito request and returns success", - "preConditions": { - "amplify-configuration": "authconfiguration_userauth.json", - "state": "SignedOut_Configured.json", - "mockedResponses": [ - { - "type": "cognitoIdentityProvider", - "apiName": "initiateAuth", - "responseType": "success", - "response": { - "challengeName": "SELECT_CHALLENGE", - "session": "session-id", - "parameters": {}, - "availableChallenges": [ - "PASSWORD", - "WEB_AUTHN", - "EMAIL_OTP" - ] - } - } - ] - }, - "api": { - "name": "signIn", - "params": { - "username": "username", - "password": "" - }, - "options": { - "signInOptions": { - "authFlow": "USER_AUTH", - "preferredFirstFactor": null - } - } - }, - "validations": [ - { - "type": "amplify", - "apiName": "signIn", - "responseType": "success", - "response": { - "isSignedIn": false, - "nextStep": { - "signInStep": "CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION", - "additionalInfo": {}, - "availableFactors": [ - "PASSWORD", - "WEB_AUTHN", - "EMAIL_OTP" - ] - } - } - }, - { - "type": "state", - "expectedState": "SigningIn_SelectChallenge.json" - } - ] -} \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_fails.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_fails.json index 23328eccc..a2536d85b 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_fails.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_fails.json @@ -32,7 +32,7 @@ { "type": "amplify", "apiName": "signIn", - "responseType": "success", + "responseType": "failure", "response": { "errorType": "NotAuthorizedException", "errorMessage": "Failed since user is not authorized.", diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_succeeds.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_succeeds.json index 2c28e8ba0..c0a449d14 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_succeeds.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_SRP_preference_succeeds.json @@ -83,7 +83,7 @@ }, { "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" + "expectedState": "SignedIn_SessionEstablished_User_Auth.json" } ] } \ No newline at end of file diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_fails.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_fails.json index 52fdb8f5f..2d0503715 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_fails.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_fails.json @@ -32,7 +32,7 @@ { "type": "amplify", "apiName": "signIn", - "responseType": "success", + "responseType": "failure", "response": { "errorType": "NotAuthorizedException", "errorMessage": "Failed since user is not authorized.", diff --git a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_succeeds.json b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_succeeds.json index 796c90ca8..843e4c498 100644 --- a/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_succeeds.json +++ b/aws-auth-cognito/src/test/resources/feature-test/testsuites/signIn/Test_that_USER_AUTH_signIn_with_PASSWORD_preference_succeeds.json @@ -16,6 +16,27 @@ "expiresIn": 300 } } + }, + { + "type": "cognitoIdentity", + "apiName": "getId", + "responseType": "success", + "response": { + "identityId": "someIdentityId" + } + }, + { + "type": "cognitoIdentity", + "apiName": "getCredentialsForIdentity", + "responseType": "success", + "response": { + "credentials": { + "accessKeyId": "someAccessKey", + "secretKey": "someSecretKey", + "sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VySWQiLCJ1c2VybmFtZSI6InVzZXJuYW1lIiwiZXhwIjoxNTE2MjM5MDIyLCJvcmlnaW5fanRpIjoib3JpZ2luX2p0aSJ9.Xqa-vjJe5wwwsqeRAdHf8kTBn_rYSkDn2lB7xj9Z1xU", + "expiration": 2342134 + } + } } ] }, @@ -47,7 +68,7 @@ }, { "type": "state", - "expectedState": "SignedIn_SessionEstablished.json" + "expectedState": "SignedIn_SessionEstablished_User_Auth.json" } ] } \ No newline at end of file