PM-10874: Prompt for biometrics after switching accounts (#3753)

This commit is contained in:
Shannon Draeker 2024-08-16 09:45:32 -04:00 committed by GitHub
parent d4600c5c83
commit 9148a750a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 8 deletions

View file

@ -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,
),
)
}
}
}

View file

@ -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"