BITAU-175 Remove lastSyncTime property from SharedAccountData (#4077)

This commit is contained in:
Andrew Haisting 2024-10-14 11:56:18 -05:00 committed by GitHub
parent 9b5c88e990
commit b465cc5078
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 0 additions and 50 deletions

View file

@ -3,7 +3,6 @@ package com.x8bit.bitwarden.data.platform.repository
import com.bitwarden.authenticatorbridge.model.SharedAccountData
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSource
import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
@ -22,7 +21,6 @@ class AuthenticatorBridgeRepositoryImpl(
private val vaultRepository: VaultRepository,
private val vaultDiskSource: VaultDiskSource,
private val vaultSdkSource: VaultSdkSource,
private val settingsDiskSource: SettingsDiskSource,
) : AuthenticatorBridgeRepository {
override val authenticatorSyncSymmetricKey: ByteArray?
@ -111,9 +109,6 @@ class AuthenticatorBridgeRepositoryImpl(
?.totp
}
val lastSyncTime =
settingsDiskSource.getLastSyncTime(userId) ?: return@mapNotNull null
// Lock the user's vault if we unlocked it for this operation:
if (!isVaultAlreadyUnlocked) {
vaultRepository.lockVault(userId)
@ -124,7 +119,6 @@ class AuthenticatorBridgeRepositoryImpl(
name = account.name,
email = account.email,
environmentLabel = account.environment.label,
lastSyncTime = lastSyncTime,
totpUris = totpUris,
)
}

View file

@ -48,14 +48,12 @@ object PlatformRepositoryModule {
vaultRepository: VaultRepository,
vaultDiskSource: VaultDiskSource,
vaultSdkSource: VaultSdkSource,
settingsDiskSource: SettingsDiskSource,
): AuthenticatorBridgeRepository = AuthenticatorBridgeRepositoryImpl(
authRepository = authRepository,
authDiskSource = authDiskSource,
vaultRepository = vaultRepository,
vaultDiskSource = vaultDiskSource,
vaultSdkSource = vaultSdkSource,
settingsDiskSource = settingsDiskSource,
)
@Provides

View file

@ -8,7 +8,6 @@ import com.bitwarden.vault.CipherView
import com.x8bit.bitwarden.data.auth.datasource.disk.util.FakeAuthDiskSource
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.platform.datasource.disk.util.FakeSettingsDiskSource
import com.x8bit.bitwarden.data.platform.util.asSuccess
import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSource
import com.x8bit.bitwarden.data.vault.datasource.network.model.SyncResponseJson
@ -34,7 +33,6 @@ 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.Instant
class AuthenticatorBridgeRepositoryTest {
@ -43,7 +41,6 @@ class AuthenticatorBridgeRepositoryTest {
private val vaultDiskSource = mockk<VaultDiskSource>()
private val vaultRepository = mockk<VaultRepository>()
private val fakeAuthDiskSource = FakeAuthDiskSource()
private val fakeSettingsDiskSource = FakeSettingsDiskSource()
private val authenticatorBridgeRepository = AuthenticatorBridgeRepositoryImpl(
authRepository = authRepository,
@ -51,7 +48,6 @@ class AuthenticatorBridgeRepositoryTest {
vaultRepository = vaultRepository,
vaultDiskSource = vaultDiskSource,
vaultSdkSource = vaultSdkSource,
settingsDiskSource = fakeSettingsDiskSource,
)
@BeforeEach
@ -97,10 +93,6 @@ class AuthenticatorBridgeRepositoryTest {
)
} returns VaultUnlockResult.Success
// Setup settingDiskSource to have lastSyncTime set:
fakeSettingsDiskSource.storeLastSyncTime(USER_1_ID, LAST_SYNC_TIME)
fakeSettingsDiskSource.storeLastSyncTime(USER_2_ID, LAST_SYNC_TIME)
// Add some ciphers to vaultDiskSource for each user,
// and setup mock decryption for them:
every { vaultDiskSource.getCiphers(USER_1_ID) } returns flowOf(USER_1_CIPHERS)
@ -229,29 +221,6 @@ class AuthenticatorBridgeRepositoryTest {
coVerify { vaultSdkSource.decryptCipher(USER_2_ID, USER_2_ENCRYPTED_SDK_TOTP_CIPHER) }
}
@Test
fun `syncAccounts when getLastSyncTime is null should omit account from list`() = runTest {
fakeSettingsDiskSource.storeLastSyncTime(USER_1_ID, null)
val sharedAccounts = authenticatorBridgeRepository.getSharedAccounts()
assertEquals(SharedAccountData(listOf(USER_2_SHARED_ACCOUNT)), sharedAccounts)
verify { vaultRepository.vaultUnlockDataStateFlow }
verify { vaultDiskSource.getCiphers(USER_1_ID) }
verify { vaultRepository.isVaultUnlocked(USER_1_ID) }
coVerify { vaultSdkSource.decryptCipher(USER_1_ID, USER_1_ENCRYPTED_SDK_TOTP_CIPHER) }
verify { authRepository.userStateFlow }
verify { vaultRepository.isVaultUnlocked(USER_2_ID) }
coVerify {
vaultRepository.unlockVaultWithDecryptedUserKey(
userId = USER_2_ID,
decryptedUserKey = USER_2_UNLOCK_KEY,
)
}
verify { vaultRepository.vaultUnlockDataStateFlow }
verify { vaultRepository.lockVault(USER_2_ID) }
verify { vaultDiskSource.getCiphers(USER_2_ID) }
coVerify { vaultSdkSource.decryptCipher(USER_2_ID, USER_2_ENCRYPTED_SDK_TOTP_CIPHER) }
}
@Test
@Suppress("MaxLineLength")
fun `syncAccounts when for user 1 vault is locked and unlock fails should reset authenticator sync unlock key and omit user from the list`() =
@ -432,15 +401,12 @@ private val USER_2_DECRYPTED_TOTP_CIPHER = mockk<CipherView> {
private val USER_1_EXPECTED_TOTP_LIST = listOf("totp1")
private val USER_2_EXPECTED_TOTP_LIST = listOf("totp2")
private val LAST_SYNC_TIME = Instant.now()
private val USER_1_SHARED_ACCOUNT = SharedAccountData.Account(
userId = ACCOUNT_1.userId,
name = ACCOUNT_1.name,
email = ACCOUNT_1.email,
environmentLabel = ACCOUNT_1.environment.label,
totpUris = USER_1_EXPECTED_TOTP_LIST,
lastSyncTime = LAST_SYNC_TIME,
)
private val USER_2_SHARED_ACCOUNT = SharedAccountData.Account(
@ -449,7 +415,6 @@ private val USER_2_SHARED_ACCOUNT = SharedAccountData.Account(
email = ACCOUNT_2.email,
environmentLabel = ACCOUNT_2.environment.label,
totpUris = USER_2_EXPECTED_TOTP_LIST,
lastSyncTime = LAST_SYNC_TIME,
)
private val USER_1_CIPHERS = listOf(

View file

@ -27,6 +27,5 @@ data class SharedAccountData(
val email: String,
val environmentLabel: String,
val totpUris: List<String>,
val lastSyncTime: Instant,
)
}

View file

@ -44,10 +44,6 @@ internal data class SharedAccountDataJson(
@SerialName("totpUris")
val totpUris: List<String>,
@SerialName("lastSyncTime")
@Contextual
val lastSyncTime: Instant,
)
}

View file

@ -172,7 +172,6 @@ private fun SharedAccountData.toJsonModel() = SharedAccountDataJson(
environmentLabel = account.environmentLabel,
email = account.email,
totpUris = account.totpUris,
lastSyncTime = account.lastSyncTime
)
}
)
@ -188,7 +187,6 @@ private fun SharedAccountDataJson.toDomainModel() = SharedAccountData(
environmentLabel = account.environmentLabel,
email = account.email,
totpUris = account.totpUris,
lastSyncTime = account.lastSyncTime
)
}
)