mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 19:56:02 +01:00
Convert StorageService protos to wire.
This commit is contained in:
committed by
Greyson Parrelli
parent
9a7d8c858d
commit
6a21106347
@@ -55,11 +55,13 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
setE164(E164_B)
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
pni = PNI_B.toStringWithoutPrefix(),
|
||||
e164 = E164_B
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -73,9 +75,11 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setE164(E164_B)
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
e164 = E164_B
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -89,11 +93,13 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI.UNKNOWN.toString())
|
||||
setPni(PNI.UNKNOWN.toString())
|
||||
setE164(E164_B)
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI.UNKNOWN.toString(),
|
||||
pni = PNI.UNKNOWN.toString(),
|
||||
e164 = E164_B
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -107,10 +113,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setE164(E164_A)
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
e164 = E164_A
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -124,9 +132,11 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_A.toString())
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString()
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -140,10 +150,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
pni = PNI_A.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -157,10 +169,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setE164(E164_B)
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
e164 = E164_B
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -174,10 +188,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setE164("15551234567")
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
e164 = "15551234567"
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -191,10 +207,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+1555ABC4567")
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
e164 = "+1555ABC4567"
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -208,10 +226,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+")
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
e164 = "+"
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -225,10 +245,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+12345678901234567890")
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
e164 = "+12345678901234567890"
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -242,10 +264,12 @@ class ContactRecordProcessorTest {
|
||||
// GIVEN
|
||||
val subject = ContactRecordProcessor(ACI_A, PNI_A, E164_A, recipientTable)
|
||||
|
||||
val record = buildRecord {
|
||||
setAci(ACI_B.toString())
|
||||
setE164("+05551234567")
|
||||
}
|
||||
val record = buildRecord(
|
||||
record = ContactRecord(
|
||||
aci = ACI_B.toString(),
|
||||
e164 = "+05551234567"
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.isInvalid(record)
|
||||
@@ -261,17 +285,23 @@ class ContactRecordProcessorTest {
|
||||
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(true)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
val local = buildRecord(
|
||||
STORAGE_ID_A,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_A,
|
||||
pni = PNI_A.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
}
|
||||
val remote = buildRecord(
|
||||
STORAGE_ID_B,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_A,
|
||||
pni = PNI_B.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
@@ -289,17 +319,23 @@ class ContactRecordProcessorTest {
|
||||
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(true)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
val local = buildRecord(
|
||||
STORAGE_ID_A,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_A,
|
||||
pni = PNI_A.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
val remote = buildRecord(
|
||||
STORAGE_ID_B,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_B,
|
||||
pni = PNI_A.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
@@ -317,17 +353,23 @@ class ContactRecordProcessorTest {
|
||||
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(true)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
val local = buildRecord(
|
||||
STORAGE_ID_A,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_A,
|
||||
pni = PNI_A.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
}
|
||||
val remote = buildRecord(
|
||||
STORAGE_ID_B,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_B,
|
||||
pni = PNI_B.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
@@ -345,17 +387,23 @@ class ContactRecordProcessorTest {
|
||||
|
||||
featureFlags.`when`<Boolean> { FeatureFlags.phoneNumberPrivacy() }.thenReturn(false)
|
||||
|
||||
val local = buildRecord(STORAGE_ID_A) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_A)
|
||||
setPni(PNI_A.toStringWithoutPrefix())
|
||||
}
|
||||
val local = buildRecord(
|
||||
STORAGE_ID_A,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_A,
|
||||
pni = PNI_A.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
val remote = buildRecord(STORAGE_ID_B) {
|
||||
setAci(ACI_A.toString())
|
||||
setE164(E164_B)
|
||||
setPni(PNI_B.toStringWithoutPrefix())
|
||||
}
|
||||
val remote = buildRecord(
|
||||
STORAGE_ID_B,
|
||||
record = ContactRecord(
|
||||
aci = ACI_A.toString(),
|
||||
e164 = E164_B,
|
||||
pni = PNI_B.toStringWithoutPrefix()
|
||||
)
|
||||
)
|
||||
|
||||
// WHEN
|
||||
val result = subject.merge(remote, local, TestKeyGenerator(STORAGE_ID_C))
|
||||
@@ -366,8 +414,8 @@ class ContactRecordProcessorTest {
|
||||
assertEquals(false, result.pni.isPresent)
|
||||
}
|
||||
|
||||
private fun buildRecord(id: StorageId = STORAGE_ID_A, applyParams: ContactRecord.Builder.() -> ContactRecord.Builder): SignalContactRecord {
|
||||
return SignalContactRecord(id, ContactRecord.getDefaultInstance().toBuilder().applyParams().build())
|
||||
private fun buildRecord(id: StorageId = STORAGE_ID_A, record: ContactRecord): SignalContactRecord {
|
||||
return SignalContactRecord(id, record)
|
||||
}
|
||||
|
||||
private class TestKeyGenerator(private val value: StorageId) : StorageKeyGenerator {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.thoughtcrime.securesms.storage
|
||||
|
||||
import com.google.protobuf.ByteString
|
||||
import okio.ByteString
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.BeforeClass
|
||||
@@ -31,7 +31,7 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto without an identifier, when I isInvalid, then I expect true`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord.getDefaultInstance()
|
||||
val proto = StoryDistributionListRecord()
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
|
||||
// WHEN
|
||||
@@ -44,10 +44,9 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto with an identifier that is not a UUID, when I isInvalid, then I expect true`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(ByteString.copyFrom("Greetings, fellow UUIDs".encodeToByteArray()))
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*"Greetings, fellow UUIDs".encodeToByteArray()))
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
@@ -62,10 +61,9 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto without a name or deletion timestamp, when I isInvalid, then I expect true`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(UuidUtil.toByteString(UUID.randomUUID()))
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*UuidUtil.toByteArray(UUID.randomUUID())))
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
@@ -80,11 +78,10 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto with a deletion timestamp, when I isInvalid, then I expect false`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(UuidUtil.toByteString(UUID.randomUUID()))
|
||||
.setDeletedAtTimestamp(1)
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*UuidUtil.toByteArray(UUID.randomUUID())))
|
||||
.deletedAtTimestamp(1)
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
@@ -99,11 +96,10 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto that is MyStory with a deletion timestamp, when I isInvalid, then I expect true`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(UuidUtil.toByteString(DistributionId.MY_STORY.asUuid()))
|
||||
.setDeletedAtTimestamp(1)
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*UuidUtil.toByteArray(DistributionId.MY_STORY.asUuid())))
|
||||
.deletedAtTimestamp(1)
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
@@ -118,11 +114,10 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a validated proto that is MyStory, when I isInvalid with another MyStory, then I expect true`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(UuidUtil.toByteString(DistributionId.MY_STORY.asUuid()))
|
||||
.setDeletedAtTimestamp(1)
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*UuidUtil.toByteArray(DistributionId.MY_STORY.asUuid())))
|
||||
.deletedAtTimestamp(1)
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
@@ -138,11 +133,10 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto with a visible name, when I isInvalid, then I expect false`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(UuidUtil.toByteString(UUID.randomUUID()))
|
||||
.setName("A visible name")
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*UuidUtil.toByteArray(UUID.randomUUID())))
|
||||
.name("A visible name")
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
@@ -157,10 +151,9 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto without a name, when I isInvalid, then I expect false`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(UuidUtil.toByteString(UUID.randomUUID()))
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*UuidUtil.toByteArray(UUID.randomUUID())))
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
@@ -175,11 +168,10 @@ class StoryDistributionListRecordProcessorTest {
|
||||
@Test
|
||||
fun `Given a proto without a visible name, when I isInvalid, then I expect true`() {
|
||||
// GIVEN
|
||||
val proto = StoryDistributionListRecord
|
||||
.getDefaultInstance()
|
||||
.toBuilder()
|
||||
.setIdentifier(UuidUtil.toByteString(UUID.randomUUID()))
|
||||
.setName(" ")
|
||||
val proto = StoryDistributionListRecord()
|
||||
.newBuilder()
|
||||
.identifier(ByteString.of(*UuidUtil.toByteArray(UUID.randomUUID())))
|
||||
.name(" ")
|
||||
.build()
|
||||
|
||||
val record = SignalStoryDistributionListRecord(STORAGE_ID, proto)
|
||||
|
||||
Reference in New Issue
Block a user