From 2584f4fae47070d10a2e410f4d13547d2798b2a0 Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 26 May 2017 17:39:20 -0700 Subject: [PATCH] Fix tests // FREEBIE --- libtextsecure/test/in_memory_signal_protocol_store.js | 9 ++++++++- libtextsecure/test/protocol_wrapper_test.js | 4 +++- test/keychange_listener_test.js | 4 ++-- test/storage_test.js | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libtextsecure/test/in_memory_signal_protocol_store.js b/libtextsecure/test/in_memory_signal_protocol_store.js index 92020be24..cec47e027 100644 --- a/libtextsecure/test/in_memory_signal_protocol_store.js +++ b/libtextsecure/test/in_memory_signal_protocol_store.js @@ -3,6 +3,7 @@ function SignalProtocolStore() { } SignalProtocolStore.prototype = { + Direction: { SENDING: 1, RECEIVING: 2}, getIdentityKeyPair: function() { return Promise.resolve(this.get('identityKey')); }, @@ -53,7 +54,13 @@ SignalProtocolStore.prototype = { if (identifier === null || identifier === undefined) throw new Error("Tried to put identity key for undefined/null key"); return new Promise(function(resolve) { - resolve(this.put('identityKey' + identifier, identityKey)); + var existing = this.get('identityKey' + identifier); + this.put('identityKey' + identifier, identityKey); + if (existing && existing !== identityKey) { + resolve(true); + } else { + resolve(false); + } }.bind(this)); }, diff --git a/libtextsecure/test/protocol_wrapper_test.js b/libtextsecure/test/protocol_wrapper_test.js index 02d2de562..64db34bfd 100644 --- a/libtextsecure/test/protocol_wrapper_test.js +++ b/libtextsecure/test/protocol_wrapper_test.js @@ -14,7 +14,9 @@ describe('Protocol Wrapper', function() { localStorage.clear(); libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKey) { return textsecure.storage.protocol.saveIdentity(identifier, identityKey); - }).then(done); + }).then(function() { + done(); + }); }); describe('processPreKey', function() { it('rejects if the identity key changes', function(done) { diff --git a/test/keychange_listener_test.js b/test/keychange_listener_test.js index 0b84a4f18..8710284a3 100644 --- a/test/keychange_listener_test.js +++ b/test/keychange_listener_test.js @@ -42,7 +42,7 @@ describe('KeyChangeListener', function() { done(); }); }); - return store.isTrustedIdentity(phoneNumberWithKeyChange, newKey); + return store.saveIdentity(phoneNumberWithKeyChange, newKey); }); }); @@ -66,7 +66,7 @@ describe('KeyChangeListener', function() { done(); }); }); - return store.isTrustedIdentity(phoneNumberWithKeyChange, newKey); + return store.saveIdentity(phoneNumberWithKeyChange, newKey); }); }); diff --git a/test/storage_test.js b/test/storage_test.js index bd255a490..06f305e4c 100644 --- a/test/storage_test.js +++ b/test/storage_test.js @@ -56,7 +56,7 @@ describe("SignalProtocolStore", function() { describe('isTrustedIdentity', function() { it('returns true if a key is trusted', function(done) { store.saveIdentity(identifier, testKey.pubKey).then(function() { - store.isTrustedIdentity(identifier, testKey.pubKey).then(function(trusted) { + store.isTrustedIdentity(identifier, testKey.pubKey, store.Direction.RECEIVING).then(function(trusted) { if (trusted) { done(); } else { @@ -68,7 +68,7 @@ describe("SignalProtocolStore", function() { it('returns false if a key is untrusted', function(done) { var newIdentity = libsignal.crypto.getRandomBytes(33); store.saveIdentity(identifier, testKey.pubKey).then(function() { - store.isTrustedIdentity(identifier, newIdentity).then(function(trusted) { + store.isTrustedIdentity(identifier, newIdentity, store.Direction.SENDING).then(function(trusted) { if (trusted) { done(new Error('Allowed to overwrite identity key')); } else {