2017-05-07 23:18:22 +02:00
|
|
|
describe('KeyChangeListener', function() {
|
2018-04-27 23:25:04 +02:00
|
|
|
var phoneNumberWithKeyChange = '+13016886524'; // nsa
|
|
|
|
var address = new libsignal.SignalProtocolAddress(
|
|
|
|
phoneNumberWithKeyChange,
|
|
|
|
1
|
|
|
|
);
|
2017-05-10 23:11:31 +02:00
|
|
|
var oldKey = libsignal.crypto.getRandomBytes(33);
|
|
|
|
var newKey = libsignal.crypto.getRandomBytes(33);
|
2017-05-07 23:18:22 +02:00
|
|
|
var store;
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
store = new SignalProtocolStore();
|
|
|
|
Whisper.KeyChangeListener.init(store);
|
2017-06-29 05:59:15 +02:00
|
|
|
return store.saveIdentity(address.toString(), oldKey);
|
2017-05-07 23:18:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
2017-05-10 23:11:31 +02:00
|
|
|
return store.removeIdentityKey(phoneNumberWithKeyChange);
|
2017-05-07 23:18:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('When we have a conversation with this contact', function() {
|
2018-03-28 00:58:00 +02:00
|
|
|
let convo;
|
2017-05-07 23:18:22 +02:00
|
|
|
before(function() {
|
2018-03-28 00:58:00 +02:00
|
|
|
convo = ConversationController.dangerouslyCreateAndAdd({
|
|
|
|
id: phoneNumberWithKeyChange,
|
|
|
|
type: 'private',
|
|
|
|
});
|
2017-05-10 21:34:41 +02:00
|
|
|
return convo.save();
|
2017-05-07 23:18:22 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function() {
|
|
|
|
convo.destroyMessages();
|
|
|
|
return convo.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generates a key change notice in the private conversation with this contact', function(done) {
|
|
|
|
convo.on('newmessage', function() {
|
|
|
|
return convo.fetchMessages().then(function() {
|
|
|
|
var message = convo.messageCollection.at(0);
|
|
|
|
assert.strictEqual(message.get('type'), 'keychange');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-20 05:53:12 +02:00
|
|
|
store.saveIdentity(address.toString(), newKey);
|
2017-05-07 23:18:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('When we have a group with this contact', function() {
|
2018-03-28 00:58:00 +02:00
|
|
|
let convo;
|
2017-05-07 23:18:22 +02:00
|
|
|
before(function() {
|
2018-03-28 00:58:00 +02:00
|
|
|
convo = ConversationController.dangerouslyCreateAndAdd({
|
|
|
|
id: 'groupId',
|
|
|
|
type: 'group',
|
|
|
|
members: [phoneNumberWithKeyChange],
|
|
|
|
});
|
2017-05-07 23:18:22 +02:00
|
|
|
return convo.save();
|
|
|
|
});
|
|
|
|
after(function() {
|
|
|
|
convo.destroyMessages();
|
|
|
|
return convo.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('generates a key change notice in the group conversation with this contact', function(done) {
|
|
|
|
convo.on('newmessage', function() {
|
|
|
|
return convo.fetchMessages().then(function() {
|
|
|
|
var message = convo.messageCollection.at(0);
|
|
|
|
assert.strictEqual(message.get('type'), 'keychange');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-05-20 05:53:12 +02:00
|
|
|
store.saveIdentity(address.toString(), newKey);
|
2017-05-07 23:18:22 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|