mirror of
https://github.com/bitwarden/android.git
synced 2026-05-31 17:56:51 -05:00
Add auto unlock key storage (#544)
This commit is contained in:
@@ -193,6 +193,45 @@ class AuthDiskSourceTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getUserAutoUnlockKey should pull from SharedPreferences`() {
|
||||
val userAutoUnlockKeyBaseKey = "bwSecureStorage:userKeyAutoUnlock"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockUserAutoUnlockKey = "mockUserAutoUnlockKey"
|
||||
fakeEncryptedSharedPreferences
|
||||
.edit()
|
||||
.putString(
|
||||
"${userAutoUnlockKeyBaseKey}_$mockUserId",
|
||||
mockUserAutoUnlockKey,
|
||||
)
|
||||
.apply()
|
||||
val actual = authDiskSource.getUserAutoUnlockKey(userId = mockUserId)
|
||||
assertEquals(
|
||||
mockUserAutoUnlockKey,
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `storeUserAutoUnlockKey should update SharedPreferences`() {
|
||||
val userAutoUnlockKeyBaseKey = "bwSecureStorage:userKeyAutoUnlock"
|
||||
val mockUserId = "mockUserId"
|
||||
val mockUserAutoUnlockKey = "mockUserAutoUnlockKey"
|
||||
authDiskSource.storeUserAutoUnlockKey(
|
||||
userId = mockUserId,
|
||||
userAutoUnlockKey = mockUserAutoUnlockKey,
|
||||
)
|
||||
val actual = fakeEncryptedSharedPreferences
|
||||
.getString(
|
||||
"${userAutoUnlockKeyBaseKey}_$mockUserId",
|
||||
null,
|
||||
)
|
||||
assertEquals(
|
||||
mockUserAutoUnlockKey,
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getOrganizationKeys should pull from SharedPreferences`() {
|
||||
val organizationKeysBaseKey = "bwPreferencesStorage:encOrgKeys"
|
||||
|
||||
@@ -21,6 +21,7 @@ class FakeAuthDiskSource : AuthDiskSource {
|
||||
|
||||
private val storedUserKeys = mutableMapOf<String, String?>()
|
||||
private val storedPrivateKeys = mutableMapOf<String, String?>()
|
||||
private val storedUserAutoUnlockKeys = mutableMapOf<String, String?>()
|
||||
private val storedOrganizations =
|
||||
mutableMapOf<String, List<SyncResponseJson.Profile.Organization>?>()
|
||||
private val storedOrganizationKeys = mutableMapOf<String, Map<String, String>?>()
|
||||
@@ -46,6 +47,13 @@ class FakeAuthDiskSource : AuthDiskSource {
|
||||
storedPrivateKeys[userId] = privateKey
|
||||
}
|
||||
|
||||
override fun getUserAutoUnlockKey(userId: String): String? =
|
||||
storedUserAutoUnlockKeys[userId]
|
||||
|
||||
override fun storeUserAutoUnlockKey(userId: String, userAutoUnlockKey: String?) {
|
||||
storedUserAutoUnlockKeys[userId] = userAutoUnlockKey
|
||||
}
|
||||
|
||||
override fun getOrganizationKeys(
|
||||
userId: String,
|
||||
): Map<String, String>? = storedOrganizationKeys[userId]
|
||||
|
||||
Reference in New Issue
Block a user