Skip to content

Commit

Permalink
fix: handle with scheme and domain from corecrypto [WPB-7084]
Browse files Browse the repository at this point in the history
  • Loading branch information
saleniuk committed Mar 11, 2024
1 parent 8189fe3 commit 6eb1f41
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ data class CryptoQualifiedClientId(

data class WireIdentity(
val clientId: CryptoQualifiedClientId,
val handle: String,
val handle: String, // handle format is "{scheme}%40{handle}@{domain}", example: "wireapp://%[email protected]"
val displayName: String,
val domain: String,
val certificate: String,
val status: CryptoCertificateStatus,
val thumbprint: String,
val serialNumber: String,
val endTimestamp: Long
)
) {
val handleWithoutSchemeAtSignAndDomain: String
get() = handle.substringAfter("://%40").removeSuffix("@$domain")
}

enum class CryptoCertificateStatus {
VALID, EXPIRED, REVOKED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1522,6 +1521,50 @@ class MLSConversationRepositoryTest {
.wasInvoked(once)
}

@Test
fun givenHandleWithSchemeAndDomain_whenGetUserIdentity_thenHandleWithoutSchemeAtSignAndDomainShouldReturnProperValue() = runTest {
// given
val handleWithSchemeAndDomain = "wireapp://%[email protected]"
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://%[email protected]"
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
Expand Down

0 comments on commit 6eb1f41

Please sign in to comment.