Skip to content

Commit

Permalink
Avoid a few more illegal states
Browse files Browse the repository at this point in the history
  • Loading branch information
sashaweiss-signal authored Sep 18, 2024
1 parent 7eed472 commit 17c5ea9
Show file tree
Hide file tree
Showing 49 changed files with 64 additions and 232 deletions.
14 changes: 10 additions & 4 deletions src/main/kotlin/Permutations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,20 @@ object Generators {
contentTypeGenerator = Generators.list("image/png")
)

fun filePointer(
contentTypeGenerator: Generator<String> = Generators.list("image/jpeg", "image/png", "image/gif", "audio/mp3", "video/mp4")
): Generator<FilePointer> = filePointerInternal(
fun stickerFilePointer(): Generator<FilePointer> = filePointerInternal(
includeFileName = true,
includeMediaSize = true,
includeCaption = false,
includeBlurHash = false,
contentTypeGenerator = Generators.list("image/png", "image/apng", "image/webp")
)

fun bodyAttachmentFilePointer(): Generator<FilePointer> = filePointerInternal(
includeFileName = true,
includeMediaSize = true,
includeCaption = true,
includeBlurHash = true,
contentTypeGenerator = contentTypeGenerator
contentTypeGenerator = Generators.list("image/jpeg", "image/png", "image/gif", "audio/mp3", "video/mp4")
)

private fun filePointerInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object ChatItemStandardMessageStandardAttachmentsTestCase : TestCase("chat_item_
},
attachments = Generators.permutation<MessageAttachment> {
frames += MessageAttachment(
pointer = some(Generators.filePointer()),
pointer = some(Generators.bodyAttachmentFilePointer()),
flag = MessageAttachment.Flag.NONE,
wasDownloaded = someBoolean(),
clientUuid = some(Generators.uuids().nullable())?.toByteArray()?.toByteString()
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/tests/ChatItemStickerMessageTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ object ChatItemStickerMessageTestCase : TestCase("chat_item_sticker_message") {
val incoming = some(incomingGenerator)
val outgoing = some(outgoingGenerator)

val contentTypeGenerator = Generators.list("image/png", "image/apng", "image/webp")

frames += Frame(
chatItem = ChatItem(
chatId = StandardFrames.chatAlice.chat!!.id,
Expand All @@ -46,7 +44,7 @@ object ChatItemStickerMessageTestCase : TestCase("chat_item_sticker_message") {
packKey = someBytes(32).toByteString(),
stickerId = someInt(1, 32),
emoji = someEmoji(),
data_ = some(Generators.filePointer(contentTypeGenerator))
data_ = some(Generators.stickerFilePointer())
),
reactions = some(Generators.reactions(2, StandardFrames.recipientSelf.recipient!!, StandardFrames.recipientAlice.recipient!!))
)
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/tests/RecipientContactsTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import PermutationScope
import TestCase
import nullable
import okio.ByteString.Companion.toByteString
import oneOf
import org.thoughtcrime.securesms.backup.v2.proto.Contact
Expand Down Expand Up @@ -40,8 +41,8 @@ object RecipientContactsTestCase : TestCase("recipient_contacts") {
notRegistered = someOneOf(notRegistered),
profileKey = someNullableBytes(32)?.toByteString(),
profileSharing = someBoolean(),
profileGivenName = someNullableString(),
profileFamilyName = someNullableString(),
profileGivenName = some(Generators.nonEmptyStrings().nullable()),
profileFamilyName = some(Generators.nonEmptyStrings().nullable()),
hideStory = someBoolean()
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/tests/RecipientDistributionListTestCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object RecipientDistributionListTestCase : TestCase("recipient_distribution_list

val myStoryGenerator = Generators.permutation<DistributionList> {
val privacyModeGenerator = Generators.enum(DistributionList.PrivacyMode::class.java, excluding = DistributionList.PrivacyMode.UNKNOWN)
val memberRecipientIdGenerator = Generators.list(memberIds).asList(0, 1, 2, 3)
val memberRecipientIdGenerator = Generators.list(memberIds).asList(1, 2, 3)

val privacyMode = some(privacyModeGenerator)
val memberRecipientIds = some(memberRecipientIdGenerator)
Expand Down Expand Up @@ -62,7 +62,7 @@ object RecipientDistributionListTestCase : TestCase("recipient_distribution_list
val (deletionTimestampGenerator, distributionListGenerator) = oneOf(
Generators.single(someIncrementingTimestamp()),
Generators.permutation {
val memberRecipientIdGenerator = Generators.list(memberIds).asList(0, 1, 2, 3)
val memberRecipientIdGenerator = Generators.list(memberIds).asList(1, 2, 3)

val privacyMode = DistributionList.PrivacyMode.ONLY_WITH
val memberRecipientIds = some(memberRecipientIdGenerator)
Expand Down
Binary file modified test-cases/chat_item_sticker_message_01.binproto
Binary file not shown.
4 changes: 1 addition & 3 deletions test-cases/chat_item_sticker_message_01.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Frame {
Reaction {
authorId = 1
emoji = "💀"
sentTimestamp = 1668034297678
sentTimestamp = 1775172671564
sortOrder = 1
}
]
Expand All @@ -141,8 +141,6 @@ Frame {
size = 1343527527
transitCdnKey = "SkLQGER"
}
blurHash = "LfLh6Voa9NIW?wNF-ooL-;WAX8oy"
caption = ""
contentType = "image/apng"
fileName = "iGqMx"
height = 39
Expand Down
Binary file modified test-cases/chat_item_sticker_message_02.binproto
Binary file not shown.
6 changes: 2 additions & 4 deletions test-cases/chat_item_sticker_message_02.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ Frame {
Reaction {
authorId = 4
emoji = "👍"
sentTimestamp = 1668034297679
sentTimestamp = 1775172671565
sortOrder = 2
},
Reaction {
authorId = 1
emoji = "👎"
sentTimestamp = 1668034297680
sentTimestamp = 1775172671566
}
]
sticker = Sticker {
Expand All @@ -151,8 +151,6 @@ Frame {
transitCdnKey = "wSQuECQWuuuEFC"
transitCdnNumber = 2
}
blurHash = "LGG*f,-i.l-o?G$~?Zt7pHN1=tE3"
caption = "GMNaiqnl"
contentType = "image/webp"
fileName = "pdcKiDzzeAEZOb"
height = 1838
Expand Down
Binary file modified test-cases/chat_item_sticker_message_03.binproto
Binary file not shown.
2 changes: 0 additions & 2 deletions test-cases/chat_item_sticker_message_03.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ Frame {
mediaName = "67fdcb1ac685a8aedbd29cb42e984d65"
size = 1322441015
}
blurHash = "LdIOX?NE9Y4T~pRPRjE1X9f5jrt6"
caption = "bYTMdKV"
contentType = "image/png"
height = 3586
incrementalMac = <bdefd49b44b4c8d19c47cb807844279f>
Expand Down
Binary file modified test-cases/chat_item_sticker_message_04.binproto
Binary file not shown.
5 changes: 2 additions & 3 deletions test-cases/chat_item_sticker_message_04.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Frame {
Reaction {
authorId = 4
emoji = "👍🏾"
sentTimestamp = 1668034297681
sortOrder = 1784708167318
sentTimestamp = 1775172671567
sortOrder = 1890617579856
}
]
sticker = Sticker {
Expand All @@ -144,7 +144,6 @@ Frame {
key = <88cf6bfa88e3f24a21a78511518391fb>
size = 1850075618
}
blurHash = "LJR,66e.~Cxu%LoLM|S2%3WWIosm"
contentType = "image/apng"
fileName = "iGqMx"
}
Expand Down
Binary file modified test-cases/chat_item_sticker_message_05.binproto
Binary file not shown.
8 changes: 3 additions & 5 deletions test-cases/chat_item_sticker_message_05.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ Frame {
Reaction {
authorId = 1
emoji = "👩‍💻"
sentTimestamp = 1668034297682
sortOrder = 1899836917778
sentTimestamp = 1775172671568
sortOrder = 1876547590663
},
Reaction {
authorId = 1
emoji = "💀"
sentTimestamp = 1668034297678
sentTimestamp = 1775172671564
sortOrder = 1
}
]
Expand All @@ -153,8 +153,6 @@ Frame {
size = 464606141
uploadTimestamp = 1664616494583
}
blurHash = "LIM:}RB8?-^L.d4]O.nkK_ruI?od"
caption = ""
contentType = "image/webp"
fileName = "pdcKiDzzeAEZOb"
height = 39
Expand Down
Binary file modified test-cases/chat_item_sticker_message_06.binproto
Binary file not shown.
1 change: 0 additions & 1 deletion test-cases/chat_item_sticker_message_06.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ Frame {
size = 228533420
uploadTimestamp = 1866570650701
}
caption = "GMNaiqnl"
contentType = "image/png"
height = 1838
width = 2923
Expand Down
Binary file modified test-cases/chat_item_sticker_message_07.binproto
Binary file not shown.
4 changes: 1 addition & 3 deletions test-cases/chat_item_sticker_message_07.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,12 @@ Frame {
Reaction {
authorId = 4
emoji = "👍"
sentTimestamp = 1668034297679
sentTimestamp = 1775172671565
sortOrder = 2
}
]
sticker = Sticker {
data_ = FilePointer {
blurHash = "LfLh6Voa9NIW?wNF-ooL-;WAX8oy"
caption = "bYTMdKV"
contentType = "image/apng"
fileName = "iGqMx"
height = 3586
Expand Down
Binary file modified test-cases/chat_item_sticker_message_08.binproto
Binary file not shown.
6 changes: 3 additions & 3 deletions test-cases/chat_item_sticker_message_08.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ Frame {
Reaction {
authorId = 1
emoji = "👎"
sentTimestamp = 1668034297680
sentTimestamp = 1775172671566
},
Reaction {
authorId = 4
emoji = "👍🏾"
sentTimestamp = 1668034297681
sortOrder = 1784708167318
sentTimestamp = 1775172671567
sortOrder = 1890617579856
}
]
sticker = Sticker {
Expand Down
Binary file modified test-cases/chat_item_sticker_message_09.binproto
Binary file not shown.
2 changes: 0 additions & 2 deletions test-cases/chat_item_sticker_message_09.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ Frame {
size = 1343527527
transitCdnKey = "SkLQGER"
}
blurHash = "LfLh6Voa9NIW?wNF-ooL-;WAX8oy"
caption = ""
contentType = "image/apng"
fileName = "iGqMx"
height = 39
Expand Down
Binary file modified test-cases/chat_item_sticker_message_10.binproto
Binary file not shown.
6 changes: 2 additions & 4 deletions test-cases/chat_item_sticker_message_10.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Frame {
Reaction {
authorId = 1
emoji = "👩‍💻"
sentTimestamp = 1668034297682
sortOrder = 1899836917778
sentTimestamp = 1775172671568
sortOrder = 1876547590663
}
]
sticker = Sticker {
Expand All @@ -147,8 +147,6 @@ Frame {
transitCdnKey = "wSQuECQWuuuEFC"
transitCdnNumber = 2
}
blurHash = "LGG*f,-i.l-o?G$~?Zt7pHN1=tE3"
caption = "GMNaiqnl"
contentType = "image/webp"
fileName = "pdcKiDzzeAEZOb"
height = 1838
Expand Down
Binary file modified test-cases/chat_item_sticker_message_11.binproto
Binary file not shown.
6 changes: 2 additions & 4 deletions test-cases/chat_item_sticker_message_11.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ Frame {
Reaction {
authorId = 1
emoji = "💀"
sentTimestamp = 1668034297678
sentTimestamp = 1775172671564
sortOrder = 1
},
Reaction {
authorId = 4
emoji = "👍"
sentTimestamp = 1668034297679
sentTimestamp = 1775172671565
sortOrder = 2
}
]
Expand All @@ -149,8 +149,6 @@ Frame {
mediaName = "67fdcb1ac685a8aedbd29cb42e984d65"
size = 1322441015
}
blurHash = "LdIOX?NE9Y4T~pRPRjE1X9f5jrt6"
caption = "bYTMdKV"
contentType = "image/png"
height = 3586
incrementalMac = <bdefd49b44b4c8d19c47cb807844279f>
Expand Down
Binary file modified test-cases/chat_item_sticker_message_12.binproto
Binary file not shown.
1 change: 0 additions & 1 deletion test-cases/chat_item_sticker_message_12.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ Frame {
key = <88cf6bfa88e3f24a21a78511518391fb>
size = 1850075618
}
blurHash = "LJR,66e.~Cxu%LoLM|S2%3WWIosm"
contentType = "image/apng"
fileName = "iGqMx"
}
Expand Down
Binary file modified test-cases/chat_item_sticker_message_13.binproto
Binary file not shown.
4 changes: 1 addition & 3 deletions test-cases/chat_item_sticker_message_13.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Frame {
Reaction {
authorId = 1
emoji = "👎"
sentTimestamp = 1668034297680
sentTimestamp = 1775172671566
}
]
sticker = Sticker {
Expand All @@ -147,8 +147,6 @@ Frame {
size = 464606141
uploadTimestamp = 1664616494583
}
blurHash = "LIM:}RB8?-^L.d4]O.nkK_ruI?od"
caption = ""
contentType = "image/webp"
fileName = "pdcKiDzzeAEZOb"
height = 39
Expand Down
Binary file modified test-cases/chat_item_sticker_message_14.binproto
Binary file not shown.
9 changes: 4 additions & 5 deletions test-cases/chat_item_sticker_message_14.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ Frame {
Reaction {
authorId = 4
emoji = "👍🏾"
sentTimestamp = 1668034297681
sortOrder = 1784708167318
sentTimestamp = 1775172671567
sortOrder = 1890617579856
},
Reaction {
authorId = 1
emoji = "👩‍💻"
sentTimestamp = 1668034297682
sortOrder = 1899836917778
sentTimestamp = 1775172671568
sortOrder = 1876547590663
}
]
sticker = Sticker {
Expand All @@ -153,7 +153,6 @@ Frame {
size = 228533420
uploadTimestamp = 1866570650701
}
caption = "GMNaiqnl"
contentType = "image/png"
height = 1838
width = 2923
Expand Down
Binary file modified test-cases/recipient_contacts_01.binproto
Binary file not shown.
4 changes: 2 additions & 2 deletions test-cases/recipient_contacts_01.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ Frame {
e164 = 33639987949
notRegistered = NotRegistered {}
pni = <f2c8f6640c624f2f806929719cb0c468>
profileFamilyName = ""
profileGivenName = ""
profileFamilyName = "CQWuu"
profileGivenName = "pIJqySkLQ"
profileKey = <149f599dab4f9c8a0a0f6193b4fffb255879953e257ab94747b56ae57f372e1b>
username = "zGYSDTsXBkoGHk.3420"
visibility = Visibility.HIDDEN
Expand Down
Binary file modified test-cases/recipient_contacts_02.binproto
Binary file not shown.
4 changes: 2 additions & 2 deletions test-cases/recipient_contacts_02.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ Frame {
unregisteredTimestamp = 1833527071192
}
pni = <f2c8f6640c624f2f806929719cb0c468>
profileFamilyName = "CQWuu"
profileGivenName = "pIJqySkLQ"
profileFamilyName = "EFCmCqQNEWGrA"
profileGivenName = "ERtwSQu"
profileSharing = true
username = "nzNFkpZzmNnJ.3791"
visibility = Visibility.HIDDEN_MESSAGE_REQUEST
Expand Down
Binary file modified test-cases/recipient_contacts_03.binproto
Binary file not shown.
2 changes: 0 additions & 2 deletions test-cases/recipient_contacts_03.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ Frame {
unregisteredTimestamp = 1695248715439
}
pni = <f2c8f6640c624f2f806929719cb0c468>
profileFamilyName = "EFCmCqQNEWGrA"
profileGivenName = "ERtwSQu"
profileKey = <149f599dab4f9c8a0a0f6193b4fffb255879953e257ab94747b56ae57f372e1b>
username = "avlHxOeTt.05"
visibility = Visibility.VISIBLE
Expand Down
Binary file modified test-cases/recipient_distribution_list_00.binproto
Binary file not shown.
7 changes: 5 additions & 2 deletions test-cases/recipient_distribution_list_00.txtproto
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ Frame {
distributionId = <00000000000000000000000000000000>
distributionList = DistributionList {
allowReplies = true
memberRecipientIds = [
4
]
name = "EtjaXtfWb"
privacyMode = PrivacyMode.ONLY_WITH
}
Expand All @@ -141,8 +144,8 @@ Frame {
Frame {
recipient = Recipient {
distributionList = DistributionListItem {
deletionTimestamp = 1828988507550
distributionId = <4918c8d4170946868d1955d4fa82c95b>
deletionTimestamp = 1727080952861
distributionId = <cde0c16d35df40188aa8ddd222a3fe4f>
}
id = 8
}
Expand Down
Binary file modified test-cases/recipient_distribution_list_01.binproto
Binary file not shown.
Loading

0 comments on commit 17c5ea9

Please sign in to comment.