mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
lint
This commit is contained in:
parent
3840d061c3
commit
9fd929e812
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import { ContentMessage } from './ContentMessage';
|
|||
import { SignalService } from '../../../../protobuf';
|
||||
|
||||
export class SessionEstablishedMessage extends ContentMessage {
|
||||
|
||||
public ttl(): number {
|
||||
return 5 * 60 * 1000;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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<Preview>;
|
||||
}
|
||||
|
||||
|
||||
export class ChatMessage extends DataMessage {
|
||||
private readonly attachments?: Array<AttachmentPointer>;
|
||||
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;
|
||||
}
|
||||
if (attachment.thumbnail) {
|
||||
quotedAttachment.thumbnail = attachment.thumbnail;
|
||||
}
|
||||
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;
|
||||
});
|
||||
return quotedAttachment;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,6 @@ export class ChatMessage extends DataMessage {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
return dataMessage;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
export * from './DeviceLinkGrantMessage';
|
||||
export * from './DeviceLinkRequestMessage';
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -8,9 +8,8 @@ interface ReceiptMessageParams extends MessageParams {
|
|||
export abstract class ReceiptMessage extends ContentMessage {
|
||||
private readonly timestamps: Array<number>;
|
||||
|
||||
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 {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
export * from './ReceiptMessage';
|
||||
export * from './DeliveryReceiptMessage';
|
||||
export * from './ReadReceiptMessage';
|
||||
|
||||
|
||||
|
|
|
@ -13,5 +13,4 @@ export abstract class SyncMessage extends ContentMessage {
|
|||
}
|
||||
|
||||
protected abstract syncProto(): SignalService.SyncMessage;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import * as SyncMessage from './SyncMessage';
|
||||
|
||||
|
||||
export {
|
||||
SyncMessage,
|
||||
};
|
||||
export { SyncMessage };
|
||||
|
|
|
@ -2,7 +2,4 @@ import { Message } from './Message';
|
|||
import { OpenGroupMessage } from './OpenGroupMessage';
|
||||
|
||||
export * from './content/';
|
||||
export {
|
||||
Message,
|
||||
OpenGroupMessage,
|
||||
};
|
||||
export { Message, OpenGroupMessage };
|
||||
|
|
|
@ -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);
|
||||
|
||||
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);
|
||||
it('can create empty message with timestamp, groupId and chatMessage', () => {
|
||||
const chatMessage = new ChatMessage({
|
||||
timestamp: Date.now(),
|
||||
body: 'body',
|
||||
});
|
||||
|
||||
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);
|
||||
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('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');
|
||||
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);
|
||||
});
|
||||
|
||||
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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 linkRequestMessage ', () => {
|
||||
let decoded: any;
|
||||
before(() => {
|
||||
const plainText = linkRequestMessage.plainTextBuffer();
|
||||
decoded = SignalService.Content.decode(plainText);
|
||||
});
|
||||
|
||||
describe('content of a linkGrantMessage ', () => {
|
||||
let decoded: any;
|
||||
before(() => {
|
||||
const plainText = linkGrantMessage.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 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('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');
|
||||
});
|
||||
describe('content of a linkGrantMessage ', () => {
|
||||
let decoded: any;
|
||||
before(() => {
|
||||
const plainText = linkGrantMessage.plainTextBuffer();
|
||||
decoded = SignalService.Content.decode(plainText);
|
||||
});
|
||||
|
||||
it('ttl of 2 minutes', () => {
|
||||
expect(linkRequestMessage.ttl()).to.equal(2 * 60 * 1000);
|
||||
expect(linkGrantMessage.ttl()).to.equal(2 * 60 * 1000);
|
||||
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 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('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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'),
|
||||
};
|
||||
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});
|
||||
});
|
||||
beforeEach(() => {
|
||||
const timestamp = Date.now();
|
||||
message = new EndSessionMessage({ timestamp, preKeyBundle });
|
||||
});
|
||||
|
||||
it('has a preKeyBundle', () => {
|
||||
const plainText = message.plainTextBuffer();
|
||||
const decoded = SignalService.Content.decode(plainText);
|
||||
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.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);
|
||||
});
|
||||
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);
|
||||
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');
|
||||
});
|
||||
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('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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -104,7 +104,6 @@ export const hasExpiration = (message: Message): boolean => {
|
|||
return typeof expireTimer === 'number' && expireTimer > 0;
|
||||
};
|
||||
|
||||
|
||||
export type LokiProfile = {
|
||||
displayName: string;
|
||||
avatarPointer: string;
|
||||
|
|
Loading…
Reference in a new issue