mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
Add clearData calls DiskSources (#603)
This commit is contained in:
committed by
Álison Fernandes
parent
67d7b7a9f5
commit
f1b9ded3e3
@@ -118,6 +118,39 @@ class AuthDiskSourceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clearData should clear all necessary data for the given user`() {
|
||||
val userId = "userId"
|
||||
|
||||
authDiskSource.storeLastActiveTimeMillis(
|
||||
userId = userId,
|
||||
lastActiveTimeMillis = 123456789L,
|
||||
)
|
||||
authDiskSource.storeUserKey(userId = userId, userKey = "userKey")
|
||||
authDiskSource.storeUserAutoUnlockKey(
|
||||
userId = userId,
|
||||
userAutoUnlockKey = "userAutoUnlockKey",
|
||||
)
|
||||
authDiskSource.storePrivateKey(userId = userId, privateKey = "privateKey")
|
||||
authDiskSource.storeOrganizationKeys(
|
||||
userId = userId,
|
||||
organizationKeys = mapOf("organizationId" to "key"),
|
||||
)
|
||||
authDiskSource.storeOrganizations(
|
||||
userId = userId,
|
||||
organizations = listOf(createMockOrganization(1)),
|
||||
)
|
||||
|
||||
authDiskSource.clearData(userId = userId)
|
||||
|
||||
assertNull(authDiskSource.getLastActiveTimeMillis(userId = userId))
|
||||
assertNull(authDiskSource.getUserKey(userId = userId))
|
||||
assertNull(authDiskSource.getUserAutoUnlockKey(userId = userId))
|
||||
assertNull(authDiskSource.getPrivateKey(userId = userId))
|
||||
assertNull(authDiskSource.getOrganizationKeys(userId = userId))
|
||||
assertNull(authDiskSource.getOrganizations(userId = userId))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getLastActiveTimeMillis should pull from SharedPreferences`() {
|
||||
val lastActiveTimeBaseKey = "bwPreferencesStorage:lastActiveTime"
|
||||
|
||||
+11
@@ -36,6 +36,17 @@ class FakeAuthDiskSource : AuthDiskSource {
|
||||
override val userStateFlow: Flow<UserStateJson?>
|
||||
get() = mutableUserStateFlow.onSubscription { emit(userState) }
|
||||
|
||||
override fun clearData(userId: String) {
|
||||
storedLastActiveTimeMillis.remove(userId)
|
||||
storedUserKeys.remove(userId)
|
||||
storedPrivateKeys.remove(userId)
|
||||
storedUserAutoUnlockKeys.remove(userId)
|
||||
storedOrganizations.remove(userId)
|
||||
|
||||
storedOrganizationKeys.remove(userId)
|
||||
mutableOrganizationsFlowMap.remove(userId)
|
||||
}
|
||||
|
||||
override fun getLastActiveTimeMillis(userId: String): Long? =
|
||||
storedLastActiveTimeMillis[userId]
|
||||
|
||||
|
||||
+18
@@ -58,6 +58,24 @@ class SettingsDiskSourceTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `clearData should clear all necessary data for the given user`() {
|
||||
val userId = "userId"
|
||||
settingsDiskSource.storeVaultTimeoutInMinutes(
|
||||
userId = userId,
|
||||
vaultTimeoutInMinutes = 30,
|
||||
)
|
||||
settingsDiskSource.storeVaultTimeoutAction(
|
||||
userId = userId,
|
||||
vaultTimeoutAction = VaultTimeoutAction.LOCK,
|
||||
)
|
||||
|
||||
settingsDiskSource.clearData(userId = userId)
|
||||
|
||||
assertNull(settingsDiskSource.getVaultTimeoutInMinutes(userId = userId))
|
||||
assertNull(settingsDiskSource.getVaultTimeoutAction(userId = userId))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getVaultTimeoutInMinutes when values are present should pull from SharedPreferences`() {
|
||||
val vaultTimeoutBaseKey = "bwPreferencesStorage:vaultTimeout"
|
||||
|
||||
+8
@@ -24,6 +24,14 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
||||
|
||||
override var appLanguage: AppLanguage? = null
|
||||
|
||||
override fun clearData(userId: String) {
|
||||
storedVaultTimeoutActions.remove(userId)
|
||||
storedVaultTimeoutInMinutes.remove(userId)
|
||||
|
||||
mutableVaultTimeoutActionsFlowMap.remove(userId)
|
||||
mutableVaultTimeoutInMinutesFlowMap.remove(userId)
|
||||
}
|
||||
|
||||
override fun getVaultTimeoutInMinutes(userId: String): Int? =
|
||||
storedVaultTimeoutInMinutes[userId]
|
||||
|
||||
|
||||
+53
@@ -25,6 +25,59 @@ class GeneratorDiskSourceTest {
|
||||
json = json,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `clearData should clear all necessary data for the given user`() {
|
||||
val userId = "userId"
|
||||
|
||||
val passcodeOptions = PasscodeGenerationOptions(
|
||||
length = 14,
|
||||
allowAmbiguousChar = false,
|
||||
hasNumbers = true,
|
||||
minNumber = 0,
|
||||
hasUppercase = true,
|
||||
minUppercase = null,
|
||||
hasLowercase = false,
|
||||
minLowercase = null,
|
||||
allowSpecial = false,
|
||||
minSpecial = 1,
|
||||
allowCapitalize = false,
|
||||
allowIncludeNumber = false,
|
||||
wordSeparator = "-",
|
||||
numWords = 3,
|
||||
)
|
||||
val userNameOptions = UsernameGenerationOptions(
|
||||
type = UsernameGenerationOptions.UsernameType.RANDOM_WORD,
|
||||
serviceType = UsernameGenerationOptions.ForwardedEmailServiceType.NONE,
|
||||
capitalizeRandomWordUsername = true,
|
||||
includeNumberRandomWordUsername = false,
|
||||
plusAddressedEmail = "example+plus@gmail.com",
|
||||
catchAllEmailDomain = "example.com",
|
||||
firefoxRelayApiAccessToken = "access_token_firefox_relay",
|
||||
simpleLoginApiKey = "api_key_simple_login",
|
||||
duckDuckGoApiKey = "api_key_duck_duck_go",
|
||||
fastMailApiKey = "api_key_fast_mail",
|
||||
anonAddyApiAccessToken = "access_token_anon_addy",
|
||||
anonAddyDomainName = "anonaddy.com",
|
||||
forwardEmailApiAccessToken = "access_token_forward_email",
|
||||
forwardEmailDomainName = "forwardemail.net",
|
||||
emailWebsite = "email.example.com",
|
||||
)
|
||||
|
||||
generatorDiskSource.storePasscodeGenerationOptions(
|
||||
userId = userId,
|
||||
options = passcodeOptions,
|
||||
)
|
||||
generatorDiskSource.storeUsernameGenerationOptions(
|
||||
userId = userId,
|
||||
options = userNameOptions,
|
||||
)
|
||||
|
||||
generatorDiskSource.clearData(userId = userId)
|
||||
|
||||
assertNull(generatorDiskSource.getPasscodeGenerationOptions(userId = userId))
|
||||
assertNull(generatorDiskSource.getUsernameGenerationOptions(userId = userId))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getPasscodeGenerationOptions should return correct options when available`() {
|
||||
val userId = "user123"
|
||||
|
||||
Reference in New Issue
Block a user