Fixing missing session info when there is no crypto info

This commit is contained in:
Maxime NATUREL 2022-12-27 17:24:32 +01:00 committed by Maxime NATUREL
parent 1af712910f
commit 6fdb1216ba
2 changed files with 46 additions and 5 deletions

View File

@ -49,10 +49,10 @@ class GetDeviceFullInfoUseCase @Inject constructor(
) { currentSessionCrossSigningInfo, deviceInfo, cryptoDeviceInfo -> ) { currentSessionCrossSigningInfo, deviceInfo, cryptoDeviceInfo ->
val info = deviceInfo.getOrNull() val info = deviceInfo.getOrNull()
val cryptoInfo = cryptoDeviceInfo.getOrNull() val cryptoInfo = cryptoDeviceInfo.getOrNull()
val fullInfo = if (info != null && cryptoInfo != null) { val fullInfo = if (info != null) {
val roomEncryptionTrustLevel = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoInfo) val roomEncryptionTrustLevel = getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoInfo)
val isInactive = checkIfSessionIsInactiveUseCase.execute(info.lastSeenTs) val isInactive = checkIfSessionIsInactiveUseCase.execute(info.lastSeenTs)
val isCurrentDevice = currentSessionCrossSigningInfo.deviceId == cryptoInfo.deviceId val isCurrentDevice = currentSessionCrossSigningInfo.deviceId == info.deviceId
val deviceUserAgent = parseDeviceUserAgentUseCase.execute(info.getBestLastSeenUserAgent()) val deviceUserAgent = parseDeviceUserAgentUseCase.execute(info.getBestLastSeenUserAgent())
val matrixClientInfo = info.deviceId val matrixClientInfo = info.deviceId
?.takeIf { it.isNotEmpty() } ?.takeIf { it.isNotEmpty() }

View File

@ -117,6 +117,45 @@ class GetDeviceFullInfoUseCaseTest {
} }
} }
@Test
fun `given current session and no crypto info for device when getting device info then the result is correct`() = runTest {
// Given
val currentSessionCrossSigningInfo = givenCurrentSessionCrossSigningInfo()
val deviceInfo = givenADeviceInfo()
val cryptoDeviceInfo = null
val trustLevel = givenTrustLevel(currentSessionCrossSigningInfo, cryptoDeviceInfo)
val isInactive = false
val isCurrentDevice = true
every { checkIfSessionIsInactiveUseCase.execute(any()) } returns isInactive
every { parseDeviceUserAgentUseCase.execute(any()) } returns DeviceExtendedInfo(DeviceType.MOBILE)
val matrixClientInfo = givenAMatrixClientInfo()
fakeActiveSessionHolder.fakeSession.fakeCryptoService.cryptoDeviceInfoWithIdLiveData = MutableLiveData(Optional(null))
fakeActiveSessionHolder.fakeSession.fakeCryptoService.cryptoDeviceInfoWithIdLiveData.givenAsFlow()
// When
val deviceFullInfo = getDeviceFullInfoUseCase.execute(A_DEVICE_ID).firstOrNull()
// Then
deviceFullInfo shouldBeEqualTo DeviceFullInfo(
deviceInfo = deviceInfo,
cryptoDeviceInfo = cryptoDeviceInfo,
roomEncryptionTrustLevel = trustLevel,
isInactive = isInactive,
isCurrentDevice = isCurrentDevice,
deviceExtendedInfo = DeviceExtendedInfo(DeviceType.MOBILE),
matrixClientInfo = matrixClientInfo,
)
verify {
fakeActiveSessionHolder.instance.getSafeActiveSession()
getCurrentSessionCrossSigningInfoUseCase.execute()
getEncryptionTrustLevelForDeviceUseCase.execute(currentSessionCrossSigningInfo, cryptoDeviceInfo)
fakeActiveSessionHolder.fakeSession.fakeCryptoService.getMyDevicesInfoLive(A_DEVICE_ID).asFlow()
fakeActiveSessionHolder.fakeSession.fakeCryptoService.getLiveCryptoDeviceInfoWithId(A_DEVICE_ID).asFlow()
checkIfSessionIsInactiveUseCase.execute(A_TIMESTAMP)
getMatrixClientInfoUseCase.execute(fakeActiveSessionHolder.fakeSession, A_DEVICE_ID)
}
}
@Test @Test
fun `given current session and no info for device when getting device info then the result is empty`() = runTest { fun `given current session and no info for device when getting device info then the result is empty`() = runTest {
// Given // Given
@ -131,9 +170,11 @@ class GetDeviceFullInfoUseCaseTest {
// Then // Then
deviceFullInfo.shouldBeNull() deviceFullInfo.shouldBeNull()
verify { fakeActiveSessionHolder.instance.getSafeActiveSession() } verify {
verify { fakeActiveSessionHolder.fakeSession.fakeCryptoService.getMyDevicesInfoLive(A_DEVICE_ID).asFlow() } fakeActiveSessionHolder.instance.getSafeActiveSession()
verify { fakeActiveSessionHolder.fakeSession.fakeCryptoService.getLiveCryptoDeviceInfoWithId(A_DEVICE_ID).asFlow() } fakeActiveSessionHolder.fakeSession.fakeCryptoService.getMyDevicesInfoLive(A_DEVICE_ID).asFlow()
fakeActiveSessionHolder.fakeSession.fakeCryptoService.getLiveCryptoDeviceInfoWithId(A_DEVICE_ID).asFlow()
}
} }
@Test @Test