mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 10:48:47 +03:00
Delete the users vault data on logout (#418)
This commit is contained in:
parent
772d6693a6
commit
f2f3a6a386
5 changed files with 32 additions and 1 deletions
|
@ -267,6 +267,9 @@ class AuthRepositoryImpl constructor(
|
|||
authDiskSource.userState = null
|
||||
}
|
||||
|
||||
// Delete all the vault data
|
||||
vaultRepository.deleteVaultData(userId)
|
||||
|
||||
// Lock the vault for the logged out user
|
||||
vaultRepository.lockVaultIfNecessary(userId)
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||
/**
|
||||
* Responsible for managing vault data inside the network layer.
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
interface VaultRepository {
|
||||
|
||||
/**
|
||||
|
@ -53,6 +54,11 @@ interface VaultRepository {
|
|||
*/
|
||||
fun clearUnlockedData()
|
||||
|
||||
/**
|
||||
* Completely remove any persisted data from the vault.
|
||||
*/
|
||||
fun deleteVaultData(userId: String)
|
||||
|
||||
/**
|
||||
* Attempt to sync the vault data.
|
||||
*/
|
||||
|
|
|
@ -143,6 +143,12 @@ class VaultRepositoryImpl(
|
|||
sendDataMutableStateFlow.update { DataState.Loading }
|
||||
}
|
||||
|
||||
override fun deleteVaultData(userId: String) {
|
||||
scope.launch {
|
||||
vaultDiskSource.deleteVaultData(userId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun sync() {
|
||||
if (!syncJob.isCompleted || willSyncAfterUnlock) return
|
||||
val userId = activeUserId ?: return
|
||||
|
|
|
@ -74,8 +74,9 @@ class AuthRepositoryTest {
|
|||
private val identityService: IdentityService = mockk()
|
||||
private val haveIBeenPwnedService: HaveIBeenPwnedService = mockk()
|
||||
private val mutableVaultStateFlow = MutableStateFlow(VAULT_STATE)
|
||||
private val vaultRepository: VaultRepository = mockk() {
|
||||
private val vaultRepository: VaultRepository = mockk {
|
||||
every { vaultStateFlow } returns mutableVaultStateFlow
|
||||
every { deleteVaultData(any()) } just runs
|
||||
every { lockVaultIfNecessary(any()) } just runs
|
||||
every { clearUnlockedData() } just runs
|
||||
}
|
||||
|
@ -999,6 +1000,7 @@ class AuthRepositoryTest {
|
|||
userId = USER_ID_1,
|
||||
organizationKeys = null,
|
||||
)
|
||||
verify { vaultRepository.deleteVaultData(userId = USER_ID_1) }
|
||||
verify { vaultRepository.clearUnlockedData() }
|
||||
verify { vaultRepository.lockVaultIfNecessary(userId = USER_ID_1) }
|
||||
}
|
||||
|
@ -1081,6 +1083,7 @@ class AuthRepositoryTest {
|
|||
userId = USER_ID_1,
|
||||
organizationKeys = null,
|
||||
)
|
||||
verify { vaultRepository.deleteVaultData(userId = USER_ID_1) }
|
||||
verify { vaultRepository.clearUnlockedData() }
|
||||
verify { vaultRepository.lockVaultIfNecessary(userId = USER_ID_1) }
|
||||
}
|
||||
|
@ -1131,6 +1134,7 @@ class AuthRepositoryTest {
|
|||
userId = USER_ID_2,
|
||||
organizationKeys = null,
|
||||
)
|
||||
verify { vaultRepository.deleteVaultData(userId = USER_ID_2) }
|
||||
verify(exactly = 0) { vaultRepository.clearUnlockedData() }
|
||||
verify { vaultRepository.lockVaultIfNecessary(userId = USER_ID_2) }
|
||||
}
|
||||
|
|
|
@ -243,6 +243,18 @@ class VaultRepositoryTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `deleteVaultData should call deleteVaultData on VaultDiskSource`() {
|
||||
val userId = "userId-1234"
|
||||
coEvery { vaultDiskSource.deleteVaultData(userId) } just runs
|
||||
|
||||
vaultRepository.deleteVaultData(userId = userId)
|
||||
|
||||
coVerify(exactly = 1) {
|
||||
vaultDiskSource.deleteVaultData(userId)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `sync with syncService Success should unlock the vault for orgs if necessary and update AuthDiskSource and DataStateFlows`() =
|
||||
|
|
Loading…
Add table
Reference in a new issue