session-desktop/test/keychange_listener_test.js

78 lines
2.4 KiB
JavaScript
Raw Normal View History

describe('KeyChangeListener', function() {
2018-04-27 23:25:04 +02:00
var phoneNumberWithKeyChange = '+13016886524'; // nsa
var address = new libsignal.SignalProtocolAddress(
phoneNumberWithKeyChange,
1
);
var oldKey = libsignal.crypto.getRandomBytes(33);
var newKey = libsignal.crypto.getRandomBytes(33);
var store;
beforeEach(function() {
store = new SignalProtocolStore();
Whisper.KeyChangeListener.init(store);
return store.saveIdentity(address.toString(), oldKey);
});
afterEach(function() {
return store.removeIdentityKey(phoneNumberWithKeyChange);
});
describe('When we have a conversation with this contact', function() {
let convo;
2018-09-21 03:47:19 +02:00
before(async function() {
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-09-21 03:47:19 +02:00
after(async function() {
await convo.destroyMessages();
await window.Signal.Data.saveConversation(convo.id);
});
it('generates a key change notice in the private conversation with this contact', function(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);
});
});
describe('When we have a group with this contact', function() {
let convo;
2018-09-21 03:47:19 +02:00
before(async function() {
console.log('Creating group with contact', phoneNumberWithKeyChange);
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-09-21 03:47:19 +02:00
after(async function() {
await convo.destroyMessages();
await window.Signal.Data.saveConversation(convo.id);
});
it('generates a key change notice in the group conversation with this contact', function(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);
});
});
});