add EndSession and SessionReset messages & tests
parent
601d978883
commit
46a48406c7
@ -1,13 +1,47 @@
|
||||
import { ContentMessage } from './ContentMessage';
|
||||
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 {
|
||||
private readonly preKeyBundle: PreKeyBundleType;
|
||||
|
||||
constructor(params: SessionResetParams) {
|
||||
super({ timestamp: params.timestamp, identifier: params.identifier });
|
||||
this.preKeyBundle = params.preKeyBundle;
|
||||
}
|
||||
|
||||
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 {
|
||||
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…
Reference in New Issue