mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 19:28:44 +03:00
PM-10874: Prompt for biometrics after switching accounts (#3753)
This commit is contained in:
parent
d4600c5c83
commit
9148a750a5
2 changed files with 40 additions and 8 deletions
|
@ -101,14 +101,7 @@ class VaultUnlockViewModel @Inject constructor(
|
|||
}
|
||||
.launchIn(viewModelScope)
|
||||
|
||||
val cipher = biometricsEncryptionManager.getOrCreateCipher(state.userId)
|
||||
if (state.showBiometricLogin && cipher != null) {
|
||||
sendEvent(
|
||||
VaultUnlockEvent.PromptForBiometrics(
|
||||
cipher = cipher,
|
||||
),
|
||||
)
|
||||
}
|
||||
promptForBiometricsIfAvailable()
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
|
@ -320,6 +313,20 @@ class VaultUnlockViewModel @Inject constructor(
|
|||
input = "",
|
||||
)
|
||||
}
|
||||
|
||||
// If the new account has biometrics available, automatically prompt for biometrics.
|
||||
promptForBiometricsIfAvailable()
|
||||
}
|
||||
|
||||
private fun promptForBiometricsIfAvailable() {
|
||||
val cipher = biometricsEncryptionManager.getOrCreateCipher(state.userId)
|
||||
if (state.showBiometricLogin && cipher != null) {
|
||||
sendEvent(
|
||||
VaultUnlockEvent.PromptForBiometrics(
|
||||
cipher = cipher,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -430,6 +430,31 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
|||
verify { authRepository.switchAccount(userId = updatedUserId) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `switching accounts should 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),
|
||||
)
|
||||
}
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
assertEquals(VaultUnlockEvent.PromptForBiometrics(CIPHER), awaitItem())
|
||||
expectNoEvents()
|
||||
}
|
||||
verify {
|
||||
encryptionManager.getOrCreateCipher(USER_ID)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on UnlockClick for password unlock should display error dialog on AuthenticationError`() {
|
||||
val password = "abcd1234"
|
||||
|
|
Loading…
Add table
Reference in a new issue