[PM-12604] Fix showing the biometric prompt when not needed adding account (#3962)

This commit is contained in:
Dave Severns 2024-09-25 10:49:48 -04:00 committed by GitHub
parent 4f34f6da21
commit 0f009943b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -310,6 +310,8 @@ class VaultUnlockViewModel @Inject constructor(
// If the Vault is already unlocked, do nothing. // If the Vault is already unlocked, do nothing.
if (userState.activeAccount.isVaultUnlocked) return if (userState.activeAccount.isVaultUnlocked) return
// If the user state has changed to add a new account, do nothing.
if (userState.hasPendingAccountAddition) return
mutableStateFlow.update { mutableStateFlow.update {
val accountSummaries = userState.toAccountSummaries() val accountSummaries = userState.toAccountSummaries()

View file

@ -460,7 +460,35 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
assertEquals(VaultUnlockEvent.PromptForBiometrics(CIPHER), awaitItem()) assertEquals(VaultUnlockEvent.PromptForBiometrics(CIPHER), awaitItem())
expectNoEvents() expectNoEvents()
} }
verify { // The initial state causes this to be called as well as the change.
verify(exactly = 2) {
encryptionManager.getOrCreateCipher(USER_ID)
}
}
@Suppress("MaxLineLength")
@Test
fun `switching accounts should not prompt for biometrics if new account has biometrics enabled`() =
runTest {
val account = DEFAULT_ACCOUNT.copy(
isVaultUnlocked = false,
isBiometricsEnabled = true,
)
val initialState = DEFAULT_STATE.copy(isBiometricsValid = true)
val viewModel = createViewModel(state = initialState)
mutableUserStateFlow.update {
it?.copy(
activeUserId = account.userId,
accounts = listOf(account),
hasPendingAccountAddition = true,
)
}
viewModel.eventFlow.test {
expectNoEvents()
}
// Only the call for the initial state should be called.
verify(exactly = 1) {
encryptionManager.getOrCreateCipher(USER_ID) encryptionManager.getOrCreateCipher(USER_ID)
} }
} }