Fix tests
// FREEBIE
This commit is contained in:
parent
f095a1583e
commit
2584f4fae4
4 changed files with 15 additions and 6 deletions
|
@ -3,6 +3,7 @@ function SignalProtocolStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SignalProtocolStore.prototype = {
|
SignalProtocolStore.prototype = {
|
||||||
|
Direction: { SENDING: 1, RECEIVING: 2},
|
||||||
getIdentityKeyPair: function() {
|
getIdentityKeyPair: function() {
|
||||||
return Promise.resolve(this.get('identityKey'));
|
return Promise.resolve(this.get('identityKey'));
|
||||||
},
|
},
|
||||||
|
@ -53,7 +54,13 @@ SignalProtocolStore.prototype = {
|
||||||
if (identifier === null || identifier === undefined)
|
if (identifier === null || identifier === undefined)
|
||||||
throw new Error("Tried to put identity key for undefined/null key");
|
throw new Error("Tried to put identity key for undefined/null key");
|
||||||
return new Promise(function(resolve) {
|
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));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,9 @@ describe('Protocol Wrapper', function() {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKey) {
|
libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKey) {
|
||||||
return textsecure.storage.protocol.saveIdentity(identifier, identityKey);
|
return textsecure.storage.protocol.saveIdentity(identifier, identityKey);
|
||||||
}).then(done);
|
}).then(function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('processPreKey', function() {
|
describe('processPreKey', function() {
|
||||||
it('rejects if the identity key changes', function(done) {
|
it('rejects if the identity key changes', function(done) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ describe('KeyChangeListener', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return store.isTrustedIdentity(phoneNumberWithKeyChange, newKey);
|
return store.saveIdentity(phoneNumberWithKeyChange, newKey);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ describe('KeyChangeListener', function() {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return store.isTrustedIdentity(phoneNumberWithKeyChange, newKey);
|
return store.saveIdentity(phoneNumberWithKeyChange, newKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,7 +56,7 @@ describe("SignalProtocolStore", function() {
|
||||||
describe('isTrustedIdentity', function() {
|
describe('isTrustedIdentity', function() {
|
||||||
it('returns true if a key is trusted', function(done) {
|
it('returns true if a key is trusted', function(done) {
|
||||||
store.saveIdentity(identifier, testKey.pubKey).then(function() {
|
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) {
|
if (trusted) {
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,7 +68,7 @@ describe("SignalProtocolStore", function() {
|
||||||
it('returns false if a key is untrusted', function(done) {
|
it('returns false if a key is untrusted', function(done) {
|
||||||
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
||||||
store.saveIdentity(identifier, testKey.pubKey).then(function() {
|
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) {
|
if (trusted) {
|
||||||
done(new Error('Allowed to overwrite identity key'));
|
done(new Error('Allowed to overwrite identity key'));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue