Add auto unlock key storage (#544)

This commit is contained in:
Brian Yencho
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 6686d98e34
commit 940979599e
4 changed files with 77 additions and 0 deletions
@@ -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]