Fix tests

// FREEBIE
This commit is contained in:
lilia 2017-05-26 17:39:20 -07:00 committed by Scott Nonnenberg
parent f095a1583e
commit 2584f4fae4
4 changed files with 15 additions and 6 deletions

View File

@ -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));
},

View File

@ -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) {

View File

@ -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);
});
});

View File

@ -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 {