mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
BIT-2104: Add check for file passwords matching (#1222)
This commit is contained in:
parent
af37f1c03c
commit
f09d9473f7
2 changed files with 57 additions and 12 deletions
|
@ -129,18 +129,29 @@ class ExportVaultViewModel @Inject constructor(
|
|||
)
|
||||
return
|
||||
} else if (state.exportFormat == ExportVaultFormat.JSON_ENCRYPTED) {
|
||||
if (state.filePasswordInput.isBlank()) {
|
||||
updateStateWithError(
|
||||
message = R.string.validation_field_required
|
||||
.asText(R.string.file_password.asText()),
|
||||
)
|
||||
return
|
||||
} else if (state.confirmFilePasswordInput.isBlank()) {
|
||||
updateStateWithError(
|
||||
message = R.string.validation_field_required
|
||||
.asText(R.string.confirm_file_password.asText()),
|
||||
)
|
||||
return
|
||||
when {
|
||||
state.filePasswordInput.isBlank() -> {
|
||||
updateStateWithError(
|
||||
message = R.string.validation_field_required
|
||||
.asText(R.string.file_password.asText()),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
state.confirmFilePasswordInput.isBlank() -> {
|
||||
updateStateWithError(
|
||||
message = R.string.validation_field_required
|
||||
.asText(R.string.confirm_file_password.asText()),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
state.filePasswordInput != state.confirmFilePasswordInput -> {
|
||||
updateStateWithError(
|
||||
message = R.string.master_password_confirmation_val_message.asText(),
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -208,6 +208,40 @@ class ExportVaultViewModelTest : BaseViewModelTest() {
|
|||
)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `ConfirmExportVaultClicked non-matching file passwords should show an error when export type is JSON_ENCRYPTED`() {
|
||||
val password = "password"
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
confirmFilePasswordInput = "random",
|
||||
exportFormat = ExportVaultFormat.JSON_ENCRYPTED,
|
||||
filePasswordInput = password,
|
||||
passwordInput = password,
|
||||
passwordStrengthState = PasswordStrengthState.STRONG,
|
||||
)
|
||||
coEvery {
|
||||
authRepository.getPasswordStrength(
|
||||
email = EMAIL_ADDRESS,
|
||||
password = password,
|
||||
)
|
||||
} returns PasswordStrengthResult.Success(
|
||||
passwordStrength = PasswordStrength.LEVEL_4,
|
||||
)
|
||||
val viewModel = createViewModel(
|
||||
initialState = initialState,
|
||||
)
|
||||
viewModel.trySendAction(ExportVaultAction.ConfirmExportVaultClicked)
|
||||
assertEquals(
|
||||
initialState.copy(
|
||||
dialogState = ExportVaultState.DialogState.Error(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = R.string.master_password_confirmation_val_message.asText(),
|
||||
),
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ConfirmExportVaultClicked invalid password should show an error`() {
|
||||
val password = "password"
|
||||
|
|
Loading…
Add table
Reference in a new issue