mirror of
https://github.com/bitwarden/android.git
synced 2026-11-20 11:37:52 -06:00
BIT-1148: Add storage for blocked autofill URIs (#657)
This commit is contained in:
committed by
Álison Fernandes
parent
a87bcd28ff
commit
840f675736
+66
@@ -3,6 +3,7 @@ package com.x8bit.bitwarden.data.platform.datasource.disk
|
||||
import androidx.core.content.edit
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.data.platform.base.FakeSharedPreferences
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.di.PlatformNetworkModule
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.VaultTimeoutAction
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppLanguage
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppTheme
|
||||
@@ -15,9 +16,11 @@ import org.junit.jupiter.api.Test
|
||||
|
||||
class SettingsDiskSourceTest {
|
||||
private val fakeSharedPreferences = FakeSharedPreferences()
|
||||
private val json = PlatformNetworkModule.providesJson()
|
||||
|
||||
private val settingsDiskSource = SettingsDiskSourceImpl(
|
||||
sharedPreferences = fakeSharedPreferences,
|
||||
json = json,
|
||||
)
|
||||
|
||||
@Test
|
||||
@@ -78,6 +81,10 @@ class SettingsDiskSourceTest {
|
||||
userId = userId,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
settingsDiskSource.storeBlockedAutofillUris(
|
||||
userId = userId,
|
||||
blockedAutofillUris = listOf("www.example.com"),
|
||||
)
|
||||
|
||||
settingsDiskSource.clearData(userId = userId)
|
||||
|
||||
@@ -85,6 +92,7 @@ class SettingsDiskSourceTest {
|
||||
assertNull(settingsDiskSource.getVaultTimeoutAction(userId = userId))
|
||||
assertNull(settingsDiskSource.getPullToRefreshEnabled(userId = userId))
|
||||
assertNull(settingsDiskSource.getInlineAutofillEnabled(userId = userId))
|
||||
assertNull(settingsDiskSource.getBlockedAutofillUris(userId = userId))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -441,4 +449,62 @@ class SettingsDiskSourceTest {
|
||||
)
|
||||
assertFalse(fakeSharedPreferences.contains(inlineAutofillEnabledKey))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBlockedAutofillUris should pull from SharedPreferences`() {
|
||||
val blockedAutofillUrisBaseKey = "bwPreferencesStorage:autofillBlacklistedUris"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockBlockedAutofillUris = listOf(
|
||||
"https://www.example1.com",
|
||||
"https://www.example2.com",
|
||||
)
|
||||
fakeSharedPreferences
|
||||
.edit {
|
||||
putString(
|
||||
"${blockedAutofillUrisBaseKey}_$mockUserId",
|
||||
"""
|
||||
[
|
||||
"https://www.example1.com",
|
||||
"https://www.example2.com"
|
||||
]
|
||||
"""
|
||||
.trimIndent(),
|
||||
)
|
||||
}
|
||||
val actual = settingsDiskSource.getBlockedAutofillUris(userId = mockUserId)
|
||||
assertEquals(
|
||||
mockBlockedAutofillUris,
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `storeBlockedAutofillUris should update SharedPreferences`() {
|
||||
val blockedAutofillUrisBaseKey = "bwPreferencesStorage:autofillBlacklistedUris"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockBlockedAutofillUris = listOf(
|
||||
"https://www.example1.com",
|
||||
"https://www.example2.com",
|
||||
)
|
||||
settingsDiskSource.storeBlockedAutofillUris(
|
||||
userId = mockUserId,
|
||||
blockedAutofillUris = mockBlockedAutofillUris,
|
||||
)
|
||||
val actual = fakeSharedPreferences.getString(
|
||||
"${blockedAutofillUrisBaseKey}_$mockUserId",
|
||||
null,
|
||||
)
|
||||
assertEquals(
|
||||
json.parseToJsonElement(
|
||||
"""
|
||||
[
|
||||
"https://www.example1.com",
|
||||
"https://www.example2.com"
|
||||
]
|
||||
"""
|
||||
.trimIndent(),
|
||||
),
|
||||
json.parseToJsonElement(requireNotNull(actual)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -35,6 +35,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
||||
|
||||
private val storedPullToRefreshEnabled = mutableMapOf<String, Boolean?>()
|
||||
private val storedInlineAutofillEnabled = mutableMapOf<String, Boolean?>()
|
||||
private val storedBlockedAutofillUris = mutableMapOf<String, List<String>?>()
|
||||
|
||||
private var storedIsIconLoadingDisabled: Boolean? = null
|
||||
|
||||
@@ -69,6 +70,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
||||
storedVaultTimeoutInMinutes.remove(userId)
|
||||
storedPullToRefreshEnabled.remove(userId)
|
||||
storedInlineAutofillEnabled.remove(userId)
|
||||
storedBlockedAutofillUris.remove(userId)
|
||||
|
||||
mutableVaultTimeoutActionsFlowMap.remove(userId)
|
||||
mutableVaultTimeoutInMinutesFlowMap.remove(userId)
|
||||
@@ -126,6 +128,16 @@ class FakeSettingsDiskSource : SettingsDiskSource {
|
||||
storedInlineAutofillEnabled[userId] = isInlineAutofillEnabled
|
||||
}
|
||||
|
||||
override fun getBlockedAutofillUris(userId: String): List<String>? =
|
||||
storedBlockedAutofillUris[userId]
|
||||
|
||||
override fun storeBlockedAutofillUris(
|
||||
userId: String,
|
||||
blockedAutofillUris: List<String>?,
|
||||
) {
|
||||
storedBlockedAutofillUris[userId] = blockedAutofillUris
|
||||
}
|
||||
|
||||
//region Private helper functions
|
||||
|
||||
private fun getMutableVaultTimeoutActionsFlow(
|
||||
|
||||
+33
@@ -356,6 +356,39 @@ class SettingsRepositoryTest {
|
||||
assertTrue(fakeSettingsDiskSource.getInlineAutofillEnabled(userId = userId)!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `blockedAutofillUris should pull from and update SettingsDiskSource`() {
|
||||
val userId = "userId"
|
||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||
assertEquals(
|
||||
emptyList<String>(),
|
||||
settingsRepository.blockedAutofillUris,
|
||||
)
|
||||
|
||||
// Updates to the disk source change the repository value.
|
||||
fakeSettingsDiskSource.storeBlockedAutofillUris(
|
||||
userId = userId,
|
||||
blockedAutofillUris = listOf(
|
||||
"https://www.example1.com",
|
||||
"https://www.example2.com",
|
||||
),
|
||||
)
|
||||
assertEquals(
|
||||
listOf(
|
||||
"https://www.example1.com",
|
||||
"https://www.example2.com",
|
||||
),
|
||||
settingsRepository.blockedAutofillUris,
|
||||
)
|
||||
|
||||
// Updates to the repository change the disk source value
|
||||
settingsRepository.blockedAutofillUris = emptyList()
|
||||
assertEquals(
|
||||
emptyList<String>(),
|
||||
fakeSettingsDiskSource.getBlockedAutofillUris(userId = userId),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getPullToRefreshEnabledFlow should react to changes in SettingsDiskSource`() = runTest {
|
||||
val userId = "userId"
|
||||
|
||||
Reference in New Issue
Block a user