Clear crypto on logout (#1391)

This commit is contained in:
David Perez 2024-05-24 16:44:44 -05:00 committed by Álison Fernandes
parent d3a1e0b6ed
commit 65205089db
3 changed files with 11 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
import com.x8bit.bitwarden.data.tools.generator.datasource.disk.GeneratorDiskSource
import com.x8bit.bitwarden.data.tools.generator.datasource.disk.PasswordHistoryDiskSource
import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSource
import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
@ -27,6 +28,7 @@ class UserLogoutManagerImpl(
private val settingsDiskSource: SettingsDiskSource,
private val vaultDiskSource: VaultDiskSource,
private val dispatcherManager: DispatcherManager,
private val vaultSdkSource: VaultSdkSource,
) : UserLogoutManager {
private val scope = CoroutineScope(dispatcherManager.unconfined)
private val mainScope = CoroutineScope(dispatcherManager.main)
@ -96,6 +98,7 @@ class UserLogoutManagerImpl(
}
private fun clearData(userId: String) {
vaultSdkSource.clearCrypto(userId = userId)
authDiskSource.clearData(userId = userId)
generatorDiskSource.clearData(userId = userId)
pushDiskSource.clearData(userId = userId)

View file

@ -94,6 +94,7 @@ object AuthManagerModule {
pushDiskSource: PushDiskSource,
settingsDiskSource: SettingsDiskSource,
vaultDiskSource: VaultDiskSource,
vaultSdkSource: VaultSdkSource,
dispatcherManager: DispatcherManager,
): UserLogoutManager =
UserLogoutManagerImpl(
@ -104,6 +105,7 @@ object AuthManagerModule {
pushDiskSource = pushDiskSource,
settingsDiskSource = settingsDiskSource,
vaultDiskSource = vaultDiskSource,
vaultSdkSource = vaultSdkSource,
dispatcherManager = dispatcherManager,
)
}

View file

@ -15,6 +15,7 @@ import com.x8bit.bitwarden.data.platform.repository.model.VaultTimeoutAction
import com.x8bit.bitwarden.data.tools.generator.datasource.disk.GeneratorDiskSource
import com.x8bit.bitwarden.data.tools.generator.datasource.disk.PasswordHistoryDiskSource
import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSource
import com.x8bit.bitwarden.data.vault.datasource.sdk.VaultSdkSource
import com.x8bit.bitwarden.ui.platform.base.MainDispatcherExtension
import io.mockk.coEvery
import io.mockk.coVerify
@ -53,6 +54,9 @@ class UserLogoutManagerTest {
private val vaultDiskSource: VaultDiskSource = mockk {
coEvery { deleteVaultData(any()) } just runs
}
private val vaultSdkSource: VaultSdkSource = mockk {
every { clearCrypto(userId = any()) } just runs
}
private val context: Context = mockk()
private val userLogoutManager: UserLogoutManager =
@ -64,6 +68,7 @@ class UserLogoutManagerTest {
pushDiskSource = pushDiskSource,
settingsDiskSource = settingsDiskSource,
vaultDiskSource = vaultDiskSource,
vaultSdkSource = vaultSdkSource,
dispatcherManager = FakeDispatcherManager(),
)
@ -153,6 +158,7 @@ class UserLogoutManagerTest {
}
private fun assertDataCleared(userId: String) {
verify { vaultSdkSource.clearCrypto(userId = userId) }
verify { authDiskSource.clearData(userId = userId) }
verify { generatorDiskSource.clearData(userId = userId) }
verify { pushDiskSource.clearData(userId = userId) }