mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-29 05:04:54 +01:00
Remove E164s most places and prefer ServiceId more places.\
This commit is contained in:
committed by
Alex Hart
parent
d6b6884c69
commit
935dd7de45
@@ -4,7 +4,6 @@ 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.util.UuidUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -17,8 +17,8 @@ import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
import org.whispersystems.signalservice.api.groupsv2.DecryptedGroupHistoryEntry
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupHistoryPage
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
import org.whispersystems.signalservice.api.push.DistributionId
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import java.util.UUID
|
||||
|
||||
fun DecryptedGroupChange.Builder.setNewDescription(description: String) {
|
||||
@@ -190,20 +190,20 @@ fun decryptedGroup(
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun member(aci: UUID, role: Member.Role = Member.Role.DEFAULT, joinedAt: Int = 0): DecryptedMember {
|
||||
return member(ACI.from(aci), role, joinedAt)
|
||||
fun member(serviceId: UUID, role: Member.Role = Member.Role.DEFAULT, joinedAt: Int = 0): DecryptedMember {
|
||||
return member(ServiceId.from(serviceId), role, joinedAt)
|
||||
}
|
||||
|
||||
fun member(aci: ACI, role: Member.Role = Member.Role.DEFAULT, joinedAt: Int = 0): DecryptedMember {
|
||||
fun member(serviceId: ServiceId, role: Member.Role = Member.Role.DEFAULT, joinedAt: Int = 0): DecryptedMember {
|
||||
return DecryptedMember.newBuilder()
|
||||
.setRole(role)
|
||||
.setUuid(aci.toByteString())
|
||||
.setUuid(serviceId.toByteString())
|
||||
.setJoinedAtRevision(joinedAt)
|
||||
.build()
|
||||
}
|
||||
|
||||
fun requestingMember(aci: ACI): DecryptedRequestingMember {
|
||||
fun requestingMember(serviceId: ServiceId): DecryptedRequestingMember {
|
||||
return DecryptedRequestingMember.newBuilder()
|
||||
.setUuid(aci.toByteString())
|
||||
.setUuid(serviceId.toByteString())
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.util.Bitmask
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import java.util.UUID
|
||||
import kotlin.random.Random
|
||||
|
||||
@@ -31,7 +31,7 @@ object RecipientDatabaseTestUtils {
|
||||
isSelf: Boolean = false,
|
||||
participants: List<Recipient> = listOf(),
|
||||
recipientId: RecipientId = RecipientId.from(Random.nextLong()),
|
||||
aci: ACI? = ACI.from(UUID.randomUUID()),
|
||||
serviceId: ServiceId? = ServiceId.from(UUID.randomUUID()),
|
||||
username: String? = null,
|
||||
e164: String? = null,
|
||||
email: String? = null,
|
||||
@@ -93,7 +93,7 @@ object RecipientDatabaseTestUtils {
|
||||
registered,
|
||||
RecipientRecord(
|
||||
recipientId,
|
||||
aci,
|
||||
serviceId,
|
||||
null,
|
||||
username,
|
||||
e164,
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -51,7 +52,7 @@ public final class UpdateDescriptionTest {
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void stringFactory_cannot_run_on_main_thread() {
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), () -> "update", 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), () -> "update", 0);
|
||||
|
||||
setMainThread(true);
|
||||
|
||||
@@ -60,7 +61,7 @@ public final class UpdateDescriptionTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void stringFactory_cannot_call_static_string() {
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), () -> "update", 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), () -> "update", 0);
|
||||
|
||||
description.getStaticString();
|
||||
}
|
||||
@@ -74,7 +75,7 @@ public final class UpdateDescriptionTest {
|
||||
return "update";
|
||||
};
|
||||
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory, 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory, 0);
|
||||
|
||||
assertEquals(0, factoryCalls.get());
|
||||
|
||||
@@ -90,7 +91,7 @@ public final class UpdateDescriptionTest {
|
||||
public void stringFactory_reevaluated_on_every_call() {
|
||||
AtomicInteger factoryCalls = new AtomicInteger();
|
||||
UpdateDescription.StringFactory stringFactory = () -> "call" + factoryCalls.incrementAndGet();
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory, 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory, 0);
|
||||
|
||||
setMainThread(false);
|
||||
|
||||
@@ -126,8 +127,8 @@ public final class UpdateDescriptionTest {
|
||||
AtomicInteger factoryCalls2 = new AtomicInteger();
|
||||
UpdateDescription.StringFactory stringFactory1 = () -> "update." + factoryCalls1.incrementAndGet();
|
||||
UpdateDescription.StringFactory stringFactory2 = () -> "update." + factoryCalls2.incrementAndGet();
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
|
||||
factoryCalls1.set(10);
|
||||
factoryCalls2.set(20);
|
||||
@@ -149,9 +150,9 @@ public final class UpdateDescriptionTest {
|
||||
AtomicInteger factoryCalls2 = new AtomicInteger();
|
||||
UpdateDescription.StringFactory stringFactory1 = () -> "update." + factoryCalls1.incrementAndGet();
|
||||
UpdateDescription.StringFactory stringFactory2 = () -> "update." + factoryCalls2.incrementAndGet();
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.staticDescription("static", 0);
|
||||
UpdateDescription description3 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
UpdateDescription description3 = UpdateDescription.mentioning(Collections.singletonList(ServiceId.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
|
||||
factoryCalls1.set(100);
|
||||
factoryCalls2.set(200);
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.signal.zkgroup.profiles.ProfileKey;
|
||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil;
|
||||
import org.thoughtcrime.securesms.testutil.LogRecorder;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
@@ -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(ACI.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(newMember), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(member), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(member), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(member), profileKey2)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(member), profileKey1)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(member), profileKey2)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(editor), profileKey)));
|
||||
assertThat(profileKeySet.getAuthoritativeProfileKeys(), is(Collections.singletonMap(ServiceId.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(ACI.from(requesting), profileKey)));
|
||||
assertThat(profileKeySet.getProfileKeys(), is(Collections.singletonMap(ServiceId.from(requesting), profileKey)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider
|
||||
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.ServiceId
|
||||
import java.util.UUID
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@@ -52,9 +53,9 @@ class GroupsV2StateProcessorTest {
|
||||
companion object {
|
||||
val masterKey = GroupMasterKey(fromStringCondensed("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"))
|
||||
val selfAci: ACI = ACI.from(UUID.randomUUID())
|
||||
val otherAci: ACI = ACI.from(UUID.randomUUID())
|
||||
val selfAndOthers: List<DecryptedMember> = listOf(member(selfAci), member(otherAci))
|
||||
val others: List<DecryptedMember> = listOf(member(otherAci))
|
||||
val otherSid: ServiceId = ServiceId.from(UUID.randomUUID())
|
||||
val selfAndOthers: List<DecryptedMember> = listOf(member(selfAci), member(otherSid))
|
||||
val others: List<DecryptedMember> = listOf(member(otherSid))
|
||||
}
|
||||
|
||||
private lateinit var groupDatabase: GroupDatabase
|
||||
@@ -248,7 +249,7 @@ class GroupsV2StateProcessorTest {
|
||||
revision = 2,
|
||||
title = "Breaking Signal for Science",
|
||||
description = "We break stuff, because we must.",
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 2))
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 2))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(2) {
|
||||
@@ -270,7 +271,7 @@ class GroupsV2StateProcessorTest {
|
||||
revision = 3,
|
||||
title = "Breaking Signal for Science",
|
||||
description = "We break stuff, because we must.",
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 2))
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 2))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(2) {
|
||||
@@ -327,7 +328,7 @@ class GroupsV2StateProcessorTest {
|
||||
serverState(
|
||||
revision = 3,
|
||||
title = "Beam me up",
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 3))
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 3))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(3) {
|
||||
@@ -357,7 +358,7 @@ class GroupsV2StateProcessorTest {
|
||||
serverState(
|
||||
revision = 5,
|
||||
title = "Beam me up!",
|
||||
members = listOf(member(otherAci), member(selfAci, joinedAt = 3))
|
||||
members = listOf(member(otherSid), member(selfAci, joinedAt = 3))
|
||||
)
|
||||
changeSet {
|
||||
changeLog(3) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.testutil.LogRecorder;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -40,7 +41,7 @@ public final class RecipientIdCacheTest {
|
||||
|
||||
@Test
|
||||
public void empty_access_by_uuid() {
|
||||
RecipientId recipientId = recipientIdCache.get(ACI.from(UUID.randomUUID()), null);
|
||||
RecipientId recipientId = recipientIdCache.get(ServiceId.from(UUID.randomUUID()), null);
|
||||
|
||||
assertNull(recipientId);
|
||||
}
|
||||
@@ -55,11 +56,11 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_uuid() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, null));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci1, null);
|
||||
RecipientId recipientId = recipientIdCache.get(sid1, null);
|
||||
|
||||
assertEquals(recipientId1, recipientId);
|
||||
}
|
||||
@@ -67,12 +68,12 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_miss_by_uuid() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ACI aci2 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid2 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, null));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci2, null);
|
||||
RecipientId recipientId = recipientIdCache.get(sid2, null);
|
||||
|
||||
assertNull(recipientId);
|
||||
}
|
||||
@@ -80,11 +81,11 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_uuid_e164_not_supplied_on_get() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, "+15551234567"));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, "+15551234567"));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci1, null);
|
||||
RecipientId recipientId = recipientIdCache.get(sid1, null);
|
||||
|
||||
assertEquals(recipientId1, recipientId);
|
||||
}
|
||||
@@ -92,11 +93,11 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_miss_by_uuid_e164_not_supplied_on_put() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, null));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci1, "+15551234567");
|
||||
RecipientId recipientId = recipientIdCache.get(sid1, "+15551234567");
|
||||
|
||||
assertNull(recipientId);
|
||||
}
|
||||
@@ -129,9 +130,9 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_e164_uuid_not_supplied_on_get() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, "+15551234567"));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, "+15551234567"));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(null, "+15551234567");
|
||||
|
||||
@@ -141,12 +142,12 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_miss_by_e164_uuid_not_supplied_on_put() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, null, e164));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci1, e164);
|
||||
RecipientId recipientId = recipientIdCache.get(sid1, e164);
|
||||
|
||||
assertNull(recipientId);
|
||||
}
|
||||
@@ -154,12 +155,12 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void cache_hit_by_both() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, e164));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, e164));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci1, e164);
|
||||
RecipientId recipientId = recipientIdCache.get(sid1, e164);
|
||||
|
||||
assertEquals(recipientId1, recipientId);
|
||||
}
|
||||
@@ -167,13 +168,13 @@ public final class RecipientIdCacheTest {
|
||||
@Test
|
||||
public void full_recipient_id_learned_by_two_puts() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, null));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
recipientIdCache.put(recipient(recipientId1, null, e164));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci1, e164);
|
||||
RecipientId recipientId = recipientIdCache.get(sid1, e164);
|
||||
|
||||
assertEquals(recipientId1, recipientId);
|
||||
}
|
||||
@@ -182,13 +183,13 @@ public final class RecipientIdCacheTest {
|
||||
public void if_cache_state_disagrees_returns_null() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
RecipientId recipientId2 = recipientId();
|
||||
ACI aci = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid = ServiceId.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, null, e164));
|
||||
recipientIdCache.put(recipient(recipientId2, aci, null));
|
||||
recipientIdCache.put(recipient(recipientId2, sid, null));
|
||||
|
||||
RecipientId recipientId = recipientIdCache.get(aci, e164);
|
||||
RecipientId recipientId = recipientIdCache.get(sid, e164);
|
||||
|
||||
assertNull(recipientId);
|
||||
|
||||
@@ -200,15 +201,15 @@ public final class RecipientIdCacheTest {
|
||||
public void after_invalid_cache_hit_entries_are_cleared_up() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
RecipientId recipientId2 = recipientId();
|
||||
ACI aci = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid = ServiceId.from(UUID.randomUUID());
|
||||
String e164 = "+1555123456";
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, null, e164));
|
||||
recipientIdCache.put(recipient(recipientId2, aci, null));
|
||||
recipientIdCache.put(recipient(recipientId2, sid, null));
|
||||
|
||||
recipientIdCache.get(aci, e164);
|
||||
recipientIdCache.get(sid, e164);
|
||||
|
||||
assertNull(recipientIdCache.get(aci, null));
|
||||
assertNull(recipientIdCache.get(sid, null));
|
||||
assertNull(recipientIdCache.get(null, e164));
|
||||
}
|
||||
|
||||
@@ -216,57 +217,57 @@ public final class RecipientIdCacheTest {
|
||||
public void multiple_entries() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
RecipientId recipientId2 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ACI aci2 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
ServiceId sid2 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, null));
|
||||
recipientIdCache.put(recipient(recipientId2, aci2, null));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
recipientIdCache.put(recipient(recipientId2, sid2, null));
|
||||
|
||||
assertEquals(recipientId1, recipientIdCache.get(aci1, null));
|
||||
assertEquals(recipientId2, recipientIdCache.get(aci2, null));
|
||||
assertEquals(recipientId1, recipientIdCache.get(sid1, null));
|
||||
assertEquals(recipientId2, recipientIdCache.get(sid2, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void drops_oldest_when_reaches_cache_limit() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, null));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
for (int i = 0; i < TEST_CACHE_LIMIT; i++) {
|
||||
recipientIdCache.put(recipient(recipientId(), ACI.from(UUID.randomUUID()), null));
|
||||
recipientIdCache.put(recipient(recipientId(), ServiceId.from(UUID.randomUUID()), null));
|
||||
}
|
||||
|
||||
assertNull(recipientIdCache.get(aci1, null));
|
||||
assertNull(recipientIdCache.get(sid1, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void remains_in_cache_when_used_before_reaching_cache_limit() {
|
||||
RecipientId recipientId1 = recipientId();
|
||||
ACI aci1 = ACI.from(UUID.randomUUID());
|
||||
ServiceId sid1 = ServiceId.from(UUID.randomUUID());
|
||||
|
||||
recipientIdCache.put(recipient(recipientId1, aci1, null));
|
||||
recipientIdCache.put(recipient(recipientId1, sid1, null));
|
||||
|
||||
for (int i = 0; i < TEST_CACHE_LIMIT - 1; i++) {
|
||||
recipientIdCache.put(recipient(recipientId(), ACI.from(UUID.randomUUID()), null));
|
||||
recipientIdCache.put(recipient(recipientId(), ServiceId.from(UUID.randomUUID()), null));
|
||||
}
|
||||
|
||||
assertEquals(recipientId1, recipientIdCache.get(aci1, null));
|
||||
assertEquals(recipientId1, recipientIdCache.get(sid1, null));
|
||||
|
||||
recipientIdCache.put(recipient(recipientId(), ACI.from(UUID.randomUUID()), null));
|
||||
recipientIdCache.put(recipient(recipientId(), ServiceId.from(UUID.randomUUID()), null));
|
||||
|
||||
assertEquals(recipientId1, recipientIdCache.get(aci1, null));
|
||||
assertEquals(recipientId1, recipientIdCache.get(sid1, null));
|
||||
}
|
||||
|
||||
private static @NonNull RecipientId recipientId() {
|
||||
return mock(RecipientId.class);
|
||||
}
|
||||
|
||||
private static @NonNull Recipient recipient(RecipientId recipientId, @Nullable ACI aci, @Nullable String e164) {
|
||||
private static @NonNull Recipient recipient(RecipientId recipientId, @Nullable ServiceId serviceId, @Nullable String e164) {
|
||||
Recipient mock = mock(Recipient.class);
|
||||
|
||||
when(mock.getId()).thenReturn(recipientId);
|
||||
when(mock.getServiceId()).thenReturn(Optional.fromNullable(aci));
|
||||
when(mock.getServiceId()).thenReturn(Optional.fromNullable(serviceId));
|
||||
when(mock.getE164()).thenReturn(Optional.fromNullable(e164));
|
||||
|
||||
return mock;
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.storage.StorageSyncHelper.IdDifferenceResult;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.api.storage.SignalAccountRecord;
|
||||
import org.whispersystems.signalservice.api.storage.SignalContactRecord;
|
||||
@@ -47,15 +47,15 @@ import static org.thoughtcrime.securesms.testutil.TestHelpers.byteListOf;
|
||||
@PowerMockRunnerDelegate(JUnit4.class)
|
||||
public final class StorageSyncHelperTest {
|
||||
|
||||
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 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 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(ACI_SELF));
|
||||
when(SELF.getServiceId()).thenReturn(Optional.of(SID_SELF));
|
||||
when(SELF.getE164()).thenReturn(Optional.of(E164_SELF));
|
||||
when(SELF.resolve()).thenReturn(SELF);
|
||||
}
|
||||
@@ -132,8 +132,8 @@ public final class StorageSyncHelperTest {
|
||||
byte[] profileKey = new byte[32];
|
||||
byte[] profileKeyCopy = profileKey.clone();
|
||||
|
||||
SignalContactRecord a = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
SignalContactRecord a = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
@@ -147,8 +147,8 @@ public final class StorageSyncHelperTest {
|
||||
byte[] profileKeyCopy = profileKey.clone();
|
||||
profileKeyCopy[0] = 1;
|
||||
|
||||
SignalContactRecord a = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, ACI_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
SignalContactRecord a = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKey).build();
|
||||
SignalContactRecord b = contactBuilder(1, SID_A, E164_A, "a").setProfileKey(profileKeyCopy).build();
|
||||
|
||||
assertNotEquals(a, b);
|
||||
assertNotEquals(a.hashCode(), b.hashCode());
|
||||
@@ -171,7 +171,7 @@ public final class StorageSyncHelperTest {
|
||||
}
|
||||
|
||||
private static SignalContactRecord.Builder contactBuilder(int key,
|
||||
ACI aci,
|
||||
ServiceId aci,
|
||||
String e164,
|
||||
String profileName)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user