mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-02 16:23:20 +01:00
Use protopiler for protocol buffers
Co-authored-by: Jamie Kyle <jamie@signal.org>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import Long from 'long';
|
||||
import { v4 as generateUuid } from 'uuid';
|
||||
|
||||
import {
|
||||
@@ -23,9 +22,40 @@ const FLAGS = Proto.DataMessage.Flags;
|
||||
const TIMESTAMP = Date.now();
|
||||
const CLIENT_UUID = generateUuid();
|
||||
|
||||
const UNPROCESSED_ATTACHMENT: Proto.IAttachmentPointer = {
|
||||
cdnId: Long.fromNumber(123),
|
||||
cdnKey: 'cdnKey',
|
||||
const EMPTY_DATA_MESSAGE: Proto.DataMessage.Params = {
|
||||
body: null,
|
||||
attachments: null,
|
||||
groupV2: null,
|
||||
flags: null,
|
||||
expireTimer: null,
|
||||
expireTimerVersion: null,
|
||||
profileKey: null,
|
||||
timestamp: null,
|
||||
quote: null,
|
||||
contact: null,
|
||||
preview: null,
|
||||
sticker: null,
|
||||
requiredProtocolVersion: null,
|
||||
isViewOnce: null,
|
||||
reaction: null,
|
||||
delete: null,
|
||||
bodyRanges: null,
|
||||
groupCallUpdate: null,
|
||||
payment: null,
|
||||
storyContext: null,
|
||||
giftBadge: null,
|
||||
pollCreate: null,
|
||||
pollTerminate: null,
|
||||
pollVote: null,
|
||||
pinMessage: null,
|
||||
unpinMessage: null,
|
||||
adminDelete: null,
|
||||
};
|
||||
|
||||
const UNPROCESSED_ATTACHMENT: Proto.AttachmentPointer.Params = {
|
||||
attachmentIdentifier: {
|
||||
cdnKey: 'cdnKey',
|
||||
},
|
||||
cdnNumber: 2,
|
||||
blurHash: 'blurHash',
|
||||
caption: 'caption',
|
||||
@@ -35,16 +65,17 @@ const UNPROCESSED_ATTACHMENT: Proto.IAttachmentPointer = {
|
||||
contentType: IMAGE_GIF,
|
||||
incrementalMac: new Uint8Array([12, 12, 12]),
|
||||
chunkSize: 24,
|
||||
uploadTimestamp: Long.fromNumber(456),
|
||||
uploadTimestamp: 456n,
|
||||
size: 34,
|
||||
height: 64,
|
||||
width: 128,
|
||||
flags: 1,
|
||||
fileName: 'fileName',
|
||||
thumbnail: null,
|
||||
};
|
||||
|
||||
const PROCESSED_ATTACHMENT: ProcessedAttachment = {
|
||||
cdnId: '123',
|
||||
cdnId: undefined,
|
||||
cdnKey: 'cdnKey',
|
||||
cdnNumber: 2,
|
||||
blurHash: 'blurHash',
|
||||
@@ -64,12 +95,17 @@ const PROCESSED_ATTACHMENT: ProcessedAttachment = {
|
||||
};
|
||||
|
||||
describe('processDataMessage', () => {
|
||||
const check = (message: Proto.IDataMessage) =>
|
||||
const check = (
|
||||
message: Partial<Omit<Proto.DataMessage.Params, 'timestamp'>>
|
||||
) =>
|
||||
processDataMessage(
|
||||
{
|
||||
timestamp: Long.fromNumber(TIMESTAMP),
|
||||
...message,
|
||||
},
|
||||
Proto.DataMessage.decode(
|
||||
Proto.DataMessage.encode({
|
||||
...EMPTY_DATA_MESSAGE,
|
||||
timestamp: BigInt(TIMESTAMP),
|
||||
...message,
|
||||
})
|
||||
),
|
||||
TIMESTAMP,
|
||||
{
|
||||
_createName: () => 'random-path',
|
||||
@@ -94,7 +130,9 @@ describe('processDataMessage', () => {
|
||||
attachments: [
|
||||
{
|
||||
...UNPROCESSED_ATTACHMENT,
|
||||
cdnId: new Long(0),
|
||||
attachmentIdentifier: {
|
||||
cdnId: 0n,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -103,6 +141,7 @@ describe('processDataMessage', () => {
|
||||
{
|
||||
...PROCESSED_ATTACHMENT,
|
||||
cdnId: undefined,
|
||||
cdnKey: undefined,
|
||||
downloadPath: 'random-path',
|
||||
},
|
||||
]);
|
||||
@@ -154,7 +193,7 @@ describe('processDataMessage', () => {
|
||||
});
|
||||
|
||||
it('should throw on too many attachments', () => {
|
||||
const attachments: Array<Proto.IAttachmentPointer> = [];
|
||||
const attachments: Array<Proto.AttachmentPointer.Params> = [];
|
||||
for (let i = 0; i < ATTACHMENT_MAX + 1; i += 1) {
|
||||
attachments.push(UNPROCESSED_ATTACHMENT);
|
||||
}
|
||||
@@ -206,9 +245,12 @@ describe('processDataMessage', () => {
|
||||
it('should process quote, dropping second attachment', () => {
|
||||
const out = check({
|
||||
quote: {
|
||||
id: Long.fromNumber(1),
|
||||
id: 1n,
|
||||
authorAci: null,
|
||||
authorAciBinary: ACI_BINARY_1,
|
||||
text: 'text',
|
||||
bodyRanges: null,
|
||||
type: null,
|
||||
attachments: [
|
||||
{
|
||||
contentType: 'image/jpeg',
|
||||
@@ -235,20 +277,31 @@ describe('processDataMessage', () => {
|
||||
thumbnail: PROCESSED_ATTACHMENT,
|
||||
},
|
||||
],
|
||||
bodyRanges: undefined,
|
||||
bodyRanges: [],
|
||||
type: 0,
|
||||
});
|
||||
});
|
||||
|
||||
it('should process contact, dropping second contact', () => {
|
||||
const EMPTY_CONTACT = {
|
||||
$unknown: [],
|
||||
number: [],
|
||||
name: null,
|
||||
email: [],
|
||||
address: [],
|
||||
organization: '',
|
||||
};
|
||||
const out = check({
|
||||
contact: [
|
||||
{
|
||||
...EMPTY_CONTACT,
|
||||
avatar: {
|
||||
avatar: UNPROCESSED_ATTACHMENT,
|
||||
isProfile: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
...EMPTY_CONTACT,
|
||||
avatar: {
|
||||
avatar: UNPROCESSED_ATTACHMENT,
|
||||
isProfile: true,
|
||||
@@ -259,7 +312,11 @@ describe('processDataMessage', () => {
|
||||
|
||||
assert.deepStrictEqual(out.contact, [
|
||||
{
|
||||
avatar: { avatar: PROCESSED_ATTACHMENT, isProfile: false },
|
||||
...EMPTY_CONTACT,
|
||||
avatar: {
|
||||
avatar: PROCESSED_ATTACHMENT,
|
||||
isProfile: false,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -273,12 +330,14 @@ describe('processDataMessage', () => {
|
||||
image: UNPROCESSED_ATTACHMENT,
|
||||
title: 'Signal Private Messenger #1',
|
||||
url: 'https://signal.org',
|
||||
date: null,
|
||||
},
|
||||
{
|
||||
description: 'Say "hello" again',
|
||||
image: UNPROCESSED_ATTACHMENT,
|
||||
title: 'Signal Private Messenger #2',
|
||||
url: 'https://signal.org',
|
||||
date: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -300,8 +359,10 @@ describe('processDataMessage', () => {
|
||||
check({
|
||||
reaction: {
|
||||
emoji: '😎',
|
||||
remove: null,
|
||||
targetAuthorAci: null,
|
||||
targetAuthorAciBinary: ACI_BINARY_1,
|
||||
targetSentTimestamp: Long.fromNumber(TIMESTAMP),
|
||||
targetSentTimestamp: BigInt(TIMESTAMP),
|
||||
},
|
||||
}).reaction,
|
||||
{
|
||||
@@ -317,8 +378,9 @@ describe('processDataMessage', () => {
|
||||
reaction: {
|
||||
emoji: '😎',
|
||||
remove: true,
|
||||
targetAuthorAci: null,
|
||||
targetAuthorAciBinary: ACI_BINARY_1,
|
||||
targetSentTimestamp: Long.fromNumber(TIMESTAMP),
|
||||
targetSentTimestamp: BigInt(TIMESTAMP),
|
||||
},
|
||||
}).reaction,
|
||||
{
|
||||
@@ -334,8 +396,11 @@ describe('processDataMessage', () => {
|
||||
const out = check({
|
||||
preview: [
|
||||
{
|
||||
date: Long.fromNumber(TIMESTAMP),
|
||||
date: BigInt(TIMESTAMP),
|
||||
image: UNPROCESSED_ATTACHMENT,
|
||||
url: null,
|
||||
title: null,
|
||||
description: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -343,9 +408,9 @@ describe('processDataMessage', () => {
|
||||
assert.deepStrictEqual(out.preview, [
|
||||
{
|
||||
date: TIMESTAMP,
|
||||
description: undefined,
|
||||
title: undefined,
|
||||
url: undefined,
|
||||
description: '',
|
||||
title: '',
|
||||
url: '',
|
||||
image: PROCESSED_ATTACHMENT,
|
||||
},
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user