From 9fd929e8129bbd69e278ee9099985e20e0288206 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 29 May 2020 15:44:18 +1000 Subject: [PATCH] lint --- ts/session/messages/outgoing/Message.ts | 1 - .../messages/outgoing/OpenGroupMessage.ts | 14 +- .../outgoing/content/ContentMessage.ts | 3 +- .../outgoing/content/EndSessionMessage.ts | 1 - .../content/SessionEstablishedMessage.ts | 1 - .../outgoing/content/SessionResetMessage.ts | 2 - .../outgoing/content/TypingMessage.ts | 3 +- .../outgoing/content/data/ChatMessage.ts | 37 ++-- .../content/data/ClosedGroupChatMessage.ts | 2 +- .../outgoing/content/data/DataMessage.ts | 1 - .../content/data/DeviceUnlinkMessage.ts | 1 - .../content/link/DeviceLinkGrantMessage.ts | 8 +- .../content/link/DeviceLinkRequestMessage.ts | 4 +- .../messages/outgoing/content/link/index.ts | 1 - .../content/receipt/ReadReceiptMessage.ts | 1 - .../content/receipt/ReceiptMessage.ts | 6 +- .../outgoing/content/receipt/index.ts | 2 - .../outgoing/content/sync/SyncMessage.ts | 1 - .../messages/outgoing/content/sync/index.ts | 5 +- ts/session/messages/outgoing/index.ts | 5 +- .../messages/ClosedGroupChatMessage_test.ts | 86 ++++---- .../messages/DeviceLinkMessage_test.ts | 191 +++++++++++------- .../messages/DeviceUnlinkMessage_test.ts | 42 ++-- .../messages/EndSessionMessage_test.ts | 116 ++++++----- .../SessionEstablishedMessage_test.ts | 42 ++-- ts/types/Message.ts | 1 - 26 files changed, 319 insertions(+), 258 deletions(-) diff --git a/ts/session/messages/outgoing/Message.ts b/ts/session/messages/outgoing/Message.ts index b432cac94..382d5ff7c 100644 --- a/ts/session/messages/outgoing/Message.ts +++ b/ts/session/messages/outgoing/Message.ts @@ -9,7 +9,6 @@ export abstract class Message { public readonly timestamp: number; public readonly identifier: string; - constructor({ timestamp, identifier }: MessageParams) { this.timestamp = timestamp; if (identifier && identifier.length === 0) { diff --git a/ts/session/messages/outgoing/OpenGroupMessage.ts b/ts/session/messages/outgoing/OpenGroupMessage.ts index b23486045..11d3b9750 100644 --- a/ts/session/messages/outgoing/OpenGroupMessage.ts +++ b/ts/session/messages/outgoing/OpenGroupMessage.ts @@ -16,13 +16,13 @@ export class OpenGroupMessage extends Message { public readonly quote?: QuotedAttachmentType; constructor({ - timestamp, - server, - attachments, - body, - quote, - identifier, - } : OpenGroupMessageParams) { + timestamp, + server, + attachments, + body, + quote, + identifier, + }: OpenGroupMessageParams) { super({ timestamp, identifier }); this.server = server; this.body = body; diff --git a/ts/session/messages/outgoing/content/ContentMessage.ts b/ts/session/messages/outgoing/content/ContentMessage.ts index 57b9f9f5d..5eab1bc3e 100644 --- a/ts/session/messages/outgoing/content/ContentMessage.ts +++ b/ts/session/messages/outgoing/content/ContentMessage.ts @@ -2,7 +2,6 @@ import { Message } from '../Message'; import { SignalService } from '../../../../protobuf'; export abstract class ContentMessage extends Message { - public plainTextBuffer(): Uint8Array { return SignalService.Content.encode(this.contentProto()).finish(); } @@ -16,6 +15,6 @@ export abstract class ContentMessage extends Message { */ protected getDefaultTTL(): number { // 1 day default for any other message - return 24 * 60 * 60 * 1000; + return 24 * 60 * 60 * 1000; } } diff --git a/ts/session/messages/outgoing/content/EndSessionMessage.ts b/ts/session/messages/outgoing/content/EndSessionMessage.ts index e7092413c..f19b111dd 100644 --- a/ts/session/messages/outgoing/content/EndSessionMessage.ts +++ b/ts/session/messages/outgoing/content/EndSessionMessage.ts @@ -2,7 +2,6 @@ import { SessionResetMessage } from './SessionResetMessage'; import { SignalService } from '../../../../protobuf'; export class EndSessionMessage extends SessionResetMessage { - public ttl(): number { return 4 * 24 * 60 * 60 * 1000; // 4 days } diff --git a/ts/session/messages/outgoing/content/SessionEstablishedMessage.ts b/ts/session/messages/outgoing/content/SessionEstablishedMessage.ts index fd8d4526f..aa95082a7 100644 --- a/ts/session/messages/outgoing/content/SessionEstablishedMessage.ts +++ b/ts/session/messages/outgoing/content/SessionEstablishedMessage.ts @@ -2,7 +2,6 @@ import { ContentMessage } from './ContentMessage'; import { SignalService } from '../../../../protobuf'; export class SessionEstablishedMessage extends ContentMessage { - public ttl(): number { return 5 * 60 * 1000; } diff --git a/ts/session/messages/outgoing/content/SessionResetMessage.ts b/ts/session/messages/outgoing/content/SessionResetMessage.ts index d5b83ee4c..b4fb8ebb0 100644 --- a/ts/session/messages/outgoing/content/SessionResetMessage.ts +++ b/ts/session/messages/outgoing/content/SessionResetMessage.ts @@ -2,7 +2,6 @@ import { ContentMessage } from './ContentMessage'; import { SignalService } from '../../../../protobuf'; import { MessageParams } from '../Message'; - export interface PreKeyBundleType { identityKey: Uint8Array; deviceId: number; @@ -13,7 +12,6 @@ export interface PreKeyBundleType { signature: Uint8Array; } - interface SessionResetParams extends MessageParams { preKeyBundle: PreKeyBundleType; } diff --git a/ts/session/messages/outgoing/content/TypingMessage.ts b/ts/session/messages/outgoing/content/TypingMessage.ts index c9da65401..4de716b06 100644 --- a/ts/session/messages/outgoing/content/TypingMessage.ts +++ b/ts/session/messages/outgoing/content/TypingMessage.ts @@ -15,13 +15,12 @@ export class TypingMessage extends ContentMessage { private readonly groupId?: string; constructor(params: TypingMessageParams) { - super({timestamp: params.timestamp, identifier: params.identifier}); + super({ timestamp: params.timestamp, identifier: params.identifier }); this.isTyping = params.isTyping; this.typingTimestamp = params.typingTimestamp; this.groupId = params.groupId; } - public ttl(): number { return 60 * 1000; // 1 minute for typing indicators } diff --git a/ts/session/messages/outgoing/content/data/ChatMessage.ts b/ts/session/messages/outgoing/content/data/ChatMessage.ts index d75105903..d77b31a7b 100644 --- a/ts/session/messages/outgoing/content/data/ChatMessage.ts +++ b/ts/session/messages/outgoing/content/data/ChatMessage.ts @@ -19,9 +19,9 @@ export interface AttachmentPointer { } export interface Preview { - url?: string; - title?: string; - image?: AttachmentPointer; + url?: string; + title?: string; + image?: AttachmentPointer; } export interface QuotedAttachment { @@ -46,7 +46,6 @@ export interface ChatMessageParams extends MessageParams { preview?: Array; } - export class ChatMessage extends DataMessage { private readonly attachments?: Array; private readonly body?: string; @@ -82,7 +81,6 @@ export class ChatMessage extends DataMessage { dataMessage.attachments = this.attachments || []; - if (this.expireTimer) { dataMessage.expireTimer = this.expireTimer; } @@ -118,20 +116,22 @@ export class ChatMessage extends DataMessage { dataMessage.quote.author = this.quote.author; dataMessage.quote.text = this.quote.text; if (this.quote.attachments) { - dataMessage.quote.attachments = this.quote.attachments.map((attachment: QuotedAttachment) => { - const quotedAttachment = new SignalService.DataMessage.Quote.QuotedAttachment(); - if (attachment.contentType) { - quotedAttachment.contentType = attachment.contentType; - } - if (attachment.fileName) { - quotedAttachment.fileName = attachment.fileName; + dataMessage.quote.attachments = this.quote.attachments.map( + (attachment: QuotedAttachment) => { + const quotedAttachment = new SignalService.DataMessage.Quote.QuotedAttachment(); + if (attachment.contentType) { + quotedAttachment.contentType = attachment.contentType; + } + if (attachment.fileName) { + quotedAttachment.fileName = attachment.fileName; + } + if (attachment.thumbnail) { + quotedAttachment.thumbnail = attachment.thumbnail; + } + + return quotedAttachment; } - if (attachment.thumbnail) { - quotedAttachment.thumbnail = attachment.thumbnail; - } - - return quotedAttachment; - }); + ); } } @@ -150,7 +150,6 @@ export class ChatMessage extends DataMessage { }); } - return dataMessage; } } diff --git a/ts/session/messages/outgoing/content/data/ClosedGroupChatMessage.ts b/ts/session/messages/outgoing/content/data/ClosedGroupChatMessage.ts index 0d8ff5eeb..b9acf4bc8 100644 --- a/ts/session/messages/outgoing/content/data/ClosedGroupChatMessage.ts +++ b/ts/session/messages/outgoing/content/data/ClosedGroupChatMessage.ts @@ -30,7 +30,7 @@ export class ClosedGroupChatMessage extends DataMessage { const messageProto = this.chatMessage.dataProto(); const id = new TextEncoder().encode(this.groupId); const type = SignalService.GroupContext.Type.DELIVER; - messageProto.group = new SignalService.GroupContext({id, type}); + messageProto.group = new SignalService.GroupContext({ id, type }); return messageProto; } diff --git a/ts/session/messages/outgoing/content/data/DataMessage.ts b/ts/session/messages/outgoing/content/data/DataMessage.ts index 03582177d..869a3b736 100644 --- a/ts/session/messages/outgoing/content/data/DataMessage.ts +++ b/ts/session/messages/outgoing/content/data/DataMessage.ts @@ -2,7 +2,6 @@ import { ContentMessage } from '../ContentMessage'; import { SignalService } from '../../../../../protobuf'; export abstract class DataMessage extends ContentMessage { - protected contentProto(): SignalService.Content { return new SignalService.Content({ dataMessage: this.dataProto(), diff --git a/ts/session/messages/outgoing/content/data/DeviceUnlinkMessage.ts b/ts/session/messages/outgoing/content/data/DeviceUnlinkMessage.ts index 9f45728a2..b08764e07 100644 --- a/ts/session/messages/outgoing/content/data/DeviceUnlinkMessage.ts +++ b/ts/session/messages/outgoing/content/data/DeviceUnlinkMessage.ts @@ -2,7 +2,6 @@ import { DataMessage } from './DataMessage'; import { SignalService } from '../../../../../protobuf'; export class DeviceUnlinkMessage extends DataMessage { - public ttl(): number { return 4 * 24 * 60 * 60 * 1000; // 4 days for device unlinking } diff --git a/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts b/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts index 78a936e59..7e608b8d5 100644 --- a/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts +++ b/ts/session/messages/outgoing/content/link/DeviceLinkGrantMessage.ts @@ -1,5 +1,8 @@ import { SignalService } from '../../../../../protobuf'; -import { DeviceLinkMessageParams, DeviceLinkRequestMessage } from './DeviceLinkRequestMessage'; +import { + DeviceLinkMessageParams, + DeviceLinkRequestMessage, +} from './DeviceLinkRequestMessage'; import { LokiProfile } from '../../../../../types/Message'; interface DeviceLinkGrantMessageParams extends DeviceLinkMessageParams { @@ -13,8 +16,7 @@ export class DeviceLinkGrantMessage extends DeviceLinkRequestMessage { private readonly profileKey: Uint8Array; private readonly grantSignature: Uint8Array; - constructor(params: DeviceLinkGrantMessageParams - ) { + constructor(params: DeviceLinkGrantMessageParams) { super({ timestamp: params.timestamp, identifier: params.identifier, diff --git a/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts b/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts index 3c9c43d5d..a2c33e8ab 100644 --- a/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts +++ b/ts/session/messages/outgoing/content/link/DeviceLinkRequestMessage.ts @@ -1,13 +1,12 @@ import { ContentMessage } from '../ContentMessage'; import { SignalService } from '../../../../../protobuf'; import { MessageParams } from '../../Message'; -export interface DeviceLinkMessageParams extends MessageParams{ +export interface DeviceLinkMessageParams extends MessageParams { primaryDevicePubKey: string; secondaryDevicePubKey: string; requestSignature: Uint8Array; } - export class DeviceLinkRequestMessage extends ContentMessage { protected readonly primaryDevicePubKey: string; protected readonly secondaryDevicePubKey: string; @@ -44,4 +43,3 @@ export class DeviceLinkRequestMessage extends ContentMessage { }); } } - diff --git a/ts/session/messages/outgoing/content/link/index.ts b/ts/session/messages/outgoing/content/link/index.ts index 69a9fe9bc..d0a7f9317 100644 --- a/ts/session/messages/outgoing/content/link/index.ts +++ b/ts/session/messages/outgoing/content/link/index.ts @@ -1,3 +1,2 @@ export * from './DeviceLinkGrantMessage'; export * from './DeviceLinkRequestMessage'; - diff --git a/ts/session/messages/outgoing/content/receipt/ReadReceiptMessage.ts b/ts/session/messages/outgoing/content/receipt/ReadReceiptMessage.ts index f7e1895cf..511a66117 100644 --- a/ts/session/messages/outgoing/content/receipt/ReadReceiptMessage.ts +++ b/ts/session/messages/outgoing/content/receipt/ReadReceiptMessage.ts @@ -2,7 +2,6 @@ import { SignalService } from '../../../../../protobuf'; import { ReceiptMessage } from './ReceiptMessage'; export class ReadReceiptMessage extends ReceiptMessage { - public getReceiptType(): SignalService.ReceiptMessage.Type { return SignalService.ReceiptMessage.Type.READ; } diff --git a/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts b/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts index 9e00042e9..e6f7b34ab 100644 --- a/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts +++ b/ts/session/messages/outgoing/content/receipt/ReceiptMessage.ts @@ -8,9 +8,8 @@ interface ReceiptMessageParams extends MessageParams { export abstract class ReceiptMessage extends ContentMessage { private readonly timestamps: Array; - constructor({ timestamp, identifier, timestamps }: - ReceiptMessageParams) { - super({timestamp, identifier}); + constructor({ timestamp, identifier, timestamps }: ReceiptMessageParams) { + super({ timestamp, identifier }); this.timestamps = timestamps; } @@ -33,4 +32,3 @@ export abstract class ReceiptMessage extends ContentMessage { }); } } - diff --git a/ts/session/messages/outgoing/content/receipt/index.ts b/ts/session/messages/outgoing/content/receipt/index.ts index e5e2ff898..65d840ba7 100644 --- a/ts/session/messages/outgoing/content/receipt/index.ts +++ b/ts/session/messages/outgoing/content/receipt/index.ts @@ -1,5 +1,3 @@ export * from './ReceiptMessage'; export * from './DeliveryReceiptMessage'; export * from './ReadReceiptMessage'; - - diff --git a/ts/session/messages/outgoing/content/sync/SyncMessage.ts b/ts/session/messages/outgoing/content/sync/SyncMessage.ts index aa16ffe6e..3eb336dc6 100644 --- a/ts/session/messages/outgoing/content/sync/SyncMessage.ts +++ b/ts/session/messages/outgoing/content/sync/SyncMessage.ts @@ -13,5 +13,4 @@ export abstract class SyncMessage extends ContentMessage { } protected abstract syncProto(): SignalService.SyncMessage; - } diff --git a/ts/session/messages/outgoing/content/sync/index.ts b/ts/session/messages/outgoing/content/sync/index.ts index 0d101537b..6da779ff9 100644 --- a/ts/session/messages/outgoing/content/sync/index.ts +++ b/ts/session/messages/outgoing/content/sync/index.ts @@ -1,6 +1,3 @@ import * as SyncMessage from './SyncMessage'; - -export { - SyncMessage, -}; +export { SyncMessage }; diff --git a/ts/session/messages/outgoing/index.ts b/ts/session/messages/outgoing/index.ts index 3d821cc73..8aa5f07ef 100644 --- a/ts/session/messages/outgoing/index.ts +++ b/ts/session/messages/outgoing/index.ts @@ -2,7 +2,4 @@ import { Message } from './Message'; import { OpenGroupMessage } from './OpenGroupMessage'; export * from './content/'; -export { - Message, - OpenGroupMessage, -}; +export { Message, OpenGroupMessage }; diff --git a/ts/test/session/messages/ClosedGroupChatMessage_test.ts b/ts/test/session/messages/ClosedGroupChatMessage_test.ts index a68661579..5a1b9890e 100644 --- a/ts/test/session/messages/ClosedGroupChatMessage_test.ts +++ b/ts/test/session/messages/ClosedGroupChatMessage_test.ts @@ -1,50 +1,62 @@ import { expect } from 'chai'; -import { ChatMessage, ClosedGroupChatMessage } from '../../../session/messages/outgoing'; +import { + ChatMessage, + ClosedGroupChatMessage, +} from '../../../session/messages/outgoing'; import { SignalService } from '../../../protobuf'; import { TextEncoder } from 'util'; describe('ClosedGroupChatMessage', () => { - it('can create empty message with timestamp, groupId and chatMessage', () => { - const chatMessage = new ChatMessage({ - timestamp: Date.now(), - body: 'body', - }); - const message = new ClosedGroupChatMessage({ - groupId: '12', - chatMessage, - }); - const plainText = message.plainTextBuffer(); - const decoded = SignalService.Content.decode(plainText); - expect(decoded.dataMessage).to.have.property('group').to.have.deep.property('id', new TextEncoder().encode('12')); - expect(decoded.dataMessage).to.have.property('group').to.have.deep.property('type', SignalService.GroupContext.Type.DELIVER); + it('can create empty message with timestamp, groupId and chatMessage', () => { + const chatMessage = new ChatMessage({ + timestamp: Date.now(), + body: 'body', + }); + const message = new ClosedGroupChatMessage({ + groupId: '12', + chatMessage, + }); + const plainText = message.plainTextBuffer(); + const decoded = SignalService.Content.decode(plainText); + expect(decoded.dataMessage) + .to.have.property('group') + .to.have.deep.property('id', new TextEncoder().encode('12')); + expect(decoded.dataMessage) + .to.have.property('group') + .to.have.deep.property('type', SignalService.GroupContext.Type.DELIVER); - expect(decoded.dataMessage).to.have.deep.property('body', 'body'); + expect(decoded.dataMessage).to.have.deep.property('body', 'body'); - // we use the timestamp of the chatMessage as parent timestamp - expect(message).to.have.property('timestamp').to.be.equal(chatMessage.timestamp); - }); + // we use the timestamp of the chatMessage as parent timestamp + expect(message) + .to.have.property('timestamp') + .to.be.equal(chatMessage.timestamp); + }); - it('ttl of 1 day', () => { - const chatMessage = new ChatMessage({ - timestamp: Date.now(), - }); - const message = new ClosedGroupChatMessage({ - groupId: '12', - chatMessage, - }); - expect(message.ttl()).to.equal(24 * 60 * 60 * 1000); + it('ttl of 1 day', () => { + const chatMessage = new ChatMessage({ + timestamp: Date.now(), }); + const message = new ClosedGroupChatMessage({ + groupId: '12', + chatMessage, + }); + expect(message.ttl()).to.equal(24 * 60 * 60 * 1000); + }); - it('has an identifier', () => { - const chatMessage = new ChatMessage({ - timestamp: Date.now(), - }); - const message = new ClosedGroupChatMessage({ - groupId: '12', - chatMessage, - }); - expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); - expect(message.identifier).to.not.equal(undefined, 'identifier cannot be undefined'); + it('has an identifier', () => { + const chatMessage = new ChatMessage({ + timestamp: Date.now(), + }); + const message = new ClosedGroupChatMessage({ + groupId: '12', + chatMessage, }); + expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); + expect(message.identifier).to.not.equal( + undefined, + 'identifier cannot be undefined' + ); + }); }); diff --git a/ts/test/session/messages/DeviceLinkMessage_test.ts b/ts/test/session/messages/DeviceLinkMessage_test.ts index 71cfd603b..c7d3c8118 100644 --- a/ts/test/session/messages/DeviceLinkMessage_test.ts +++ b/ts/test/session/messages/DeviceLinkMessage_test.ts @@ -1,96 +1,133 @@ import { expect } from 'chai'; -import { beforeEach} from 'mocha'; +import { beforeEach } from 'mocha'; -import { DeviceLinkGrantMessage, DeviceLinkRequestMessage } from '../../../session/messages/outgoing'; +import { + DeviceLinkGrantMessage, + DeviceLinkRequestMessage, +} from '../../../session/messages/outgoing'; import { SignalService } from '../../../protobuf'; import { LokiProfile } from '../../../types/Message'; describe('DeviceLinkMessage', () => { - let linkRequestMessage: DeviceLinkRequestMessage; - let linkGrantMessage: DeviceLinkGrantMessage; - let lokiProfile: LokiProfile; + let linkRequestMessage: DeviceLinkRequestMessage; + let linkGrantMessage: DeviceLinkGrantMessage; + let lokiProfile: LokiProfile; - beforeEach(() => { - linkRequestMessage = new DeviceLinkRequestMessage({ - timestamp: Date.now(), - primaryDevicePubKey: '111111', - secondaryDevicePubKey: '222222', - requestSignature: new Uint8Array([1, 2, 3, 4, 5, 6]), - }); - - lokiProfile = { - displayName: 'displayName', - avatarPointer: 'avatarPointer', - profileKey: new Uint8Array([1, 2, 3, 4]), - }; - - linkGrantMessage = new DeviceLinkGrantMessage({ - timestamp: Date.now(), - primaryDevicePubKey: '111111', - secondaryDevicePubKey: '222222', - requestSignature: new Uint8Array([1, 2, 3, 4, 5, 6]), - grantSignature: new Uint8Array([6, 5, 4, 3, 2, 1]), - lokiProfile, - }); + beforeEach(() => { + linkRequestMessage = new DeviceLinkRequestMessage({ + timestamp: Date.now(), + primaryDevicePubKey: '111111', + secondaryDevicePubKey: '222222', + requestSignature: new Uint8Array([1, 2, 3, 4, 5, 6]), }); - describe('content of a linkRequestMessage ', () => { - let decoded: any; - before(() => { - const plainText = linkRequestMessage.plainTextBuffer(); - decoded = SignalService.Content.decode(plainText); - }); + lokiProfile = { + displayName: 'displayName', + avatarPointer: 'avatarPointer', + profileKey: new Uint8Array([1, 2, 3, 4]), + }; - it('has a pairingAuthorisation.primaryDevicePubKey', () => { - expect(decoded.pairingAuthorisation).to.have.property('primaryDevicePubKey', '111111'); - }); - it('has a pairingAuthorisation.secondaryDevicePubKey', () => { - expect(decoded.pairingAuthorisation).to.have.property('secondaryDevicePubKey', '222222'); - }); - it('has a pairingAuthorisation.requestSignature', () => { - expect(decoded.pairingAuthorisation).to.have.property('requestSignature').to.deep.equal(new Uint8Array([1, 2, 3, 4, 5, 6])); - }); - it('has no pairingAuthorisation.grantSignature', () => { - expect(decoded.pairingAuthorisation).to.have.property('grantSignature').to.have.lengthOf(0); - }); - it('has no lokiProfile', () => { - expect(decoded).to.not.have.property('lokiProfile'); - }); + linkGrantMessage = new DeviceLinkGrantMessage({ + timestamp: Date.now(), + primaryDevicePubKey: '111111', + secondaryDevicePubKey: '222222', + requestSignature: new Uint8Array([1, 2, 3, 4, 5, 6]), + grantSignature: new Uint8Array([6, 5, 4, 3, 2, 1]), + lokiProfile, }); + }); - describe('content of a linkGrantMessage ', () => { - let decoded: any; - before(() => { - const plainText = linkGrantMessage.plainTextBuffer(); - decoded = SignalService.Content.decode(plainText); - }); + describe('content of a linkRequestMessage ', () => { + let decoded: any; + before(() => { + const plainText = linkRequestMessage.plainTextBuffer(); + decoded = SignalService.Content.decode(plainText); + }); - it('has a pairingAuthorisation.primaryDevicePubKey', () => { - expect(decoded.pairingAuthorisation).to.have.property('primaryDevicePubKey', '111111'); - }); - it('has a pairingAuthorisation.secondaryDevicePubKey', () => { - expect(decoded.pairingAuthorisation).to.have.property('secondaryDevicePubKey', '222222'); - }); - it('has a pairingAuthorisation.requestSignature', () => { - expect(decoded.pairingAuthorisation).to.have.property('requestSignature').to.deep.equal(new Uint8Array([1, 2, 3, 4, 5, 6])); - }); - it('has a pairingAuthorisation.grantSignature', () => { - expect(decoded.pairingAuthorisation).to.have.property('grantSignature').to.deep.equal(new Uint8Array([6, 5, 4, 3, 2, 1])); - }); - it('has a lokiProfile', () => { - expect(decoded.dataMessage).to.have.property('profileKey').to.be.deep.equal(lokiProfile.profileKey); - expect(decoded.dataMessage).to.have.property('profile').to.have.property('displayName').to.be.deep.equal('displayName'); - expect(decoded.dataMessage).to.have.property('profile').to.have.property('avatar').to.be.deep.equal('avatarPointer'); - }); + it('has a pairingAuthorisation.primaryDevicePubKey', () => { + expect(decoded.pairingAuthorisation).to.have.property( + 'primaryDevicePubKey', + '111111' + ); + }); + it('has a pairingAuthorisation.secondaryDevicePubKey', () => { + expect(decoded.pairingAuthorisation).to.have.property( + 'secondaryDevicePubKey', + '222222' + ); + }); + it('has a pairingAuthorisation.requestSignature', () => { + expect(decoded.pairingAuthorisation) + .to.have.property('requestSignature') + .to.deep.equal(new Uint8Array([1, 2, 3, 4, 5, 6])); + }); + it('has no pairingAuthorisation.grantSignature', () => { + expect(decoded.pairingAuthorisation) + .to.have.property('grantSignature') + .to.have.lengthOf(0); + }); + it('has no lokiProfile', () => { + expect(decoded).to.not.have.property('lokiProfile'); }); + }); - it('ttl of 2 minutes', () => { - expect(linkRequestMessage.ttl()).to.equal(2 * 60 * 1000); - expect(linkGrantMessage.ttl()).to.equal(2 * 60 * 1000); + describe('content of a linkGrantMessage ', () => { + let decoded: any; + before(() => { + const plainText = linkGrantMessage.plainTextBuffer(); + decoded = SignalService.Content.decode(plainText); }); - it('has an identifier', () => { - expect(linkRequestMessage.identifier).to.not.equal(null, 'identifier cannot be null'); - expect(linkRequestMessage.identifier).to.not.equal(undefined, 'identifier cannot be undefined'); + it('has a pairingAuthorisation.primaryDevicePubKey', () => { + expect(decoded.pairingAuthorisation).to.have.property( + 'primaryDevicePubKey', + '111111' + ); }); + it('has a pairingAuthorisation.secondaryDevicePubKey', () => { + expect(decoded.pairingAuthorisation).to.have.property( + 'secondaryDevicePubKey', + '222222' + ); + }); + it('has a pairingAuthorisation.requestSignature', () => { + expect(decoded.pairingAuthorisation) + .to.have.property('requestSignature') + .to.deep.equal(new Uint8Array([1, 2, 3, 4, 5, 6])); + }); + it('has a pairingAuthorisation.grantSignature', () => { + expect(decoded.pairingAuthorisation) + .to.have.property('grantSignature') + .to.deep.equal(new Uint8Array([6, 5, 4, 3, 2, 1])); + }); + it('has a lokiProfile', () => { + expect(decoded.dataMessage) + .to.have.property('profileKey') + .to.be.deep.equal(lokiProfile.profileKey); + expect(decoded.dataMessage) + .to.have.property('profile') + .to.have.property('displayName') + .to.be.deep.equal('displayName'); + expect(decoded.dataMessage) + .to.have.property('profile') + .to.have.property('avatar') + .to.be.deep.equal('avatarPointer'); + }); + }); + + it('ttl of 2 minutes', () => { + expect(linkRequestMessage.ttl()).to.equal(2 * 60 * 1000); + expect(linkGrantMessage.ttl()).to.equal(2 * 60 * 1000); + }); + + it('has an identifier', () => { + expect(linkRequestMessage.identifier).to.not.equal( + null, + 'identifier cannot be null' + ); + expect(linkRequestMessage.identifier).to.not.equal( + undefined, + 'identifier cannot be undefined' + ); + }); }); diff --git a/ts/test/session/messages/DeviceUnlinkMessage_test.ts b/ts/test/session/messages/DeviceUnlinkMessage_test.ts index 52d8bc015..f29bea841 100644 --- a/ts/test/session/messages/DeviceUnlinkMessage_test.ts +++ b/ts/test/session/messages/DeviceUnlinkMessage_test.ts @@ -1,29 +1,35 @@ import { expect } from 'chai'; -import { beforeEach} from 'mocha'; +import { beforeEach } from 'mocha'; import { DeviceUnlinkMessage } from '../../../session/messages/outgoing'; import { SignalService } from '../../../protobuf'; describe('DeviceUnlinkMessage', () => { - let message: DeviceUnlinkMessage; - beforeEach(() => { - const timestamp = Date.now(); - message = new DeviceUnlinkMessage({timestamp}); - }); + let message: DeviceUnlinkMessage; + beforeEach(() => { + const timestamp = Date.now(); + message = new DeviceUnlinkMessage({ timestamp }); + }); - it('content of just the UNPAIRING_REQUEST flag set', () => { - const plainText = message.plainTextBuffer(); - const decoded = SignalService.Content.decode(plainText); + it('content of just the UNPAIRING_REQUEST flag set', () => { + const plainText = message.plainTextBuffer(); + const decoded = SignalService.Content.decode(plainText); - expect(decoded.dataMessage).to.have.property('flags', SignalService.DataMessage.Flags.UNPAIRING_REQUEST); - }); + expect(decoded.dataMessage).to.have.property( + 'flags', + SignalService.DataMessage.Flags.UNPAIRING_REQUEST + ); + }); - it('ttl of 4 days', () => { - expect(message.ttl()).to.equal(4 * 24 * 60 * 60 * 1000); - }); + it('ttl of 4 days', () => { + expect(message.ttl()).to.equal(4 * 24 * 60 * 60 * 1000); + }); - it('has an identifier', () => { - expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); - expect(message.identifier).to.not.equal(undefined, 'identifier cannot be undefined'); - }); + it('has an identifier', () => { + expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); + expect(message.identifier).to.not.equal( + undefined, + 'identifier cannot be undefined' + ); + }); }); diff --git a/ts/test/session/messages/EndSessionMessage_test.ts b/ts/test/session/messages/EndSessionMessage_test.ts index 7da213e49..4b6e864de 100644 --- a/ts/test/session/messages/EndSessionMessage_test.ts +++ b/ts/test/session/messages/EndSessionMessage_test.ts @@ -1,54 +1,78 @@ import { expect } from 'chai'; -import { beforeEach} from 'mocha'; +import { beforeEach } from 'mocha'; import { EndSessionMessage } from '../../../session/messages/outgoing'; import { SignalService } from '../../../protobuf'; import { TextEncoder } from 'util'; describe('EndSessionMessage', () => { - let message: EndSessionMessage; - const preKeyBundle = { - deviceId: 123456, - preKeyId: 654321, - signedKeyId: 111111, - preKey: new TextEncoder().encode('preKey'), - signature: new TextEncoder().encode('signature'), - signedKey: new TextEncoder().encode('signedKey'), - identityKey: new TextEncoder().encode('identityKey'), - }; - - beforeEach(() => { - const timestamp = Date.now(); - message = new EndSessionMessage({timestamp, preKeyBundle}); - }); - - it('has a preKeyBundle', () => { - const plainText = message.plainTextBuffer(); - const decoded = SignalService.Content.decode(plainText); - - expect(decoded.preKeyBundleMessage).to.have.property('deviceId', preKeyBundle.deviceId); - expect(decoded.preKeyBundleMessage).to.have.property('preKeyId', preKeyBundle.preKeyId); - expect(decoded.preKeyBundleMessage).to.have.property('signedKeyId', preKeyBundle.signedKeyId); - - expect(decoded.preKeyBundleMessage).to.have.deep.property('signature', preKeyBundle.signature); - expect(decoded.preKeyBundleMessage).to.have.deep.property('signedKey', preKeyBundle.signedKey); - expect(decoded.preKeyBundleMessage).to.have.deep.property('identityKey', preKeyBundle.identityKey); - }); - - it('has a dataMessage with `END_SESSION` flag and `TERMINATE` as body', () => { - const plainText = message.plainTextBuffer(); - const decoded = SignalService.Content.decode(plainText); - - expect(decoded.dataMessage).to.have.property('flags', SignalService.DataMessage.Flags.END_SESSION); - expect(decoded.dataMessage).to.have.deep.property('body', 'TERMINATE'); - }); - - it('ttl of 4 days', () => { - expect(message.ttl()).to.equal(4 * 24 * 60 * 60 * 1000); - }); - - it('has an identifier', () => { - expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); - expect(message.identifier).to.not.equal(undefined, 'identifier cannot be undefined'); - }); + let message: EndSessionMessage; + const preKeyBundle = { + deviceId: 123456, + preKeyId: 654321, + signedKeyId: 111111, + preKey: new TextEncoder().encode('preKey'), + signature: new TextEncoder().encode('signature'), + signedKey: new TextEncoder().encode('signedKey'), + identityKey: new TextEncoder().encode('identityKey'), + }; + + beforeEach(() => { + const timestamp = Date.now(); + message = new EndSessionMessage({ timestamp, preKeyBundle }); + }); + + it('has a preKeyBundle', () => { + const plainText = message.plainTextBuffer(); + const decoded = SignalService.Content.decode(plainText); + + expect(decoded.preKeyBundleMessage).to.have.property( + 'deviceId', + preKeyBundle.deviceId + ); + expect(decoded.preKeyBundleMessage).to.have.property( + 'preKeyId', + preKeyBundle.preKeyId + ); + expect(decoded.preKeyBundleMessage).to.have.property( + 'signedKeyId', + preKeyBundle.signedKeyId + ); + + expect(decoded.preKeyBundleMessage).to.have.deep.property( + 'signature', + preKeyBundle.signature + ); + expect(decoded.preKeyBundleMessage).to.have.deep.property( + 'signedKey', + preKeyBundle.signedKey + ); + expect(decoded.preKeyBundleMessage).to.have.deep.property( + 'identityKey', + preKeyBundle.identityKey + ); + }); + + it('has a dataMessage with `END_SESSION` flag and `TERMINATE` as body', () => { + const plainText = message.plainTextBuffer(); + const decoded = SignalService.Content.decode(plainText); + + expect(decoded.dataMessage).to.have.property( + 'flags', + SignalService.DataMessage.Flags.END_SESSION + ); + expect(decoded.dataMessage).to.have.deep.property('body', 'TERMINATE'); + }); + + it('ttl of 4 days', () => { + expect(message.ttl()).to.equal(4 * 24 * 60 * 60 * 1000); + }); + + it('has an identifier', () => { + expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); + expect(message.identifier).to.not.equal( + undefined, + 'identifier cannot be undefined' + ); + }); }); diff --git a/ts/test/session/messages/SessionEstablishedMessage_test.ts b/ts/test/session/messages/SessionEstablishedMessage_test.ts index 555190a3d..40d672bb8 100644 --- a/ts/test/session/messages/SessionEstablishedMessage_test.ts +++ b/ts/test/session/messages/SessionEstablishedMessage_test.ts @@ -1,29 +1,35 @@ import { expect } from 'chai'; -import { beforeEach} from 'mocha'; +import { beforeEach } from 'mocha'; import { SessionEstablishedMessage } from '../../../session/messages/outgoing'; import { SignalService } from '../../../protobuf'; describe('SessionEstablishedMessage', () => { - let message: SessionEstablishedMessage; - beforeEach(() => { - const timestamp = Date.now(); - message = new SessionEstablishedMessage({timestamp}); - }); + let message: SessionEstablishedMessage; + beforeEach(() => { + const timestamp = Date.now(); + message = new SessionEstablishedMessage({ timestamp }); + }); - it('has a nullMessage not null', () => { - const plainText = message.plainTextBuffer(); - const decoded = SignalService.Content.decode(plainText); + it('has a nullMessage not null', () => { + const plainText = message.plainTextBuffer(); + const decoded = SignalService.Content.decode(plainText); - expect(decoded.nullMessage).to.be.not.equal(null, 'decoded.dataMessage.nullMessage should not be null'); - }); + expect(decoded.nullMessage).to.be.not.equal( + null, + 'decoded.dataMessage.nullMessage should not be null' + ); + }); - it('ttl of 5 minutes', () => { - expect(message.ttl()).to.equal(5 * 60 * 1000); - }); + it('ttl of 5 minutes', () => { + expect(message.ttl()).to.equal(5 * 60 * 1000); + }); - it('has an identifier', () => { - expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); - expect(message.identifier).to.not.equal(undefined, 'identifier cannot be undefined'); - }); + it('has an identifier', () => { + expect(message.identifier).to.not.equal(null, 'identifier cannot be null'); + expect(message.identifier).to.not.equal( + undefined, + 'identifier cannot be undefined' + ); + }); }); diff --git a/ts/types/Message.ts b/ts/types/Message.ts index d7cb90e63..db77b5bad 100644 --- a/ts/types/Message.ts +++ b/ts/types/Message.ts @@ -104,7 +104,6 @@ export const hasExpiration = (message: Message): boolean => { return typeof expireTimer === 'number' && expireTimer > 0; }; - export type LokiProfile = { displayName: string; avatarPointer: string;