mirror of
https://github.com/bitwarden/android.git
synced 2024-11-25 02:46:00 +03:00
BIT-2106: Export vault file with password (#1241)
This commit is contained in:
parent
ee12bd9da5
commit
bf26db1d4f
2 changed files with 59 additions and 2 deletions
|
@ -272,7 +272,13 @@ class ExportVaultViewModel @Inject constructor(
|
|||
|
||||
viewModelScope.launch {
|
||||
val result = vaultRepository.exportVaultDataToString(
|
||||
format = state.exportFormat.toExportFormat(state.passwordInput),
|
||||
format = state.exportFormat.toExportFormat(
|
||||
password = if (state.exportFormat == ExportVaultFormat.JSON_ENCRYPTED) {
|
||||
state.filePasswordInput
|
||||
} else {
|
||||
state.passwordInput
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
sendAction(
|
||||
|
@ -308,8 +314,11 @@ class ExportVaultViewModel @Inject constructor(
|
|||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
confirmFilePasswordInput = "",
|
||||
dialogState = null,
|
||||
filePasswordInput = "",
|
||||
passwordInput = "",
|
||||
passwordStrengthState = PasswordStrengthState.NONE,
|
||||
exportData = result.vaultData,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.exportvault
|
|||
import android.net.Uri
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.bitwarden.core.ExportFormat
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
|
@ -51,7 +52,7 @@ class ExportVaultViewModelTest : BaseViewModelTest() {
|
|||
)
|
||||
|
||||
private val vaultRepository: VaultRepository = mockk {
|
||||
coEvery { exportVaultDataToString(any()) } returns mockk()
|
||||
coEvery { exportVaultDataToString(any()) } returns ExportVaultDataResult.Success("data")
|
||||
}
|
||||
private val fileManager: FileManager = mockk()
|
||||
|
||||
|
@ -104,6 +105,53 @@ class ExportVaultViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `ConfirmExportVaultClicked should show success with valid input when export type is JSON_ENCRYPTED`() {
|
||||
val filePassword = "filePassword"
|
||||
val password = "password"
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
confirmFilePasswordInput = filePassword,
|
||||
exportFormat = ExportVaultFormat.JSON_ENCRYPTED,
|
||||
filePasswordInput = filePassword,
|
||||
passwordInput = password,
|
||||
passwordStrengthState = PasswordStrengthState.STRONG,
|
||||
)
|
||||
coEvery {
|
||||
authRepository.getPasswordStrength(
|
||||
email = EMAIL_ADDRESS,
|
||||
password = password,
|
||||
)
|
||||
} returns PasswordStrengthResult.Success(
|
||||
passwordStrength = PasswordStrength.LEVEL_4,
|
||||
)
|
||||
coEvery {
|
||||
authRepository.validatePassword(
|
||||
password = password,
|
||||
)
|
||||
} returns ValidatePasswordResult.Success(isValid = true)
|
||||
val viewModel = createViewModel(
|
||||
initialState = initialState,
|
||||
)
|
||||
viewModel.trySendAction(ExportVaultAction.ConfirmExportVaultClicked)
|
||||
assertEquals(
|
||||
initialState.copy(
|
||||
confirmFilePasswordInput = "",
|
||||
exportData = "data",
|
||||
filePasswordInput = "",
|
||||
passwordInput = "",
|
||||
passwordStrengthState = PasswordStrengthState.NONE,
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
coVerify {
|
||||
authRepository.validatePassword(password)
|
||||
vaultRepository.exportVaultDataToString(
|
||||
format = ExportFormat.EncryptedJson(filePassword),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ConfirmExportVaultClicked blank password should show an error`() {
|
||||
val viewModel = createViewModel()
|
||||
|
|
Loading…
Reference in a new issue