mirror of
https://github.com/bitwarden/android.git
synced 2025-12-11 04:39:19 -06:00
[PM-23546] Update 2FA verification code accept any length (#5500)
Co-authored-by: Patrick Honkonen <1883101+SaintPatrck@users.noreply.github.com>
This commit is contained in:
parent
929233081c
commit
c5a40a89d9
@ -247,7 +247,7 @@ private fun TwoFactorLoginScreenContent(
|
||||
Spacer(modifier = Modifier.height(height = 12.dp))
|
||||
Text(
|
||||
text = if (state.isNewDeviceVerification) {
|
||||
R.string.enter_verification_code_new_device.asText(state.displayEmail).invoke()
|
||||
stringResource(R.string.enter_verification_code_new_device)
|
||||
} else {
|
||||
state.authMethod.description(
|
||||
state.displayEmail,
|
||||
|
||||
@ -190,12 +190,10 @@ class TwoFactorLoginViewModel @Inject constructor(
|
||||
* Update the state with the new text and enable or disable the continue button.
|
||||
*/
|
||||
private fun handleCodeInputChanged(action: TwoFactorLoginAction.CodeInputChanged) {
|
||||
@Suppress("MagicNumber")
|
||||
val minLength = if (state.isNewDeviceVerification) 8 else 6
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
codeInput = action.input,
|
||||
isContinueButtonEnabled = action.input.length >= minLength,
|
||||
isContinueButtonEnabled = action.input.isNotEmpty(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@
|
||||
<string name="authenticator_app_title">Authenticator app</string>
|
||||
<string name="enter_verification_code_app">Enter the 6 digit verification code from your authenticator app.</string>
|
||||
<string name="enter_verification_code_email">Enter the 6 digit verification code that was emailed to %1$s.</string>
|
||||
<string name="enter_verification_code_new_device">We don\'t recognize this device. Enter the 8 digit verification code that was emailed to %1$s.</string>
|
||||
<string name="enter_verification_code_new_device">We don\'t recognize this device. Enter the code sent to your email to verify your identity.</string>
|
||||
<string name="recovery_code_title">Recovery code</string>
|
||||
<string name="remember">Remember</string>
|
||||
<string name="remember_email">Remember email</string>
|
||||
|
||||
@ -318,15 +318,14 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `Continue buttons should only be enabled when code is 8 digit enough on isNewDeviceVerification`() {
|
||||
val initialState = DEFAULT_STATE.copy(isNewDeviceVerification = true)
|
||||
val viewModel = createViewModel(initialState)
|
||||
viewModel.trySendAction(TwoFactorLoginAction.CodeInputChanged("123456"))
|
||||
fun `Continue buttons should only be enabled when code is not empty`() {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(TwoFactorLoginAction.CodeInputChanged(""))
|
||||
|
||||
// 6 digit should be false when isNewDeviceVerification is true.
|
||||
assertEquals(
|
||||
initialState.copy(
|
||||
codeInput = "123456",
|
||||
DEFAULT_STATE.copy(
|
||||
codeInput = "",
|
||||
isContinueButtonEnabled = false,
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
@ -335,7 +334,7 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
||||
// Set it to true.
|
||||
viewModel.trySendAction(TwoFactorLoginAction.CodeInputChanged("12345678"))
|
||||
assertEquals(
|
||||
initialState.copy(
|
||||
DEFAULT_STATE.copy(
|
||||
codeInput = "12345678",
|
||||
isContinueButtonEnabled = true,
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user