BIT-1659-filter-out-reprompt-ciphers (#918)

This commit is contained in:
Lucas Kivi 2024-01-31 18:38:28 -06:00 committed by Álison Fernandes
parent 1448322964
commit 3b1758262b
2 changed files with 35 additions and 4 deletions

View file

@ -1,5 +1,6 @@
package com.x8bit.bitwarden.data.autofill.provider
import com.bitwarden.core.CipherRepromptType
import com.bitwarden.core.CipherType
import com.bitwarden.core.CipherView
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
@ -41,7 +42,14 @@ class AutofillCipherProviderImpl(
.mapNotNull { cipherView ->
cipherView
// We only care about non-deleted card ciphers.
.takeIf { cipherView.type == CipherType.CARD && cipherView.deletedDate == null }
.takeIf {
// Must be card type.
cipherView.type == CipherType.CARD &&
// Must not be deleted.
cipherView.deletedDate == null &&
// Must not require a reprompt.
it.reprompt == CipherRepromptType.NONE
}
?.let { nonNullCipherView ->
AutofillCipher.Card(
cipherId = cipherView.id,
@ -63,7 +71,14 @@ class AutofillCipherProviderImpl(
val cipherViews = getUnlockedCiphersOrNull() ?: return emptyList()
// We only care about non-deleted login ciphers.
val loginCiphers = cipherViews
.filter { it.type == CipherType.LOGIN && it.deletedDate == null }
.filter {
// Must be login type
it.type == CipherType.LOGIN &&
// Must not be deleted.
it.deletedDate == null &&
// Must not require a reprompt.
it.reprompt == CipherRepromptType.NONE
}
return cipherMatchingManager
// Filter for ciphers that match the uri in some way.

View file

@ -1,6 +1,7 @@
package com.x8bit.bitwarden.data.autofill.processor
import com.bitwarden.core.CardView
import com.bitwarden.core.CipherRepromptType
import com.bitwarden.core.CipherType
import com.bitwarden.core.CipherView
import com.bitwarden.core.LoginView
@ -43,6 +44,7 @@ class AutofillCipherProviderTest {
every { deletedDate } returns null
every { id } returns CIPHER_ID
every { name } returns CARD_NAME
every { reprompt } returns CipherRepromptType.NONE
every { type } returns CipherType.CARD
}
private val loginViewWithoutTotp: LoginView = mockk {
@ -55,6 +57,7 @@ class AutofillCipherProviderTest {
every { id } returns CIPHER_ID
every { login } returns loginViewWithoutTotp
every { name } returns LOGIN_NAME
every { reprompt } returns CipherRepromptType.NONE
every { type } returns CipherType.LOGIN
}
private val loginViewWithTotp: LoginView = mockk {
@ -67,6 +70,7 @@ class AutofillCipherProviderTest {
every { id } returns CIPHER_ID
every { login } returns loginViewWithTotp
every { name } returns LOGIN_NAME
every { reprompt } returns CipherRepromptType.NONE
every { type } returns CipherType.LOGIN
}
private val authRepository: AuthRepository = mockk {
@ -153,15 +157,21 @@ class AutofillCipherProviderTest {
@Suppress("MaxLineLength")
@Test
fun `getCardAutofillCiphers when unlocked should return non-null and non-deleted card ciphers`() =
fun `getCardAutofillCiphers when unlocked should return non-null, non-deleted, and non-reprompt card ciphers`() =
runTest {
val deletedCardCipherView: CipherView = mockk {
every { deletedDate } returns mockk()
every { type } returns CipherType.CARD
}
val repromptCardCipherView: CipherView = mockk {
every { deletedDate } returns null
every { reprompt } returns CipherRepromptType.PASSWORD
every { type } returns CipherType.CARD
}
val cipherViews = listOf(
cardCipherView,
deletedCardCipherView,
repromptCardCipherView,
loginCipherViewWithTotp,
loginCipherViewWithoutTotp,
)
@ -197,17 +207,23 @@ class AutofillCipherProviderTest {
@Suppress("MaxLineLength")
@Test
fun `getLoginAutofillCiphers when unlocked should return matched, non-deleted, login ciphers`() =
fun `getLoginAutofillCiphers when unlocked should return matched, non-deleted, non-reprompt, login ciphers`() =
runTest {
val deletedLoginCipherView: CipherView = mockk {
every { deletedDate } returns mockk()
every { type } returns CipherType.LOGIN
}
val repromptLoginCipherView: CipherView = mockk {
every { deletedDate } returns null
every { reprompt } returns CipherRepromptType.PASSWORD
every { type } returns CipherType.LOGIN
}
val cipherViews = listOf(
cardCipherView,
loginCipherViewWithTotp,
loginCipherViewWithoutTotp,
deletedLoginCipherView,
repromptLoginCipherView,
)
val filteredCipherViews = listOf(
loginCipherViewWithTotp,