Improve keychange notice reliability/perf
Bind a single listener to keychange events from the storage interface, which then looks up relevant conversations and adds notices to them, with tests. Previously we would need to instantiate a conversation model in order to start listening to its key change events. In practice this usually happens at startup but we shouldn't rely on it, and it incurs higher overhead since it creates a different listener for each conversation. // FREEBIE
This commit is contained in:
parent
787c393e1b
commit
aed5735620
8 changed files with 127 additions and 25 deletions
|
@ -529,6 +529,7 @@
|
|||
<script type="text/javascript" src="../js/conversation_controller.js" data-cover></script>
|
||||
<script type="text/javascript" src="../js/panel_controller.js"></script>
|
||||
<script type='text/javascript' src='../js/emoji_util.js'></script>
|
||||
<script type="text/javascript" src="../js/keychange_listener.js"></script>
|
||||
|
||||
<script type="text/javascript" src="../js/chromium.js"></script>
|
||||
|
||||
|
@ -574,6 +575,7 @@
|
|||
<script type="text/javascript" src="models/conversations_test.js"></script>
|
||||
<script type="text/javascript" src="models/messages_test.js"></script>
|
||||
<script type="text/javascript" src="storage_test.js"></script>
|
||||
<script type="text/javascript" src="keychange_listener_test.js"></script>
|
||||
|
||||
<script type="text/javascript" src="fixtures.js"></script>
|
||||
<script type="text/javascript" src="fixtures_test.js"></script>
|
||||
|
|
74
test/keychange_listener_test.js
Normal file
74
test/keychange_listener_test.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
describe('KeyChangeListener', function() {
|
||||
var phone_number_with_keychange = '+13016886524'; // nsa
|
||||
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(phone_number_with_keychange, oldkey);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
return store.removeIdentityKey(phone_number_with_keychange);
|
||||
});
|
||||
|
||||
describe('When we have a conversation with this contact', function() {
|
||||
var convo = new Whisper.Conversation({ id: phone_number_with_keychange, type: 'private'});
|
||||
before(function() {
|
||||
ConversationController.add(convo);
|
||||
return new Promise(function(resolve) { convo.save().then(resolve); });
|
||||
});
|
||||
|
||||
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.isTrustedIdentity(phone_number_with_keychange, newkey);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('When we have a group with this contact', function() {
|
||||
var convo = new Whisper.Conversation({ id: 'groupId', type: 'group', members: [phone_number_with_keychange] });
|
||||
before(function() {
|
||||
ConversationController.add(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.isTrustedIdentity(phone_number_with_keychange, newkey);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue