mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
d8ce198f55
* Fetch conversations once, clean up ConversationController API Race conditions around re-fetching have caused some problems recently, so this removes the need to re-fetch conversations. They are fetched once or saved once, and that is it. All interaction goes through the ConversationController, which is the central source of truth. We have two rules for Conversations: 1. If a conversation is in the ConversationController it doesn't need to be fetched, but its initial fetch/save might be in progress. You can wait for that fetch/save with conversation.initialPromise. 2. If a conversation is not already in the ConversationController, it's not yet in the database. It needs to be added to the ConversationController and saved to the database. FREEBIE * Remove Conversation.fetch() call in Message.handleDataMessage() FREEBIE * ConversationController.API cleanup: Fix two missing spots FREEBIE
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
describe('KeyChangeListener', function() {
|
|
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;
|
|
|
|
before(function() {
|
|
storage.put('safety-numbers-approval', false);
|
|
});
|
|
|
|
after(function() {
|
|
storage.remove('safety-numbers-approval');
|
|
});
|
|
|
|
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() {
|
|
var convo = new Whisper.Conversation({ id: phoneNumberWithKeyChange, type: 'private'});
|
|
before(function() {
|
|
ConversationController.createTemporary(convo);
|
|
return convo.save();
|
|
});
|
|
|
|
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();
|
|
});
|
|
});
|
|
return store.saveIdentity(address.toString(), newKey);
|
|
});
|
|
});
|
|
|
|
|
|
describe('When we have a group with this contact', function() {
|
|
var convo = new Whisper.Conversation({ id: 'groupId', type: 'group', members: [phoneNumberWithKeyChange] });
|
|
before(function() {
|
|
ConversationController.createTemporary(convo);
|
|
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();
|
|
});
|
|
});
|
|
return store.saveIdentity(address.toString(), newKey);
|
|
});
|
|
|
|
});
|
|
|
|
});
|