Add auto unlock key storage (#544)

This commit is contained in:
Brian Yencho
2024-01-08 22:18:40 -06:00
committed by GitHub
parent 26cbdc27f4
commit 3cc2f2143f
4 changed files with 77 additions and 0 deletions

View File

@@ -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"

View File

@@ -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]