Add read support for binary service ids.

This commit is contained in:
Michelle Tang
2025-10-28 14:29:43 -04:00
committed by jeffrey-signal
parent bf4aa9cae9
commit f16405fabf
48 changed files with 399 additions and 205 deletions

View File

@@ -197,14 +197,14 @@ class ChatFolderRecordProcessorTest {
val proto = ChatFolderRecord.Builder().apply {
identifier = UuidUtil.toByteArray(UUID.randomUUID()).toByteString()
name = "Folder1"
position = -1
position = 1
showOnlyUnread = false
showMutedChats = false
includeAllIndividualChats = false
includeAllGroupChats = false
folderType = ChatFolderRecord.FolderType.CUSTOM
deletedAtTimestampMs = 0L
includedRecipients = listOf(Recipient(contact = Recipient.Contact(serviceId = "bad")))
includedRecipients = listOf(Recipient(contact = Recipient.Contact(serviceIdBinary = "bad".toByteArray().toByteString())))
}.build()
val record = SignalChatFolderRecord(STORAGE_ID, proto)

View File

@@ -21,6 +21,7 @@ import org.thoughtcrime.securesms.database.RecipientTable
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.testutil.EmptyLogger
import org.thoughtcrime.securesms.testutil.MockAppDependenciesRule
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.storage.SignalContactRecord
@@ -58,8 +59,8 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
pni = PNI_B.toStringWithoutPrefix(),
aciBinary = ACI_B.toByteString(),
pniBinary = PNI_B.toByteStringWithoutPrefix(),
e164 = E164_B
)
)
@@ -96,8 +97,8 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI.UNKNOWN.toString(),
pni = PNI.UNKNOWN.toString(),
aciBinary = ACI.UNKNOWN.toByteString(),
pniBinary = PNI.UNKNOWN.toByteString(),
e164 = E164_B
)
)
@@ -116,7 +117,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
aciBinary = ACI_B.toByteString(),
e164 = E164_A
)
)
@@ -135,7 +136,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_A.toString()
aciBinary = ACI_A.toByteString()
)
)
@@ -153,8 +154,8 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
pni = PNI_A.toStringWithoutPrefix()
aciBinary = ACI_B.toByteString(),
pniBinary = PNI_A.toByteStringWithoutPrefix()
)
)
@@ -172,7 +173,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
aciBinary = ACI_B.toByteString(),
e164 = E164_B
)
)
@@ -191,7 +192,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
aciBinary = ACI_B.toByteString(),
e164 = "15551234567"
)
)
@@ -210,7 +211,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
aciBinary = ACI_B.toByteString(),
e164 = "+1555ABC4567"
)
)
@@ -229,7 +230,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
aciBinary = ACI_B.toByteString(),
e164 = "+"
)
)
@@ -248,7 +249,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
aciBinary = ACI_B.toByteString(),
e164 = "+12345678901234567890"
)
)
@@ -267,7 +268,7 @@ class ContactRecordProcessorTest {
val record = buildRecord(
record = ContactRecord(
aci = ACI_B.toString(),
aciBinary = ACI_B.toByteString(),
e164 = "+05551234567"
)
)
@@ -287,18 +288,18 @@ class ContactRecordProcessorTest {
val local = buildRecord(
STORAGE_ID_A,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_A,
pni = PNI_A.toStringWithoutPrefix()
pniBinary = PNI_A.toByteStringWithoutPrefix()
)
)
val remote = buildRecord(
STORAGE_ID_B,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_A,
pni = PNI_B.toStringWithoutPrefix()
pniBinary = PNI_B.toByteStringWithoutPrefix()
)
)
@@ -306,9 +307,9 @@ class ContactRecordProcessorTest {
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
// THEN
assertEquals(local.proto.aci, result.proto.aci)
assertEquals(ServiceId.parseOrNull(local.proto.aci, local.proto.aciBinary), ServiceId.parseOrNull(result.proto.aci, result.proto.aciBinary))
assertEquals(local.proto.e164, result.proto.e164)
assertEquals(local.proto.pni, result.proto.pni)
assertEquals(ServiceId.parseOrNull(local.proto.pni, local.proto.pniBinary), ServiceId.parseOrNull(result.proto.pni, result.proto.pniBinary))
}
@Test
@@ -319,18 +320,18 @@ class ContactRecordProcessorTest {
val local = buildRecord(
STORAGE_ID_A,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_A,
pni = PNI_A.toStringWithoutPrefix()
pniBinary = PNI_A.toByteStringWithoutPrefix()
)
)
val remote = buildRecord(
STORAGE_ID_B,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_B,
pni = PNI_A.toStringWithoutPrefix()
pniBinary = PNI_A.toByteStringWithoutPrefix()
)
)
@@ -338,9 +339,9 @@ class ContactRecordProcessorTest {
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
// THEN
assertEquals(local.proto.aci, result.proto.aci)
assertEquals(ServiceId.parseOrNull(local.proto.aci, local.proto.aciBinary), ServiceId.parseOrNull(result.proto.aci, result.proto.aciBinary))
assertEquals(local.proto.e164, result.proto.e164)
assertEquals(local.proto.pni, result.proto.pni)
assertEquals(ServiceId.parseOrNull(local.proto.pni, local.proto.pniBinary), ServiceId.parseOrNull(result.proto.pni, result.proto.pniBinary))
}
@Test
@@ -351,18 +352,18 @@ class ContactRecordProcessorTest {
val local = buildRecord(
STORAGE_ID_A,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_A,
pni = PNI_A.toStringWithoutPrefix()
pniBinary = PNI_A.toByteStringWithoutPrefix()
)
)
val remote = buildRecord(
STORAGE_ID_B,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_B,
pni = PNI_B.toStringWithoutPrefix()
pniBinary = PNI_B.toByteStringWithoutPrefix()
)
)
@@ -370,9 +371,9 @@ class ContactRecordProcessorTest {
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
// THEN
assertEquals(remote.proto.aci, result.proto.aci)
assertEquals(ServiceId.parseOrNull(remote.proto.aci, remote.proto.aciBinary), ServiceId.parseOrNull(result.proto.aci, result.proto.aciBinary))
assertEquals(remote.proto.e164, result.proto.e164)
assertEquals(remote.proto.pni, result.proto.pni)
assertEquals(ServiceId.parseOrNull(remote.proto.pni, remote.proto.pniBinary), ServiceId.parseOrNull(result.proto.pni, result.proto.pniBinary))
}
@Test
@@ -383,7 +384,7 @@ class ContactRecordProcessorTest {
val local = buildRecord(
STORAGE_ID_A,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_A
)
)
@@ -391,7 +392,7 @@ class ContactRecordProcessorTest {
val remote = buildRecord(
STORAGE_ID_B,
record = ContactRecord(
aci = ACI_A.toString(),
aciBinary = ACI_A.toByteString(),
e164 = E164_A,
nickname = ContactRecord.Name(given = "Ghost", family = "Spider"),
note = "Spidey Friend"

View File

@@ -103,7 +103,7 @@ class NotificationProfileRecordProcessorTest {
val proto = NotificationProfile.Builder().apply {
id = UuidUtil.toByteArray(UUID.randomUUID()).toByteString()
name = "Profile"
allowedMembers = listOf(Recipient(contact = Recipient.Contact(serviceId = "bad")))
allowedMembers = listOf(Recipient(contact = Recipient.Contact(serviceIdBinary = "bad".toByteArray().toByteString())))
}.build()
val record = SignalNotificationProfileRecord(STORAGE_ID, proto)

View File

@@ -162,6 +162,7 @@ class StorageSyncHelperTest {
private fun contactBuilder(aci: ACI, e164: String, profileName: String): ContactRecord.Builder {
return ContactRecord.Builder()
.aci(aci.toString())
.aciBinary(aci.toByteString())
.e164(e164)
.givenName(profileName)
}