From 6eb1f4162cc6f0c359fd41802452f3ddaf869d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= Date: Mon, 11 Mar 2024 17:47:36 +0100 Subject: [PATCH] fix: handle with scheme and domain from corecrypto [WPB-7084] --- .../com/wire/kalium/cryptography/IDs.kt | 7 ++- ...onversationsVerificationStatusesHandler.kt | 2 +- .../MLSConversationRepositoryTest.kt | 45 ++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/IDs.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/IDs.kt index 588cd678401..fd448bbddb8 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/IDs.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/IDs.kt @@ -72,7 +72,7 @@ data class CryptoQualifiedClientId( data class WireIdentity( val clientId: CryptoQualifiedClientId, - val handle: String, + val handle: String, // handle format is "{scheme}%40{handle}@{domain}", example: "wireapp://%40hans.wurst@elna.wire.link" val displayName: String, val domain: String, val certificate: String, @@ -80,7 +80,10 @@ data class WireIdentity( val thumbprint: String, val serialNumber: String, val endTimestamp: Long -) +) { + val handleWithoutSchemeAtSignAndDomain: String + get() = handle.substringAfter("://%40").removeSuffix("@$domain") +} enum class CryptoCertificateStatus { VALID, EXPIRED, REVOKED; diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/MLSConversationsVerificationStatusesHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/MLSConversationsVerificationStatusesHandler.kt index 0fda5da96d6..4bad97b793d 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/MLSConversationsVerificationStatusesHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/MLSConversationsVerificationStatusesHandler.kt @@ -123,7 +123,7 @@ internal class MLSConversationsVerificationStatusesHandlerImpl( val isUserVerified = wireIdentity.firstOrNull { it.status != CryptoCertificateStatus.VALID || it.displayName != persistedMemberInfo?.name || - it.handle != persistedMemberInfo.handle + it.handleWithoutSchemeAtSignAndDomain != persistedMemberInfo.handle } == null if (!isUserVerified) { newStatus = VerificationStatus.NOT_VERIFIED diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt index 2cc0014451b..d39c889c66d 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/conversation/MLSConversationRepositoryTest.kt @@ -108,7 +108,6 @@ import kotlinx.coroutines.test.runTest import kotlinx.coroutines.yield import kotlinx.datetime.Instant import kotlin.test.Test -import kotlin.test.assertContentEquals import kotlin.test.assertEquals import kotlin.test.assertIs @@ -1522,6 +1521,50 @@ class MLSConversationRepositoryTest { .wasInvoked(once) } + @Test + fun givenHandleWithSchemeAndDomain_whenGetUserIdentity_thenHandleWithoutSchemeAtSignAndDomainShouldReturnProperValue() = runTest { + // given + val handleWithSchemeAndDomain = "wireapp://%40handle@domain.com" + val handle = "handle" + val groupId = Arrangement.GROUP_ID.value + val (_, mlsConversationRepository) = Arrangement() + .withGetEstablishedSelfMLSGroupIdReturns(groupId) + .withGetMLSClientSuccessful() + .withGetUserIdentitiesReturn(mapOf(groupId to listOf(WIRE_IDENTITY.copy(handle = handleWithSchemeAndDomain)))) + .arrange() + // when + val result = mlsConversationRepository.getUserIdentity(TestUser.USER_ID) + // then + result.shouldSucceed() { + it.forEach { + assertEquals(handle, it.handleWithoutSchemeAtSignAndDomain) + } + } + } + + @Test + fun givenHandleWithSchemeAndDomain_whenGetMemberIdentities_thenHandleWithoutSchemeAtSignAndDomainShouldReturnProperValue() = runTest { + // given + val handleWithSchemeAndDomain = "wireapp://%40handle@domain.com" + val handle = "handle" + val groupId = Arrangement.GROUP_ID.value + val (_, mlsConversationRepository) = Arrangement() + .withGetMLSGroupIdByConversationIdReturns(groupId) + .withGetMLSClientSuccessful() + .withGetUserIdentitiesReturn(mapOf(groupId to listOf(WIRE_IDENTITY.copy(handle = handleWithSchemeAndDomain)))) + .arrange() + // when + val result = mlsConversationRepository.getMembersIdentities(TestConversation.ID, listOf(TestUser.USER_ID)) + // then + result.shouldSucceed() { + it.values.forEach { + it.forEach { + assertEquals(handle, it.handleWithoutSchemeAtSignAndDomain) + } + } + } + } + private class Arrangement { @Mock