mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 04:33:36 +00:00
Use strongly-typed ACIs and PNIs everywhere.
This commit is contained in:
@@ -30,7 +30,6 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.testutil.SystemOutLogger
|
||||
import org.thoughtcrime.securesms.util.IdentityUtil
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException
|
||||
import org.whispersystems.signalservice.api.services.ProfileService
|
||||
import org.whispersystems.signalservice.internal.ServiceResponse
|
||||
@@ -125,7 +124,7 @@ class SafetyNumberRepositoryTest {
|
||||
@Test
|
||||
fun batchSafetyNumberCheckSync_batchOf1_oneChange() {
|
||||
val other = recipientPool[1]
|
||||
val otherAci = ACI.from(other.requireServiceId())
|
||||
val otherAci = other.requireAci()
|
||||
val otherNewIdentityKey = IdentityKeyUtil.generateIdentityKeyPair().publicKey
|
||||
val keys = listOf(ContactSearchKey.RecipientSearchKey(other.id, false))
|
||||
|
||||
@@ -146,7 +145,7 @@ class SafetyNumberRepositoryTest {
|
||||
fun batchSafetyNumberCheckSync_batchOf2_oneChange() {
|
||||
val other = recipientPool[1]
|
||||
val secondOther = recipientPool[2]
|
||||
val otherAci = ACI.from(other.requireServiceId())
|
||||
val otherAci = other.requireAci()
|
||||
val otherNewIdentityKey = IdentityKeyUtil.generateIdentityKeyPair().publicKey
|
||||
val keys = listOf(ContactSearchKey.RecipientSearchKey(other.id, false), ContactSearchKey.RecipientSearchKey(secondOther.id, false))
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.contacts.sync;
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.contacts.sync.FuzzyPhoneNumberHelper.InputResult;
|
||||
import org.thoughtcrime.securesms.contacts.sync.FuzzyPhoneNumberHelper.OutputResult;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -85,15 +85,15 @@ class GroupChangeData(private val revision: Int, private val groupOperations: Gr
|
||||
}
|
||||
|
||||
fun source(serviceId: ServiceId) {
|
||||
actionsBuilder.sourceUuid = groupOperations.encryptUuid(serviceId.uuid())
|
||||
actionsBuilder.sourceUuid = groupOperations.encryptUuid(serviceId.rawUuid)
|
||||
}
|
||||
|
||||
fun deleteMember(serviceId: ServiceId) {
|
||||
actionsBuilder.addDeleteMembers(GroupChange.Actions.DeleteMemberAction.newBuilder().setDeletedUserId(groupOperations.encryptUuid(serviceId.uuid())))
|
||||
actionsBuilder.addDeleteMembers(GroupChange.Actions.DeleteMemberAction.newBuilder().setDeletedUserId(groupOperations.encryptUuid(serviceId.rawUuid)))
|
||||
}
|
||||
|
||||
fun modifyRole(serviceId: ServiceId, role: Member.Role) {
|
||||
actionsBuilder.addModifyMemberRoles(GroupChange.Actions.ModifyMemberRoleAction.newBuilder().setUserId(groupOperations.encryptUuid(serviceId.uuid())).setRole(role))
|
||||
actionsBuilder.addModifyMemberRoles(GroupChange.Actions.ModifyMemberRoleAction.newBuilder().setUserId(groupOperations.encryptUuid(serviceId.rawUuid)).setRole(role))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.recipients.RecipientDetails
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import java.util.Optional
|
||||
import java.util.UUID
|
||||
import kotlin.random.Random
|
||||
@@ -34,7 +34,7 @@ object RecipientDatabaseTestUtils {
|
||||
isSelf: Boolean = false,
|
||||
participants: List<RecipientId> = listOf(),
|
||||
recipientId: RecipientId = RecipientId.from(Random.nextLong()),
|
||||
serviceId: ServiceId? = ServiceId.from(UUID.randomUUID()),
|
||||
serviceId: ACI? = ACI.from(UUID.randomUUID()),
|
||||
username: String? = null,
|
||||
e164: String? = null,
|
||||
email: String? = null,
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.signal.storageservice.protos.groups.local.DecryptedMember;
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedPendingMember;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.PNI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.PNI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.ServiceIds;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
@@ -88,8 +88,8 @@ public final class GroupsV2UpdateMessageProducerTest {
|
||||
|
||||
producer = new GroupsV2UpdateMessageProducer(ApplicationProvider.getApplicationContext(), new ServiceIds(ACI.from(you), PNI.from(UUID.randomUUID())), null);
|
||||
|
||||
recipientIdMockedStatic.when(() -> RecipientId.from(ServiceId.from(alice))).thenReturn(aliceId);
|
||||
recipientIdMockedStatic.when(() -> RecipientId.from(ServiceId.from(bob))).thenReturn(bobId);
|
||||
recipientIdMockedStatic.when(() -> RecipientId.from(ACI.from(alice))).thenReturn(aliceId);
|
||||
recipientIdMockedStatic.when(() -> RecipientId.from(ACI.from(bob))).thenReturn(bobId);
|
||||
recipientMockedStatic.when(() -> Recipient.resolved(aliceId)).thenReturn(aliceRecipient);
|
||||
recipientMockedStatic.when(() -> Recipient.resolved(bobId)).thenReturn(bobRecipient);
|
||||
}
|
||||
@@ -1446,7 +1446,7 @@ public final class GroupsV2UpdateMessageProducerTest {
|
||||
}
|
||||
|
||||
private void assertSingleChangeMentioning(DecryptedGroupChange change, List<UUID> expectedMentions) {
|
||||
List<ServiceId> expectedMentionSids = expectedMentions.stream().map(ServiceId::from).collect(Collectors.toList());
|
||||
List<ServiceId> expectedMentionSids = expectedMentions.stream().map(ACI::from).collect(Collectors.toList());
|
||||
|
||||
List<UpdateDescription> changes = producer.describeChanges(null, change);
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -46,7 +47,7 @@ public final class UpdateDescriptionTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void stringFactory_cannot_call_static_string() {
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), () -> new SpannableString("update"), 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), () -> new SpannableString("update"), 0);
|
||||
|
||||
description.getStaticSpannable();
|
||||
}
|
||||
@@ -60,7 +61,7 @@ public final class UpdateDescriptionTest {
|
||||
return new SpannableString("update");
|
||||
};
|
||||
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory, 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory, 0);
|
||||
|
||||
assertEquals(0, factoryCalls.get());
|
||||
|
||||
@@ -74,7 +75,7 @@ public final class UpdateDescriptionTest {
|
||||
public void stringFactory_reevaluated_on_every_call() {
|
||||
AtomicInteger factoryCalls = new AtomicInteger();
|
||||
UpdateDescription.SpannableFactory stringFactory = () -> new SpannableString( "call" + factoryCalls.incrementAndGet());
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory, 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory, 0);
|
||||
|
||||
assertEquals("call1", description.getSpannable().toString());
|
||||
assertEquals("call2", description.getSpannable().toString());
|
||||
@@ -108,8 +109,8 @@ public final class UpdateDescriptionTest {
|
||||
AtomicInteger factoryCalls2 = new AtomicInteger();
|
||||
UpdateDescription.SpannableFactory stringFactory1 = () -> new SpannableString("update." + factoryCalls1.incrementAndGet());
|
||||
UpdateDescription.SpannableFactory stringFactory2 = () -> new SpannableString("update." + factoryCalls2.incrementAndGet());
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
|
||||
factoryCalls1.set(10);
|
||||
factoryCalls2.set(20);
|
||||
@@ -129,9 +130,9 @@ public final class UpdateDescriptionTest {
|
||||
AtomicInteger factoryCalls2 = new AtomicInteger();
|
||||
UpdateDescription.SpannableFactory stringFactory1 = () -> new SpannableString("update." + factoryCalls1.incrementAndGet());
|
||||
UpdateDescription.SpannableFactory stringFactory2 = () -> new SpannableString("update." + factoryCalls2.incrementAndGet());
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.staticDescription("static", 0);
|
||||
UpdateDescription description3 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
UpdateDescription description3 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
|
||||
factoryCalls1.set(100);
|
||||
factoryCalls2.set(200);
|
||||
|
||||
@@ -39,9 +39,8 @@ import org.thoughtcrime.securesms.testutil.SystemOutLogger
|
||||
import org.whispersystems.signalservice.api.groupsv2.ClientZkOperations
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Api
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Operations
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
import org.whispersystems.signalservice.api.push.PNI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.PNI
|
||||
import org.whispersystems.signalservice.api.push.ServiceIds
|
||||
import java.util.UUID
|
||||
|
||||
@@ -58,9 +57,9 @@ class GroupManagerV2Test_edit {
|
||||
val selfAci: ACI = ACI.from(UUID.randomUUID())
|
||||
val selfPni: PNI = PNI.from(UUID.randomUUID())
|
||||
val serviceIds: ServiceIds = ServiceIds(selfAci, selfPni)
|
||||
val otherSid: ServiceId = ServiceId.from(UUID.randomUUID())
|
||||
val selfAndOthers: List<DecryptedMember> = listOf(member(selfAci), member(otherSid))
|
||||
val others: List<DecryptedMember> = listOf(member(otherSid))
|
||||
val otherAci: ACI = ACI.from(UUID.randomUUID())
|
||||
val selfAndOthers: List<DecryptedMember> = listOf(member(selfAci), member(otherAci))
|
||||
val others: List<DecryptedMember> = listOf(member(otherAci))
|
||||
}
|
||||
|
||||
private lateinit var groupTable: GroupTable
|
||||
@@ -136,13 +135,13 @@ class GroupManagerV2Test_edit {
|
||||
revision = 5,
|
||||
members = listOf(
|
||||
member(selfAci, role = Member.Role.ADMINISTRATOR),
|
||||
member(otherSid)
|
||||
member(otherAci)
|
||||
)
|
||||
)
|
||||
groupChange(6) {
|
||||
source(selfAci)
|
||||
deleteMember(selfAci)
|
||||
modifyRole(otherSid, Member.Role.ADMINISTRATOR)
|
||||
modifyRole(otherAci, Member.Role.ADMINISTRATOR)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +152,7 @@ class GroupManagerV2Test_edit {
|
||||
then { patchedGroup ->
|
||||
assertThat("Revision updated by one", patchedGroup.revision, `is`(6))
|
||||
assertThat("Self is no longer in the group", patchedGroup.membersList.find { it.uuid == selfAci.toByteString() }, Matchers.nullValue())
|
||||
assertThat("Other is now an admin in the group", patchedGroup.membersList.find { it.uuid == otherSid.toByteString() }?.role, `is`(Member.Role.ADMINISTRATOR))
|
||||
assertThat("Other is now an admin in the group", patchedGroup.membersList.find { it.uuid == otherAci.toByteString() }?.role, `is`(Member.Role.ADMINISTRATOR))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKey;
|
||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
|
||||
import org.thoughtcrime.securesms.testutil.LogRecorder;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -40,7 +41,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(editor).addMember(newMember, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(newMember), profileKey)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,7 +53,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(newMember).addMember(newMember, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(newMember), profileKey)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,7 +65,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(newMember).promote(newMember, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(newMember), profileKey)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +78,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(editor).promote(newMember, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(newMember), profileKey)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +90,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeByUnknown().promote(newMember, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(newMember), profileKey)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +102,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(member).profileKeyUpdate(member, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.from(member), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(member), profileKey)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,7 +115,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(editor).profileKeyUpdate(member, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.from(member), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(member), profileKey)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +130,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(editor).profileKeyUpdate(member, profileKey2).build());
|
||||
|
||||
assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.from(member), profileKey2)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(member), profileKey2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -144,7 +145,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(editor).profileKeyUpdate(member, profileKey2).build());
|
||||
|
||||
assertTrue(profileKeySet.getProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.from(member), profileKey1)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(member), profileKey1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +160,7 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(member).profileKeyUpdate(member, profileKey2).build());
|
||||
|
||||
assertTrue(profileKeySet.getProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.from(member), profileKey2)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(member), profileKey2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,7 +187,7 @@ public final class ProfileKeySetTest {
|
||||
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(editor).requestJoin(profileKey).build());
|
||||
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.from(editor), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ACI.from(editor), profileKey)));
|
||||
assertTrue(profileKeySet.getProfileKeys().isEmpty());
|
||||
}
|
||||
|
||||
@@ -200,6 +201,6 @@ public final class ProfileKeySetTest {
|
||||
profileKeySet.addKeysFromGroupChange(changeBy(editor).requestJoin(requesting, profileKey).build());
|
||||
|
||||
assertTrue(profileKeySet.getAuthoritativeProfileKeys().isEmpty());
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.from(requesting), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ACI.from(requesting), profileKey)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,8 @@ import org.thoughtcrime.securesms.logging.CustomSignalProtocolLogger
|
||||
import org.thoughtcrime.securesms.testutil.SystemOutLogger
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupsV2Api
|
||||
import org.whispersystems.signalservice.api.groupsv2.PartialDecryptedGroup
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
import org.whispersystems.signalservice.api.push.PNI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.PNI
|
||||
import org.whispersystems.signalservice.api.push.ServiceIds
|
||||
import java.util.UUID
|
||||
|
||||
@@ -60,9 +59,9 @@ class GroupsV2StateProcessorTest {
|
||||
private val masterKey = GroupMasterKey(fromStringCondensed("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"))
|
||||
private val selfAci: ACI = ACI.from(UUID.randomUUID())
|
||||
private val serviceIds: ServiceIds = ServiceIds(selfAci, PNI.from(UUID.randomUUID()))
|
||||
private val otherSid: ServiceId = ServiceId.from(UUID.randomUUID())
|
||||
private val selfAndOthers: List<DecryptedMember> = listOf(member(selfAci), member(otherSid))
|
||||
private val others: List<DecryptedMember> = listOf(member(otherSid))
|
||||
private val otherAci: ACI = ACI.from(UUID.randomUUID())
|
||||
private val selfAndOthers: List<DecryptedMember> = listOf(member(selfAci), member(otherAci))
|
||||
private val others: List<DecryptedMember> = listOf(member(otherAci))
|
||||
}
|
||||
|
||||
private lateinit var groupTable: GroupTable
|
||||
@@ -268,7 +267,7 @@ class GroupsV2StateProcessorTest {
|
||||
revision = 2,
|
||||
title = "Breaking Signal for Science",
|
||||
description = "We break stuff, because we must.",
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 2))
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 2))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(2) {
|
||||
@@ -290,7 +289,7 @@ class GroupsV2StateProcessorTest {
|
||||
revision = 3,
|
||||
title = "Breaking Signal for Science",
|
||||
description = "We break stuff, because we must.",
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 2))
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 2))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(2) {
|
||||
@@ -346,7 +345,7 @@ class GroupsV2StateProcessorTest {
|
||||
serverState(
|
||||
revision = 3,
|
||||
title = "Beam me up",
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 3))
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 3))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(3) {
|
||||
@@ -376,7 +375,7 @@ class GroupsV2StateProcessorTest {
|
||||
serverState(
|
||||
revision = 5,
|
||||
title = "Beam me up!",
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 3))
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 3))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(3) {
|
||||
@@ -470,7 +469,7 @@ class GroupsV2StateProcessorTest {
|
||||
*/
|
||||
@Test
|
||||
fun missedMemberAddResolvesWithMultipleRevisionUpdate() {
|
||||
val secondOther = member(ServiceId.from(UUID.randomUUID()))
|
||||
val secondOther = member(ACI.from(UUID.randomUUID()))
|
||||
|
||||
profileAndMessageHelper.masterKey = masterKey
|
||||
|
||||
@@ -521,7 +520,7 @@ class GroupsV2StateProcessorTest {
|
||||
*/
|
||||
@Test
|
||||
fun missedMemberAddResolvesWithForcedUpdate() {
|
||||
val secondOther = member(ServiceId.from(UUID.randomUUID()))
|
||||
val secondOther = member(ACI.from(UUID.randomUUID()))
|
||||
|
||||
profileAndMessageHelper.masterKey = masterKey
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.testutil.LogRecorder;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -40,7 +41,7 @@ public final class RecipientIdCacheTest {
|
||||
|
||||
@Test
|
||||
public void empty_access_by_uuid() {
|
||||
RecipientId recipientId = recipientIdCache.get(ServiceId.from(UUID.randomUUID()), null);
|
||||
RecipientId recipientId = recipientIdCache.get(ACI.from(UUID.randomUUID()), null);
|
||||
|
||||
assertNull(recipientId);
|
||||
}
|
||||
@@ -55,7 +56,7 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_uuid() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
@@ -67,8 +68,8 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_miss_by_uuid() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid2 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid2 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
@@ -80,7 +81,7 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_uuid_e164_not_supplied_on_get() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, "+15551234567"));
|
||||
|
||||
@@ -92,7 +93,7 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_miss_by_uuid_e164_not_supplied_on_put() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
@@ -129,7 +130,7 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_e164_uuid_not_supplied_on_get() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, "+15551234567"));
|
||||
|
||||
@@ -141,7 +142,7 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_miss_by_e164_uuid_not_supplied_on_put() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, null, e164));
|
||||
@@ -154,7 +155,7 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_both() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, e164));
|
||||
@@ -167,7 +168,7 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void full_recipient_id_learned_by_two_puts() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
@@ -182,7 +183,7 @@ public final class RecipientIdCacheTest {
|
||||
public void if_cache_state_disagrees_returns_null() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
RecipientId recipientId2 = recipientId();
|
||||
ServiceId sid = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid = ACI.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, null, e164));
|
||||
@@ -200,7 +201,7 @@ public final class RecipientIdCacheTest {
|
||||
public void after_invalid_cache_hit_entries_are_cleared_up() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
RecipientId recipientId2 = recipientId();
|
||||
ServiceId sid = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid = ACI.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, null, e164));
|
||||
@@ -216,8 +217,8 @@ public final class RecipientIdCacheTest {
|
||||
public void multiple_entries() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
RecipientId recipientId2 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid2 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid2 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
recipientIdCache.put(recipient(recipientId2, sid2, null));
|
||||
@@ -229,12 +230,12 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void drops_oldest_when_reaches_cache_limit() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
for (int i = 0; i < TEST_CACHE_LIMIT; i++) {
|
||||
recipientIdCache.put(recipient(recipientId(), ServiceId.from(UUID.randomUUID()), null));
|
||||
recipientIdCache.put(recipient(recipientId(), ACI.from(UUID.randomUUID()), null));
|
||||
}
|
||||
|
||||
assertNull(recipientIdCache.get(sid1, null));
|
||||
@@ -243,17 +244,17 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void remains_in_cache_when_used_before_reaching_cache_limit() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ACI.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
for (int i = 0; i < TEST_CACHE_LIMIT - 1; i++) {
|
||||
recipientIdCache.put(recipient(recipientId(), ServiceId.from(UUID.randomUUID()), null));
|
||||
recipientIdCache.put(recipient(recipientId(), ACI.from(UUID.randomUUID()), null));
|
||||
}
|
||||
|
||||
assertEquals(recipientId1, recipientIdCache.get(sid1, null));
|
||||
|
||||
recipientIdCache.put(recipient(recipientId(), ServiceId.from(UUID.randomUUID()), null));
|
||||
recipientIdCache.put(recipient(recipientId(), ACI.from(UUID.randomUUID()), null));
|
||||
|
||||
assertEquals(recipientId1, recipientIdCache.get(sid1, null));
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.thoughtcrime.securesms.keyvalue.AccountValues
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.testutil.EmptyLogger
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
import org.whispersystems.signalservice.api.push.PNI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.PNI
|
||||
import org.whispersystems.signalservice.api.storage.SignalContactRecord
|
||||
import org.whispersystems.signalservice.api.storage.StorageId
|
||||
import org.whispersystems.signalservice.internal.storage.protos.ContactRecord
|
||||
@@ -56,9 +56,9 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServicePni(PNI_B.toString())
|
||||
setServiceE164(E164_B)
|
||||
setAci(ACI_B.toString())
|
||||
setPni(PNI_B.toString())
|
||||
setE164(E164_B)
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -74,7 +74,7 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceE164(E164_B)
|
||||
setE164(E164_B)
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -90,8 +90,8 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServiceE164(E164_A)
|
||||
setAci(ACI_B.toString())
|
||||
setE164(E164_A)
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -107,7 +107,7 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_A.toString())
|
||||
setAci(ACI_A.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -123,7 +123,7 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(PNI_A.toString())
|
||||
setAci(PNI_A.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -139,8 +139,8 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServicePni(PNI_A.toString())
|
||||
setAci(ACI_B.toString())
|
||||
setPni(PNI_A.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -150,52 +150,14 @@ class ContactRecordProcessorTest {
|
||||
assertTrue(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isInvalid, pniOnly pnpDisabled, true`() {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(false)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(PNI_B.toString())
|
||||
setServicePni(PNI_B.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
|
||||
// THEN
|
||||
assertTrue(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isInvalid, pniOnly pnpEnabled, false`() {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(true)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(PNI_B.toString())
|
||||
setServicePni(PNI_B.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
|
||||
// THEN
|
||||
assertFalse(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `isInvalid, valid E164, true`() {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServiceE164(E164_B)
|
||||
setAci(ACI_B.toString())
|
||||
setE164(E164_B)
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -211,8 +173,8 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServiceE164("15551234567")
|
||||
setAci(ACI_B.toString())
|
||||
setE164("15551234567")
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -228,8 +190,8 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServiceE164("+1555ABC4567")
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+1555ABC4567")
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -245,8 +207,8 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServiceE164("+")
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+")
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -262,8 +224,8 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServiceE164("+12345678901234567890")
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+12345678901234567890")
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -279,8 +241,8 @@ class ContactRecordProcessorTest {
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setServiceId(ACI_B.toString())
|
||||
setServiceE164("+05551234567")
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+05551234567")
|
||||
}
|
||||
|
||||
// WHEN
|
||||
@@ -298,22 +260,22 @@ class ContactRecordProcessorTest {
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(true)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_A)
|
||||
setServicePni(PNI_A.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_A)
|
||||
setServicePni(PNI_B.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_B.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
|
||||
// THEN
|
||||
assertEquals(local.serviceId, result.serviceId)
|
||||
assertEquals(local.aci, result.aci)
|
||||
assertEquals(local.number.get(), result.number.get())
|
||||
assertEquals(local.pni.get(), result.pni.get())
|
||||
}
|
||||
@@ -326,22 +288,22 @@ class ContactRecordProcessorTest {
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(true)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_A)
|
||||
setServicePni(PNI_A.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_B)
|
||||
setServicePni(PNI_A.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_A.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
|
||||
// THEN
|
||||
assertEquals(local.serviceId, result.serviceId)
|
||||
assertEquals(local.aci, result.aci)
|
||||
assertEquals(local.number.get(), result.number.get())
|
||||
assertEquals(local.pni.get(), result.pni.get())
|
||||
}
|
||||
@@ -354,22 +316,22 @@ class ContactRecordProcessorTest {
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(true)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_A)
|
||||
setServicePni(PNI_A.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_B)
|
||||
setServicePni(PNI_B.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_B.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
|
||||
// THEN
|
||||
assertEquals(remote.serviceId, result.serviceId)
|
||||
assertEquals(remote.aci, result.aci)
|
||||
assertEquals(remote.number.get(), result.number.get())
|
||||
assertEquals(remote.pni.get(), result.pni.get())
|
||||
}
|
||||
@@ -382,22 +344,22 @@ class ContactRecordProcessorTest {
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(false)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_A)
|
||||
setServicePni(PNI_A.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toString())
|
||||
}
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setServiceId(ACI_A.toString())
|
||||
setServiceE164(E164_B)
|
||||
setServicePni(PNI_B.toString())
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_B.toString())
|
||||
}
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
|
||||
// THEN
|
||||
assertEquals(remote.serviceId, result.serviceId)
|
||||
assertEquals(remote.aci, result.aci)
|
||||
assertEquals(remote.number.get(), result.number.get())
|
||||
assertEquals(false, result.pni.isPresent)
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper.IdDifferenceResult;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.storage.SignalAccountRecord;
|
||||
import org.whispersystems.signalservice.api.storage.SignalContactRecord;
|
||||
import org.whispersystems.signalservice.api.storage.SignalGroupV1Record;
|
||||
@@ -40,15 +41,15 @@ import static org.thoughtcrime.securesms.testutil.TestHelpers.byteListOf;
|
||||
|
||||
public final class StorageSyncHelperTest {
|
||||
|
||||
private static final ServiceId SID_A = ServiceId.parseOrThrow("ebef429e-695e-4f51-bcc4-526a60ac68c7");
|
||||
private static final ServiceId SID_SELF = ServiceId.parseOrThrow("1b2a2ca5-fc9e-4656-8c9f-22cc349ed3af");
|
||||
private static final ACI ACI_A = ACI.parseOrThrow("ebef429e-695e-4f51-bcc4-526a60ac68c7");
|
||||
private static final ACI ACI_SELF = ACI.parseOrThrow("1b2a2ca5-fc9e-4656-8c9f-22cc349ed3af");
|
||||
|
||||
private static final String E164_A = "+16108675309";
|
||||
private static final String E164_SELF = "+16105555555";
|
||||
|
||||
private static final Recipient SELF = mock(Recipient.class);
|
||||
static {
|
||||
when(SELF.getServiceId()).thenReturn(Optional.of(SID_SELF));
|
||||
when(SELF.getServiceId()).thenReturn(Optional.of(ACI_SELF));
|
||||
when(SELF.getE164()).thenReturn(Optional.of(E164_SELF));
|
||||
when(SELF.resolve()).thenReturn(SELF);
|
||||
}
|
||||
@@ -132,8 +133,8 @@ public final class StorageSyncHelperTest {
|
||||
byte[] profileKey = new byte[32];
|
||||
byte[] profileKeyCopy = profileKey.clone();
|
||||
|
||||
SignalContactRecord a = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
SignalContactRecord a = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
@@ -147,8 +148,8 @@ public final class StorageSyncHelperTest {
|
||||
byte[] profileKeyCopy = profileKey.clone();
|
||||
profileKeyCopy[0] = 1;
|
||||
|
||||
SignalContactRecord a = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
SignalContactRecord a = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
|
||||
assertNotEquals(a, b);
|
||||
assertNotEquals(a.hashCode(), b.hashCode());
|
||||
@@ -171,7 +172,7 @@ public final class StorageSyncHelperTest {
|
||||
}
|
||||
|
||||
private static SignalContactRecord.Builder contactBuilder(int key,
|
||||
ServiceId aci,
|
||||
ACI aci,
|
||||
String e164,
|
||||
String profileName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user