add EndSession and SessionReset messages & tests

pull/1151/head
Audric Ackermann 5 years ago
parent 601d978883
commit 46a48406c7
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -4,10 +4,19 @@ import { SignalService } from '../../../../protobuf';
export class EndSessionMessage extends SessionResetMessage { export class EndSessionMessage extends SessionResetMessage {
public ttl(): number { public ttl(): number {
return this.getDefaultTTL(); return 4 * 24 * 60 * 60 * 1000; // 4 days
} }
protected contentProto(): SignalService.Content { protected contentProto(): SignalService.Content {
throw new Error('Not implemented'); const dataMessage = new SignalService.DataMessage({
body: 'TERMINATE',
flags: SignalService.DataMessage.Flags.END_SESSION,
});
const preKeyBundleMessage = this.getPreKeyBundleMessage();
return new SignalService.Content({
dataMessage,
preKeyBundleMessage,
});
} }
} }

@ -1,13 +1,47 @@
import { ContentMessage } from './ContentMessage'; import { ContentMessage } from './ContentMessage';
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
export interface PreKeyBundleType {
identityKey?: (Uint8Array|null);
deviceId?: (number|null);
preKeyId?: (number|null);
signedKeyId?: (number|null);
preKey?: (Uint8Array|null);
signedKey?: (Uint8Array|null);
signature?: (Uint8Array|null);
}
interface SessionResetParams {
timestamp: number;
identifier: string;
preKeyBundle: PreKeyBundleType;
}
export class SessionResetMessage extends ContentMessage { export class SessionResetMessage extends ContentMessage {
private readonly preKeyBundle: PreKeyBundleType;
constructor(params: SessionResetParams) {
super({ timestamp: params.timestamp, identifier: params.identifier });
this.preKeyBundle = params.preKeyBundle;
}
public ttl(): number { public ttl(): number {
return this.getDefaultTTL(); return 4 * 24 * 60 * 60 * 1000; // 4 days
}
protected getPreKeyBundleMessage(): SignalService.PreKeyBundleMessage {
return new SignalService.PreKeyBundleMessage(this.preKeyBundle);
} }
protected contentProto(): SignalService.Content { protected contentProto(): SignalService.Content {
throw new Error('Not implemented'); const nullMessage = new SignalService.NullMessage({});
const preKeyBundleMessage = this.getPreKeyBundleMessage();
return new SignalService.Content({
nullMessage,
preKeyBundleMessage,
});
} }
} }

@ -0,0 +1,34 @@
import { expect } from 'chai';
import { beforeEach} from 'mocha';
import { EndSessionMessage } from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
describe('EndSessionMessage', () => {
let message: EndSessionMessage;
beforeEach(() => {
const timestamp = Date.now();
const identifier = '123456';
const preKeyBundle = {deviceId: 123456};
message = new EndSessionMessage({timestamp, identifier, preKeyBundle});
});
it('has a preKeyBundle', () => {
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
expect(decoded.preKeyBundleMessage).to.have.property('deviceId', 123456);
});
it('has a dataMessage with `END_SESSION` flag and `TERMINATE` as body', () => {
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.toObject(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);
});
});

@ -0,0 +1,33 @@
import { expect } from 'chai';
import { beforeEach} from 'mocha';
import { SessionResetMessage } from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
describe('SessionResetMessage', () => {
let message: SessionResetMessage;
beforeEach(() => {
const timestamp = Date.now();
const identifier = '123456';
const preKeyBundle = {deviceId: 123456};
message = new SessionResetMessage({timestamp, identifier, preKeyBundle});
});
it('has a preKeyBundle', () => {
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
expect(decoded.preKeyBundleMessage).to.have.property('deviceId', 123456);
});
it('has a nullMessage not null', () => {
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.toObject(SignalService.Content.decode(plainText));
expect(decoded.nullMessage).to.be.not.equal(null, 'decoded.dataMessage.nullMessage should not be null');
});
it('ttl of 4 days', () => {
expect(message.ttl()).to.equal(4 * 24 * 60 * 60 * 1000);
});
});
Loading…
Cancel
Save