From ffeae9372897241ed75e30aee282c8d61e10594d Mon Sep 17 00:00:00 2001 From: David Perez Date: Mon, 18 Nov 2024 09:05:00 -0600 Subject: [PATCH] PM-12733: Trim totp codes before saving them (#4315) --- .../vault/feature/manualcodeentry/ManualCodeEntryViewModel.kt | 2 +- .../feature/manualcodeentry/ManualCodeEntryViewModelTests.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModel.kt index 172afcc9a..fccbcbbc9 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModel.kt @@ -46,7 +46,7 @@ class ManualCodeEntryViewModel @Inject constructor( } private fun handleCodeSubmit() { - vaultRepository.emitTotpCodeResult(TotpCodeResult.Success(state.code)) + vaultRepository.emitTotpCodeResult(TotpCodeResult.Success(state.code.trim())) sendEvent(ManualCodeEntryEvent.NavigateBack) } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModelTests.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModelTests.kt index 585c1d7af..d7f76d3aa 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModelTests.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/manualcodeentry/ManualCodeEntryViewModelTests.kt @@ -36,8 +36,7 @@ class ManualCodeEntryViewModelTests : BaseViewModelTest() { @Test fun `CodeSubmit should emit new code and NavigateBack`() = runTest { - val viewModel = - createViewModel(initialState = ManualCodeEntryState("TestCode")) + val viewModel = createViewModel(initialState = ManualCodeEntryState(" TestCode ")) viewModel.eventFlow.test { viewModel.trySendAction(ManualCodeEntryAction.CodeSubmit)