Fix tests

Update in-memory storage implementation to parse full address strings in
saveIdentity. Update usage of saveIdentity, passing in the full address string.
This commit is contained in:
lilia 2017-07-02 16:06:04 -10:00
parent 1fe18c3384
commit f308236941
3 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,7 @@
function testIdentityKeyStore(store, registrationId, identityKey) {
describe('IdentityKeyStore', function() {
var number = '+5558675309';
var address = new libsignal.SignalProtocolAddress('+5558675309', 1);
var testKey;
before(function(done) {
Internal.crypto.createKeyPair().then(function(keyPair) {
@ -25,7 +26,7 @@ function testIdentityKeyStore(store, registrationId, identityKey) {
});
describe('saveIdentity', function() {
it('stores identity keys', function(done) {
store.saveIdentity(number, testKey.pubKey).then(function() {
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
return store.loadIdentityKey(number).then(function(key) {
assertEqualArrayBuffers(key, testKey.pubKey);
});
@ -34,7 +35,7 @@ function testIdentityKeyStore(store, registrationId, identityKey) {
});
describe('isTrustedIdentity', function() {
it('returns true if a key is trusted', function(done) {
store.saveIdentity(number, testKey.pubKey).then(function() {
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
store.isTrustedIdentity(number, testKey.pubKey).then(function(trusted) {
if (trusted) {
done();
@ -46,7 +47,7 @@ function testIdentityKeyStore(store, registrationId, identityKey) {
});
it('returns false if a key is untrusted', function(done) {
var newIdentity = libsignal.crypto.getRandomBytes(33);
store.saveIdentity(number, testKey.pubKey).then(function() {
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
store.isTrustedIdentity(number, newIdentity).then(function(trusted) {
if (trusted) {
done(new Error('Wrong value for untrusted key'));

View File

@ -56,8 +56,10 @@ SignalProtocolStore.prototype = {
if (identifier === null || identifier === undefined)
throw new Error("Tried to put identity key for undefined/null key");
var existing = this.get('identityKey' + identifier);
this.put('identityKey' + identifier, identityKey)
var address = new libsignal.SignalProtocolAddress.fromString(identifier);
var existing = this.get('identityKey' + address.getName());
this.put('identityKey' + address.getName(), identityKey)
if (existing && util.toString(identityKey) !== util.toString(existing)) {
return Promise.resolve(true);

View File

@ -408,7 +408,7 @@ describe('SessionCipher', function() {
}).then(function() {
return generateIdentity(bobStore);
}).then(function() {
return aliceStore.saveIdentity(BOB_ADDRESS.getName(), bobStore.get('identityKey').pubKey);
return aliceStore.saveIdentity(BOB_ADDRESS.toString(), bobStore.get('identityKey').pubKey);
}).then(function() {
done();
});