Remove the in-memory deviceKey (#1270)

This commit is contained in:
David Perez
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 20f7811b6a
commit 921240d173
5 changed files with 11 additions and 54 deletions
@@ -38,7 +38,7 @@ class FakeAuthDiskSource : AuthDiskSource {
mutableMapOf<String, List<SyncResponseJson.Profile.Organization>?>()
private val storedOrganizationKeys = mutableMapOf<String, Map<String, String>?>()
private val storedAccountTokens = mutableMapOf<String, AccountTokensJson?>()
private val storedDeviceKey = mutableMapOf<String, Pair<String?, Boolean>>()
private val storedDeviceKey = mutableMapOf<String, String?>()
private val storedPendingAuthRequests = mutableMapOf<String, PendingAuthRequestJson?>()
private val storedBiometricKeys = mutableMapOf<String, String?>()
private val storedMasterPasswordHashes = mutableMapOf<String, String?>()
@@ -166,14 +166,10 @@ class FakeAuthDiskSource : AuthDiskSource {
getMutableOrganizationsFlow(userId = userId).tryEmit(organizations)
}
override fun getDeviceKey(userId: String): String? = storedDeviceKey[userId]?.first
override fun getDeviceKey(userId: String): String? = storedDeviceKey[userId]
override fun storeDeviceKey(
userId: String,
deviceKey: String?,
inMemoryOnly: Boolean,
) {
storedDeviceKey[userId] = deviceKey to inMemoryOnly
override fun storeDeviceKey(userId: String, deviceKey: String?) {
storedDeviceKey[userId] = deviceKey
}
override fun getPendingAuthRequest(userId: String): PendingAuthRequestJson? =
@@ -301,8 +297,8 @@ class FakeAuthDiskSource : AuthDiskSource {
/**
* Assert that the [deviceKey] was stored successfully using the [userId].
*/
fun assertDeviceKey(userId: String, deviceKey: String?, inMemoryOnly: Boolean = false) {
assertEquals(deviceKey to inMemoryOnly, storedDeviceKey[userId])
fun assertDeviceKey(userId: String, deviceKey: String?) {
assertEquals(deviceKey, storedDeviceKey[userId])
}
/**
@@ -53,30 +53,13 @@ class TrustedDeviceManagerTests {
@Test
fun `trustThisDeviceIfNecessary when shouldTrustDevice false should return success with false`() =
runTest {
val deviceKey = "deviceKey"
val trustedDeviceResponse = TrustDeviceResponse(
deviceKey = deviceKey,
protectedUserKey = "protectedUserKey",
protectedDevicePrivateKey = "protectedDevicePrivateKey",
protectedDevicePublicKey = "protectedDevicePublicKey",
)
fakeAuthDiskSource.shouldTrustDevice = false
coEvery {
vaultSdkSource.getTrustDevice(userId = USER_ID)
} returns trustedDeviceResponse.asSuccess()
val result = manager.trustThisDeviceIfNecessary(userId = USER_ID)
assertEquals(false.asSuccess(), result)
fakeAuthDiskSource.assertDeviceKey(
userId = USER_ID,
deviceKey = deviceKey,
inMemoryOnly = true,
)
coVerify(exactly = 1) {
vaultSdkSource.getTrustDevice(userId = USER_ID)
}
coVerify(exactly = 0) {
vaultSdkSource.getTrustDevice(userId = USER_ID)
devicesService.trustDevice(
appId = any(),
encryptedUserKey = any(),