Skip to content

Commit

Permalink
BITAU-176 Filter out deleted ciphers from syncAccounts call
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaisting-livefront committed Oct 14, 2024
1 parent 8eab74d commit 74dcd26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class AuthenticatorBridgeRepositoryImpl(
val totpUris = vaultDiskSource
.getCiphers(userId)
.first()
// Filter out any ciphers without a totp item:
.filter { it.login?.totp != null }
// Filter out any ciphers without a totp item and also deleted ciphers:
.filter { it.login?.totp != null && it.deletedDate == null }
.mapNotNull {
// Decrypt each cipher and take just totp codes:
vaultSdkSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.ZonedDateTime

class AuthenticatorBridgeRepositoryTest {

Expand Down Expand Up @@ -183,7 +184,7 @@ class AuthenticatorBridgeRepositoryTest {

@Test
@Suppress("MaxLineLength")
fun `syncAccounts when vault is locked for both users should unlock and re-lock vault for both users`() =
fun `syncAccounts when vault is locked for both users should unlock and re-lock vault for both users and filter out deleted ciphers`() =
runTest {
every { vaultRepository.isVaultUnlocked(USER_1_ID) } returns false
coEvery {
Expand Down Expand Up @@ -382,10 +383,17 @@ private val USER_STATE = UserState(

private val USER_1_TOTP_CIPHER = mockk<SyncResponseJson.Cipher> {
every { login?.totp } returns "encryptedTotp1"
every { deletedDate } returns null
}

private val USER_1_DELETED_TOTP_CIPHER = mockk<SyncResponseJson.Cipher> {
every { login?.totp } returns "encryptedTotp1Deleted"
every { deletedDate } returns ZonedDateTime.now()
}

private val USER_2_TOTP_CIPHER = mockk<SyncResponseJson.Cipher> {
every { login?.totp } returns "encryptedTotp2"
every { deletedDate } returns null
}

private val USER_1_ENCRYPTED_SDK_TOTP_CIPHER = mockk<Cipher>()
Expand Down Expand Up @@ -419,6 +427,7 @@ private val USER_2_SHARED_ACCOUNT = SharedAccountData.Account(

private val USER_1_CIPHERS = listOf(
USER_1_TOTP_CIPHER,
USER_1_DELETED_TOTP_CIPHER,
)

private val USER_2_CIPHERS = listOf(
Expand Down

0 comments on commit 74dcd26

Please sign in to comment.