From 65205089dbfccf688a4e2528ad8f47cbb8af6aca Mon Sep 17 00:00:00 2001 From: David Perez Date: Fri, 24 May 2024 16:44:44 -0500 Subject: [PATCH] Clear crypto on logout (#1391) --- .../bitwarden/data/auth/manager/UserLogoutManagerImpl.kt | 3 +++ .../bitwarden/data/auth/manager/di/AuthManagerModule.kt | 2 ++ .../bitwarden/data/auth/manager/UserLogoutManagerTest.kt | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerImpl.kt index 8807c9339..3d414e232 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerImpl.kt @@ -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) diff --git a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt index 1b1f7e94e..50e6b4804 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/auth/manager/di/AuthManagerModule.kt @@ -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, ) } diff --git a/app/src/test/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerTest.kt index a1480e542..2a641aaf3 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerTest.kt @@ -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) }