From e207d4334b9ec777f399c6d3078ca0b220ec2658 Mon Sep 17 00:00:00 2001 From: Edison Zhang Date: Thu, 19 Sep 2024 10:53:33 -0700 Subject: [PATCH 1/5] moveTo SignIn is not needed due to signOut() --- .../amplifyframework/ui/authenticator/AuthenticatorViewModel.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt index 4df7cdaa..6e9bac97 100644 --- a/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt +++ b/authenticator/src/main/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModel.kt @@ -582,7 +582,6 @@ internal class AuthenticatorViewModel( logger.error(result.error.toString()) logger.error("Current signed in user session has expired, signing out.") signOut() - moveTo(AuthenticatorStep.SignIn) } else { handleGeneralFailure(result.error) } From a3684fc654f229d4406a01ab1a1b48e5472ffa51 Mon Sep 17 00:00:00 2001 From: Edison Zhang Date: Mon, 23 Sep 2024 14:15:32 -0700 Subject: [PATCH 2/5] update test cases for when getCurrentUser error with SessionExpiredException during start --- .../ui/authenticator/AuthenticatorViewModelTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt index 77e727e2..bf2ce8c6 100644 --- a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt +++ b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt @@ -133,7 +133,7 @@ class AuthenticatorViewModelTest { } @Test - fun `getCurrentUser error with session expired exception during start results in SignIn state`() = runTest { + fun `getCurrentUser error with session expired exception during start results in being signed out`() = runTest { coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = true)) coEvery { authProvider.getCurrentUser() } returns AmplifyResult.Error(SessionExpiredException()) @@ -143,8 +143,8 @@ class AuthenticatorViewModelTest { coVerify(exactly = 1) { authProvider.fetchAuthSession() authProvider.getCurrentUser() + authProvider.signOut() } - viewModel.currentStep shouldBe AuthenticatorStep.SignIn } @Test From 5d94b82c23197dfe92b851937493db994e6e86b1 Mon Sep 17 00:00:00 2001 From: Edison Zhang Date: Mon, 23 Sep 2024 17:53:29 -0700 Subject: [PATCH 3/5] complete tests for signIn next step is CONFIRM_SIGN_IN_WITH_*** --- .../AuthenticatorViewModelTest.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt index bf2ce8c6..bf2a8a38 100644 --- a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt +++ b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt @@ -220,6 +220,45 @@ class AuthenticatorViewModelTest { viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmTotpCode } + @Test + fun `SMS MFA Code next step shows the SignInConfirmMfa screen`() = runTest { + coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false)) + coEvery { authProvider.signIn(any(), any()) } returns Success( + mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_IN_WITH_SMS_MFA_CODE) + ) + + viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn)) + + viewModel.signIn("username", "password") + viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmMfa + } + + @Test + fun `Custom Challenge next step shows the SignInConfirmCustomAuth screen`() = runTest { + coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false)) + coEvery { authProvider.signIn(any(), any()) } returns Success( + mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE) + ) + + viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn)) + + viewModel.signIn("username", "password") + viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmCustomAuth + } + + @Test + fun `New Password next step shows the SignInConfirmNewPassword screen`() = runTest { + coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false)) + coEvery { authProvider.signIn(any(), any()) } returns Success( + mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_IN_WITH_NEW_PASSWORD) + ) + + viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn)) + + viewModel.signIn("username", "password") + viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmNewPassword + } + @Test fun `MFA selection next step shows error if allowedMFATypes is null`() = runTest { coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false)) From d0fd904cece6012b80bb73dc2b14c7cb279840f5 Mon Sep 17 00:00:00 2001 From: Edison Zhang Date: Mon, 23 Sep 2024 21:16:15 -0700 Subject: [PATCH 4/5] added test cases when next signIn step is ConfirmSignUp --- .../AuthenticatorViewModelTest.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt index bf2a8a38..e77cec91 100644 --- a/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt +++ b/authenticator/src/test/java/com/amplifyframework/ui/authenticator/AuthenticatorViewModelTest.kt @@ -259,6 +259,34 @@ class AuthenticatorViewModelTest { viewModel.currentStep shouldBe AuthenticatorStep.SignInConfirmNewPassword } + @Test + fun `Confirm SignUp next step, get error from resendSignUpCode, stays in SignIn screen`() = runTest { + coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false)) + coEvery { authProvider.signIn(any(), any()) } returns Success( + mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_UP) + ) + coEvery { authProvider.resendSignUpCode(any()) } returns AmplifyResult.Error(mockAuthException()) + + viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn)) + + viewModel.signIn("username", "password") + viewModel.currentStep shouldBe AuthenticatorStep.SignIn + } + + @Test + fun `Confirm SignUp next step shows the SignUpConfirm screen`() = runTest { + coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false)) + coEvery { authProvider.signIn(any(), any()) } returns Success( + mockSignInResult(signInStep = AuthSignInStep.CONFIRM_SIGN_UP) + ) + coEvery { authProvider.resendSignUpCode(any()) } returns Success(mockk()) + + viewModel.start(mockAuthenticatorConfiguration(initialStep = AuthenticatorStep.SignIn)) + + viewModel.signIn("username", "password") + viewModel.currentStep shouldBe AuthenticatorStep.SignUpConfirm + } + @Test fun `MFA selection next step shows error if allowedMFATypes is null`() = runTest { coEvery { authProvider.fetchAuthSession() } returns Success(mockAuthSession(isSignedIn = false)) From 6349059521d4065ce4555cc1a1357ff052013f03 Mon Sep 17 00:00:00 2001 From: Edison Zhang Date: Tue, 24 Sep 2024 15:01:12 -0700 Subject: [PATCH 5/5] retrigger checks