Skip to content

Commit

Permalink
[PM-12604] Fix showing the biometric prompt when not needed adding ac…
Browse files Browse the repository at this point in the history
…count (#3962)
  • Loading branch information
dseverns-livefront authored Sep 25, 2024
1 parent 4f34f6d commit 0f00994
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ class VaultUnlockViewModel @Inject constructor(

// If the Vault is already unlocked, do nothing.
if (userState.activeAccount.isVaultUnlocked) return
// If the user state has changed to add a new account, do nothing.
if (userState.hasPendingAccountAddition) return

mutableStateFlow.update {
val accountSummaries = userState.toAccountSummaries()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,35 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
assertEquals(VaultUnlockEvent.PromptForBiometrics(CIPHER), awaitItem())
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)
}
}
Expand Down

0 comments on commit 0f00994

Please sign in to comment.