From f173104c82421bfa04aecb089315f44d8f236f4a Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 4 May 2016 00:09:44 -0700 Subject: [PATCH] Tests for isTrustedIdentity // FREEBIE --- libtextsecure/test/storage_test.js | 24 ++++++++++++++++++++++++ test/storage_test.js | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/libtextsecure/test/storage_test.js b/libtextsecure/test/storage_test.js index c27368df..40971916 100644 --- a/libtextsecure/test/storage_test.js +++ b/libtextsecure/test/storage_test.js @@ -37,6 +37,30 @@ describe("SignalProtocolStore", function() { }); }).then(done,done); }); + it('returns whether a key is trusted', function(done) { + var newIdentity = textsecure.crypto.getRandomBytes(33); + store.putIdentityKey(identifier, testKey.pubKey).then(function() { + store.isTrustedIdentity(identifier, newIdentity).then(function(trusted) { + if (trusted) { + done(new Error('Allowed to overwrite identity key')); + } else { + done(); + } + }).catch(done); + }); + }); + it('returns whether a key is untrusted', function(done) { + var newIdentity = textsecure.crypto.getRandomBytes(33); + store.putIdentityKey(identifier, testKey.pubKey).then(function() { + store.isTrustedIdentity(identifier, testKey.pubKey).then(function(trusted) { + if (trusted) { + done(); + } else { + done(new Error('Allowed to overwrite identity key')); + } + }).catch(done); + }); + }); it('stores prekeys', function(done) { store.storePreKey(1, testKey).then(function() { return store.loadPreKey(1).then(function(key) { diff --git a/test/storage_test.js b/test/storage_test.js index dda8a1ac..346424ce 100644 --- a/test/storage_test.js +++ b/test/storage_test.js @@ -49,6 +49,29 @@ describe("SignalProtocolStore", function() { }); }); }); + it('returns true if a key is trusted', function(done) { + store.putIdentityKey(identifier, testKey.pubKey).then(function() { + store.isTrustedIdentity(identifier, testKey.pubKey).then(function(trusted) { + if (trusted) { + done(); + } else { + done(new Error('Allowed to overwrite identity key')); + } + }).catch(done); + }); + }); + it('returns false if a key is untrusted', function(done) { + var newIdentity = textsecure.crypto.getRandomBytes(33); + store.putIdentityKey(identifier, testKey.pubKey).then(function() { + store.isTrustedIdentity(identifier, newIdentity).then(function(trusted) { + if (trusted) { + done(new Error('Allowed to overwrite identity key')); + } else { + done(); + } + }).catch(done); + }); + }); it('stores prekeys', function(done) { store.storePreKey(1, testKey).then(function() { return store.loadPreKey(1).then(function(key) {