Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -143,8 +143,8 @@ class AuthenticatorViewModelTest {
coVerify(exactly = 1) {
authProvider.fetchAuthSession()
authProvider.getCurrentUser()
authProvider.signOut()
}
viewModel.currentStep shouldBe AuthenticatorStep.SignIn
}

@Test
Expand Down Expand Up @@ -220,6 +220,73 @@ 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 `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))
Expand Down