session-desktop/test/keychange_listener_test.js

80 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-11-02 19:02:53 +01:00
/* global ConversationController, libsignal, SignalProtocolStore, Whisper */
describe('KeyChangeListener', () => {
const phoneNumberWithKeyChange = '+13016886524'; // nsa
const address = new libsignal.SignalProtocolAddress(
2018-04-27 23:25:04 +02:00
phoneNumberWithKeyChange,
1
);
2018-11-02 19:02:53 +01:00
const oldKey = libsignal.crypto.getRandomBytes(33);
const newKey = libsignal.crypto.getRandomBytes(33);
let store;
beforeEach(async () => {
store = new SignalProtocolStore();
await store.hydrateCaches();
Whisper.KeyChangeListener.init(store);
return store.saveIdentity(address.toString(), oldKey);
});
2018-11-02 19:02:53 +01:00
afterEach(() => {
return store.removeIdentityKey(phoneNumberWithKeyChange);
});
2018-11-02 19:02:53 +01:00
describe('When we have a conversation with this contact', () => {
let convo;
2018-11-02 19:02:53 +01:00
before(async () => {
convo = ConversationController.dangerouslyCreateAndAdd({
id: phoneNumberWithKeyChange,
type: 'private',
});
2018-09-21 03:47:19 +02:00
await window.Signal.Data.saveConversation(convo.attributes, {
Conversation: Whisper.Conversation,
});
});
2018-11-02 19:02:53 +01:00
after(async () => {
2018-09-21 03:47:19 +02:00
await convo.destroyMessages();
await window.Signal.Data.saveConversation(convo.id);
});
2018-11-02 19:02:53 +01:00
it('generates a key change notice in the private conversation with this contact', done => {
2018-09-21 03:47:19 +02:00
convo.once('newmessage', async () => {
await convo.fetchMessages();
2018-09-21 03:47:19 +02:00
const message = convo.messageCollection.at(0);
assert.strictEqual(message.get('type'), 'keychange');
done();
});
store.saveIdentity(address.toString(), newKey);
});
});
2018-11-02 19:02:53 +01:00
describe('When we have a group with this contact', () => {
let convo;
2018-11-02 19:02:53 +01:00
before(async () => {
convo = ConversationController.dangerouslyCreateAndAdd({
id: 'groupId',
type: 'group',
members: [phoneNumberWithKeyChange],
});
2018-09-21 03:47:19 +02:00
await window.Signal.Data.saveConversation(convo.attributes, {
Conversation: Whisper.Conversation,
});
});
2018-11-02 19:02:53 +01:00
after(async () => {
2018-09-21 03:47:19 +02:00
await convo.destroyMessages();
await window.Signal.Data.saveConversation(convo.id);
});
2018-11-02 19:02:53 +01:00
it('generates a key change notice in the group conversation with this contact', done => {
2018-09-21 03:47:19 +02:00
convo.once('newmessage', async () => {
await convo.fetchMessages();
2018-09-21 03:47:19 +02:00
const message = convo.messageCollection.at(0);
assert.strictEqual(message.get('type'), 'keychange');
done();
});
store.saveIdentity(address.toString(), newKey);
});
});
});