2015-04-01 20:08:09 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-21 23:45:21 +00:00
|
|
|
describe("SignalProtocolStore", function() {
|
2017-06-29 02:39:55 +00:00
|
|
|
var identifier = '+5558675309';
|
|
|
|
var store;
|
|
|
|
var identityKey;
|
|
|
|
var testKey;
|
|
|
|
|
2017-06-14 17:40:21 +00:00
|
|
|
before(function(done) {
|
2017-06-29 02:39:55 +00:00
|
|
|
store = textsecure.storage.protocol;
|
|
|
|
identityKey = {
|
|
|
|
pubKey: libsignal.crypto.getRandomBytes(33),
|
|
|
|
privKey: libsignal.crypto.getRandomBytes(32),
|
|
|
|
};
|
|
|
|
testKey = {
|
|
|
|
pubKey: libsignal.crypto.getRandomBytes(33),
|
|
|
|
privKey: libsignal.crypto.getRandomBytes(32),
|
|
|
|
};
|
|
|
|
|
2017-06-14 17:40:21 +00:00
|
|
|
storage.put('registrationId', 1337);
|
|
|
|
storage.put('identityKey', identityKey);
|
|
|
|
storage.fetch().then(done, done);
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('getLocalRegistrationId', function() {
|
|
|
|
it('retrieves my registration id', function(done) {
|
|
|
|
store.getLocalRegistrationId().then(function(reg) {
|
|
|
|
assert.strictEqual(reg, 1337);
|
|
|
|
}).then(done, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('getIdentityKeyPair', function() {
|
|
|
|
it('retrieves my identity key', function(done) {
|
|
|
|
store.getIdentityKeyPair().then(function(key) {
|
|
|
|
assertEqualArrayBuffers(key.pubKey, identityKey.pubKey);
|
|
|
|
assertEqualArrayBuffers(key.privKey, identityKey.privKey);
|
|
|
|
}).then(done,done);
|
|
|
|
});
|
|
|
|
});
|
2017-06-13 20:57:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var IdentityKeyRecord = Backbone.Model.extend({
|
|
|
|
database: Whisper.Database,
|
|
|
|
storeName: 'identityKeys'
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('saveIdentity', function() {
|
|
|
|
var record = new IdentityKeyRecord({id: identifier});
|
2017-06-29 03:59:15 +00:00
|
|
|
var address = new libsignal.SignalProtocolAddress(identifier, 1);
|
2017-06-14 17:40:21 +00:00
|
|
|
|
|
|
|
it('stores identity keys', function(done) {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
|
2017-06-14 17:40:21 +00:00
|
|
|
return store.loadIdentityKey(identifier).then(function(key) {
|
|
|
|
assertEqualArrayBuffers(key, testKey.pubKey);
|
2015-07-22 19:48:08 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
2015-07-22 19:48:08 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('allows key changes', function(done) {
|
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
|
|
|
|
store.saveIdentity(address.toString(), newIdentity).then(function() {
|
2017-06-14 17:40:21 +00:00
|
|
|
done();
|
2016-05-04 07:09:44 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).catch(done);
|
2016-05-04 07:09:44 +00:00
|
|
|
});
|
2017-05-31 01:04:03 +00:00
|
|
|
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('When there is no existing key (first use)', function() {
|
|
|
|
before(function(done) {
|
|
|
|
store.removeIdentityKey(identifier).then(function() {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
|
2017-06-14 17:40:21 +00:00
|
|
|
record.fetch().then(function() { done(); });
|
|
|
|
});
|
|
|
|
});
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('marks the key firstUse', function() {
|
|
|
|
assert(record.get('firstUse'));
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('sets the timestamp', function() {
|
|
|
|
assert(record.get('timestamp'));
|
|
|
|
});
|
2017-06-13 20:57:46 +00:00
|
|
|
it('sets the verified status to DEFAULT', function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.DEFAULT);
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('When there is a different existing key (non first use)', function() {
|
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
|
|
|
var oldTimestamp = Date.now();
|
|
|
|
before(function(done) {
|
|
|
|
record.save({
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : oldTimestamp,
|
|
|
|
nonblockingApproval : false,
|
2017-06-13 20:57:46 +00:00
|
|
|
verified : store.VerifiedStatus.DEFAULT
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(function() {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), newIdentity).then(function() {
|
2017-06-14 17:40:21 +00:00
|
|
|
record.fetch().then(function() { done(); });
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('marks the key not firstUse', function() {
|
|
|
|
assert(!record.get('firstUse'));
|
|
|
|
});
|
|
|
|
it('updates the timestamp', function() {
|
|
|
|
assert.notEqual(record.get('timestamp'), oldTimestamp);
|
|
|
|
});
|
2017-06-13 20:57:46 +00:00
|
|
|
|
|
|
|
describe('The previous verified status was DEFAULT', function() {
|
|
|
|
before(function(done) {
|
|
|
|
record.save({
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : oldTimestamp,
|
|
|
|
nonblockingApproval : false,
|
|
|
|
verified : store.VerifiedStatus.DEFAULT
|
|
|
|
}).then(function() {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), newIdentity).then(function() {
|
2017-06-13 20:57:46 +00:00
|
|
|
record.fetch().then(function() { done(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('sets the new key to unverified', function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.DEFAULT);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('The previous verified status was VERIFIED', function() {
|
|
|
|
before(function(done) {
|
|
|
|
record.save({
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : oldTimestamp,
|
|
|
|
nonblockingApproval : false,
|
|
|
|
verified : store.VerifiedStatus.VERIFIED
|
|
|
|
}).then(function() {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), newIdentity).then(function() {
|
2017-06-13 20:57:46 +00:00
|
|
|
record.fetch().then(function() { done(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('sets the new key to unverified', function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.UNVERIFIED);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('The previous verified status was UNVERIFIED', function() {
|
|
|
|
before(function(done) {
|
|
|
|
record.save({
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : oldTimestamp,
|
|
|
|
nonblockingApproval : false,
|
|
|
|
verified : store.VerifiedStatus.UNVERIFIED
|
|
|
|
}).then(function() {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), newIdentity).then(function() {
|
2017-06-13 20:57:46 +00:00
|
|
|
record.fetch().then(function() { done(); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('sets the new key to unverified', function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.UNVERIFIED);
|
|
|
|
});
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('When the key has not changed', function() {
|
|
|
|
var oldTimestamp = Date.now();
|
|
|
|
before(function(done) {
|
|
|
|
record.save({
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
timestamp : oldTimestamp,
|
|
|
|
nonblockingApproval : false,
|
2017-06-13 20:57:46 +00:00
|
|
|
verified : store.VerifiedStatus.DEFAULT
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(function() { done(); });
|
|
|
|
});
|
|
|
|
describe('If it is marked firstUse', function() {
|
2017-05-31 01:04:03 +00:00
|
|
|
before(function(done) {
|
2017-06-14 17:40:21 +00:00
|
|
|
record.save({ firstUse: true }).then(function() { done(); });
|
|
|
|
});
|
|
|
|
it('nothing changes', function(done) {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), testKey.pubKey, true).then(function() {
|
2017-06-14 17:40:21 +00:00
|
|
|
record.fetch().then(function() {
|
|
|
|
assert(!record.get('nonblockingApproval'));
|
|
|
|
assert.strictEqual(record.get('timestamp'), oldTimestamp);
|
|
|
|
done();
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('If it is not marked firstUse', function() {
|
2017-05-31 01:04:03 +00:00
|
|
|
before(function(done) {
|
2017-06-14 17:40:21 +00:00
|
|
|
record.save({ firstUse: false }).then(function() { done(); });
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('If nonblocking approval is required', function() {
|
2017-07-03 22:16:52 +00:00
|
|
|
var now;
|
2017-06-17 22:41:42 +00:00
|
|
|
before(function(done) {
|
2017-07-03 22:16:52 +00:00
|
|
|
now = Date.now();
|
2017-06-17 22:41:42 +00:00
|
|
|
record.save({ timestamp: now }).then(function() { done(); });
|
|
|
|
});
|
2017-06-13 20:57:46 +00:00
|
|
|
it('sets non-blocking approval', function(done) {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), testKey.pubKey, true).then(function() {
|
2017-05-31 01:04:03 +00:00
|
|
|
record.fetch().then(function() {
|
2017-06-13 20:57:46 +00:00
|
|
|
assert.strictEqual(record.get('nonblockingApproval'), true);
|
2017-06-17 22:41:42 +00:00
|
|
|
assert.strictEqual(record.get('timestamp'), now);
|
2017-06-14 17:40:21 +00:00
|
|
|
assert.strictEqual(record.get('firstUse'), false);
|
2017-05-31 01:04:03 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-13 20:57:46 +00:00
|
|
|
describe('saveIdentityWithAttributes', function() {
|
2017-06-29 02:39:55 +00:00
|
|
|
var now;
|
|
|
|
var record;
|
|
|
|
var validAttributes;
|
|
|
|
|
2017-06-13 20:57:46 +00:00
|
|
|
before(function(done) {
|
2017-06-29 02:39:55 +00:00
|
|
|
now = Date.now();
|
|
|
|
record = new IdentityKeyRecord({id: identifier});
|
|
|
|
validAttributes = {
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : now,
|
|
|
|
verified : store.VerifiedStatus.VERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
};
|
|
|
|
|
2017-06-13 20:57:46 +00:00
|
|
|
store.removeIdentityKey(identifier).then(function() { done(); });
|
|
|
|
});
|
|
|
|
describe('with valid attributes', function() {
|
|
|
|
before(function(done) {
|
|
|
|
store.saveIdentityWithAttributes(identifier, validAttributes).then(function() {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
record.fetch().then(resolve);
|
|
|
|
});
|
|
|
|
}).then(done, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('publicKey is saved', function() {
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
|
|
|
});
|
|
|
|
it('firstUse is saved', function() {
|
|
|
|
assert.strictEqual(record.get('firstUse'), true);
|
|
|
|
});
|
|
|
|
it('timestamp is saved', function() {
|
|
|
|
assert.strictEqual(record.get('timestamp'), now);
|
|
|
|
});
|
|
|
|
it('verified is saved', function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
|
|
|
});
|
|
|
|
it('nonblockingApproval is saved', function() {
|
|
|
|
assert.strictEqual(record.get('nonblockingApproval'), false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('with invalid attributes', function() {
|
|
|
|
var attributes;
|
|
|
|
beforeEach(function() {
|
|
|
|
attributes = _.clone(validAttributes);
|
|
|
|
});
|
|
|
|
|
|
|
|
function testInvalidAttributes(done) {
|
|
|
|
store.saveIdentityWithAttributes(identifier, attributes).then(function() {
|
|
|
|
done(new Error("saveIdentityWithAttributes should have failed"));
|
|
|
|
}, function() {
|
|
|
|
done(); // good. we expect to fail with invalid attributes.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
it('rejects an invalid publicKey', function(done) {
|
|
|
|
attributes.publicKey = 'a string';
|
|
|
|
testInvalidAttributes(done);
|
|
|
|
});
|
|
|
|
it('rejects invalid firstUse', function(done) {
|
|
|
|
attributes.firstUse = 0;
|
|
|
|
testInvalidAttributes(done);
|
|
|
|
});
|
|
|
|
it('rejects invalid timestamp', function(done) {
|
|
|
|
attributes.timestamp = NaN;
|
|
|
|
testInvalidAttributes(done);
|
|
|
|
});
|
|
|
|
it('rejects invalid verified', function(done) {
|
|
|
|
attributes.verified = null;
|
|
|
|
testInvalidAttributes(done);
|
|
|
|
});
|
|
|
|
it('rejects invalid nonblockingApproval', function(done) {
|
|
|
|
attributes.nonblockingApproval = 0;
|
|
|
|
testInvalidAttributes(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('setApproval', function() {
|
|
|
|
var record = new IdentityKeyRecord({id: identifier});
|
|
|
|
function fetchRecord() {
|
|
|
|
return new Promise(function(resolve) {
|
|
|
|
record.fetch().then(resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
it ('sets nonblockingApproval', function(done) {
|
|
|
|
store.setApproval(identifier, true).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('nonblockingApproval'), true);
|
|
|
|
}).then(done, done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('setVerified', function() {
|
2017-06-17 03:21:16 +00:00
|
|
|
var record;
|
|
|
|
function saveRecordDefault() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.DEFAULT,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
record.save().then(resolve, reject);
|
|
|
|
});
|
|
|
|
}
|
2017-06-13 20:57:46 +00:00
|
|
|
function fetchRecord() {
|
2017-06-17 03:21:16 +00:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
record.fetch().then(resolve, reject);
|
2017-06-13 20:57:46 +00:00
|
|
|
});
|
|
|
|
}
|
2017-06-17 03:21:16 +00:00
|
|
|
describe('with no public key argument', function() {
|
|
|
|
before(saveRecordDefault);
|
|
|
|
it ('updates the verified status', function() {
|
|
|
|
return store.setVerified(
|
|
|
|
identifier, store.VerifiedStatus.VERIFIED
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('with the current public key', function() {
|
|
|
|
before(saveRecordDefault);
|
|
|
|
it ('updates the verified status', function() {
|
|
|
|
return store.setVerified(
|
|
|
|
identifier, store.VerifiedStatus.VERIFIED, testKey.pubKey
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('with a mismatching public key', function() {
|
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
|
|
|
before(saveRecordDefault);
|
|
|
|
it ('does not change the record.', function() {
|
|
|
|
return store.setVerified(
|
|
|
|
identifier, store.VerifiedStatus.VERIFIED, newIdentity
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.DEFAULT);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
|
|
|
});
|
|
|
|
});
|
2017-06-13 20:57:46 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-17 03:56:06 +00:00
|
|
|
describe('processVerifiedMessage', function() {
|
|
|
|
var record;
|
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
2017-06-29 02:39:55 +00:00
|
|
|
var keychangeTriggered;
|
|
|
|
|
|
|
|
function wrapDeferred(deferred) {
|
2017-06-17 03:56:06 +00:00
|
|
|
return new Promise(function(resolve, reject) {
|
2017-06-29 02:39:55 +00:00
|
|
|
return deferred.then(resolve, reject);
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
}
|
2017-06-29 02:39:55 +00:00
|
|
|
function fetchRecord() {
|
|
|
|
return wrapDeferred(record.fetch());
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
keychangeTriggered = 0;
|
|
|
|
store.bind('keychange', function() {
|
|
|
|
keychangeTriggered++;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
afterEach(function() {
|
|
|
|
store.unbind('keychange');
|
|
|
|
});
|
|
|
|
|
2017-06-17 03:56:06 +00:00
|
|
|
describe('when the new verified status is DEFAULT', function() {
|
|
|
|
describe('when there is no existing record', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({ id: identifier });
|
2017-06-29 02:39:55 +00:00
|
|
|
return wrapDeferred(record.destroy());
|
2017-06-19 23:34:00 +00:00
|
|
|
});
|
2017-06-17 03:56:06 +00:00
|
|
|
|
|
|
|
it ('does nothing', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.DEFAULT, newIdentity
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
// fetchRecord resolved so there is a record.
|
|
|
|
// Bad.
|
|
|
|
throw new Error("processVerifiedMessage should not save new records");
|
|
|
|
}, function() {
|
2017-06-19 23:34:00 +00:00
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
describe('when the record exists', function() {
|
|
|
|
describe('when the existing key is different', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.VERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return wrapDeferred(record.save());
|
|
|
|
});
|
2017-06-19 23:34:00 +00:00
|
|
|
|
2017-06-29 02:39:55 +00:00
|
|
|
it ('saves the new identity and marks it DEFAULT', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.DEFAULT, newIdentity
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.DEFAULT);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
|
|
|
|
assert.strictEqual(keychangeTriggered, 1);
|
|
|
|
});
|
2017-06-19 23:34:00 +00:00
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
});
|
|
|
|
describe('when the existing key is the same but VERIFIED', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.VERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return wrapDeferred(record.save());
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
|
|
|
|
it ('updates the verified status', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.DEFAULT, testKey.pubKey
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.DEFAULT);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
|
|
|
});
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
describe('when the existing key is the same and already DEFAULT', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.DEFAULT,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return wrapDeferred(record.save());
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('does not hang', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.DEFAULT, testKey.pubKey
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('when the new verified status is UNVERIFIED', function() {
|
|
|
|
describe('when there is no existing record', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({ id: identifier });
|
|
|
|
return wrapDeferred(record.destroy());
|
2017-06-19 23:34:00 +00:00
|
|
|
});
|
|
|
|
|
2017-06-29 02:39:55 +00:00
|
|
|
it ('saves the new identity and marks it verified', function() {
|
2017-06-17 03:56:06 +00:00
|
|
|
return store.processVerifiedMessage(
|
2017-06-29 02:39:55 +00:00
|
|
|
identifier, store.VerifiedStatus.UNVERIFIED, newIdentity
|
2017-06-17 03:56:06 +00:00
|
|
|
).then(fetchRecord).then(function() {
|
2017-06-29 02:39:55 +00:00
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.UNVERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
|
2017-06-19 23:34:00 +00:00
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
describe('when the record exists', function() {
|
|
|
|
describe('when the existing key is different', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.VERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return wrapDeferred(record.save());
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('saves the new identity and marks it UNVERIFIED', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.UNVERIFIED, newIdentity
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.UNVERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
|
|
|
|
assert.strictEqual(keychangeTriggered, 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('when the key exists and is DEFAULT', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.DEFAULT,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return wrapDeferred(record.save());
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('updates the verified status', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.UNVERIFIED, testKey.pubKey
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.UNVERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('when the key exists and is already UNVERIFIED', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.UNVERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return wrapDeferred(record.save());
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('does not hang', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.UNVERIFIED, testKey.pubKey
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
describe('when the new verified status is VERIFIED', function() {
|
|
|
|
describe('when there is no existing record', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({ id: identifier });
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
record.destroy().then(resolve, reject);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('saves the new identity and marks it verified', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.VERIFIED, newIdentity
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
|
2017-07-04 00:31:57 +00:00
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-19 23:34:00 +00:00
|
|
|
describe('when the record exists', function() {
|
2017-06-17 03:56:06 +00:00
|
|
|
describe('when the existing key is different', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.VERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
return wrapDeferred(record.save());
|
2017-06-19 23:34:00 +00:00
|
|
|
});
|
|
|
|
|
2017-06-29 02:39:55 +00:00
|
|
|
it ('saves the new identity and marks it VERIFIED', function() {
|
2017-06-17 03:56:06 +00:00
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.VERIFIED, newIdentity
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), newIdentity);
|
2017-06-19 23:34:00 +00:00
|
|
|
assert.strictEqual(keychangeTriggered, 1);
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
describe('when the existing key is the same but UNVERIFIED', function() {
|
2017-06-17 03:56:06 +00:00
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.UNVERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
return wrapDeferred(record.save());
|
2017-06-19 23:34:00 +00:00
|
|
|
});
|
2017-06-17 03:56:06 +00:00
|
|
|
|
|
|
|
it ('saves the identity and marks it verified', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.VERIFIED, testKey.pubKey
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
|
|
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
2017-06-19 23:34:00 +00:00
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
describe('when the existing key is the same and already VERIFIED', function() {
|
|
|
|
before(function() {
|
|
|
|
record = new IdentityKeyRecord({
|
|
|
|
id : identifier,
|
|
|
|
publicKey : testKey.pubKey,
|
|
|
|
firstUse : true,
|
|
|
|
timestamp : Date.now(),
|
|
|
|
verified : store.VerifiedStatus.VERIFIED,
|
|
|
|
nonblockingApproval : false
|
|
|
|
});
|
|
|
|
return wrapDeferred(record.save());
|
|
|
|
});
|
|
|
|
|
|
|
|
it ('does not hang', function() {
|
|
|
|
return store.processVerifiedMessage(
|
|
|
|
identifier, store.VerifiedStatus.VERIFIED, testKey.pubKey
|
|
|
|
).then(fetchRecord).then(function() {
|
|
|
|
assert.strictEqual(keychangeTriggered, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-29 02:39:55 +00:00
|
|
|
|
2017-06-17 03:56:06 +00:00
|
|
|
});
|
2017-06-13 20:57:46 +00:00
|
|
|
describe('getVerified', function() {
|
|
|
|
before(function(done) {
|
|
|
|
store.setVerified(identifier, store.VerifiedStatus.VERIFIED).then(done, done);
|
|
|
|
});
|
|
|
|
it ('resolves to the verified status', function(done) {
|
|
|
|
store.getVerified(identifier).then(function(result) {
|
|
|
|
assert.strictEqual(result, store.VerifiedStatus.VERIFIED);
|
|
|
|
}).then(done, done);
|
|
|
|
});
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('isTrustedIdentity', function() {
|
2017-06-29 03:59:15 +00:00
|
|
|
var address = new libsignal.SignalProtocolAddress(identifier, 1);
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('When invalid direction is given', function(done) {
|
|
|
|
it('should fail', function(done) {
|
|
|
|
store.isTrustedIdentity(identifier, testKey.pubKey).then(function() {
|
|
|
|
done(new Error('isTrustedIdentity should have failed'));
|
|
|
|
}).catch(function(e) {
|
|
|
|
done();
|
2016-05-04 07:09:44 +00:00
|
|
|
});
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2016-05-04 07:09:44 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('When direction is RECEIVING', function() {
|
|
|
|
it('always returns true', function(done) {
|
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
|
2017-06-14 17:40:21 +00:00
|
|
|
store.isTrustedIdentity(identifier, newIdentity, store.Direction.RECEIVING).then(function(trusted) {
|
|
|
|
if (trusted) {
|
|
|
|
done();
|
|
|
|
} else {
|
|
|
|
done(new Error('isTrusted returned false when receiving'));
|
|
|
|
}
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('When direction is SENDING', function() {
|
|
|
|
describe('When there is no existing key (first use)', function() {
|
|
|
|
before(function(done) {
|
|
|
|
store.removeIdentityKey(identifier).then(function() {
|
2017-05-30 22:21:56 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('returns true', function(done) {
|
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
|
|
|
store.isTrustedIdentity(identifier, newIdentity, store.Direction.SENDING).then(function(trusted) {
|
|
|
|
if (trusted) {
|
|
|
|
done();
|
|
|
|
} else {
|
|
|
|
done(new Error('isTrusted returned false on first use'));
|
|
|
|
}
|
|
|
|
}).catch(done);
|
2017-05-30 22:21:56 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('When there is an existing key', function() {
|
|
|
|
before(function(done) {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), testKey.pubKey).then(function() {
|
2017-06-14 17:40:21 +00:00
|
|
|
done();
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('When the existing key is different', function() {
|
|
|
|
it('returns false', function(done) {
|
2016-05-08 00:49:45 +00:00
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
2017-05-31 01:04:03 +00:00
|
|
|
store.isTrustedIdentity(identifier, newIdentity, store.Direction.SENDING).then(function(trusted) {
|
2017-06-14 17:40:21 +00:00
|
|
|
if (trusted) {
|
|
|
|
done(new Error('isTrusted returned true on untrusted key'));
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
2017-05-31 01:04:03 +00:00
|
|
|
}).catch(done);
|
|
|
|
});
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
describe('When the existing key matches the new key', function() {
|
|
|
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
2017-05-31 01:04:03 +00:00
|
|
|
before(function(done) {
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), newIdentity).then(function() {
|
2017-05-31 01:04:03 +00:00
|
|
|
done();
|
2017-05-30 22:21:56 +00:00
|
|
|
});
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('returns false if blocking approval is required', function(done) {
|
|
|
|
storage.put('safety-numbers-approval', true);
|
|
|
|
store.isTrustedIdentity(identifier, newIdentity, store.Direction.SENDING).then(function(trusted) {
|
|
|
|
if (trusted) {
|
|
|
|
done(new Error('isTrusted returned true on untrusted key'));
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
}).catch(done);
|
2017-05-31 01:04:03 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('returns false if keys match but nonblocking approval is required', function(done) {
|
|
|
|
storage.put('safety-numbers-approval', false);
|
|
|
|
store.isTrustedIdentity(identifier, newIdentity, store.Direction.SENDING).then(function(trusted) {
|
|
|
|
if (trusted) {
|
|
|
|
done(new Error('isTrusted returned true on untrusted key'));
|
|
|
|
} else {
|
2017-05-31 01:04:03 +00:00
|
|
|
done();
|
2017-06-14 17:40:21 +00:00
|
|
|
}
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
it('returns true if neither blocking nor nonblocking approval is required', function(done) {
|
|
|
|
storage.put('safety-numbers-approval', false);
|
2017-06-29 03:59:15 +00:00
|
|
|
store.saveIdentity(address.toString(), newIdentity, true).then(function() {
|
2017-05-31 01:04:03 +00:00
|
|
|
store.isTrustedIdentity(identifier, newIdentity, store.Direction.SENDING).then(function(trusted) {
|
|
|
|
if (trusted) {
|
2017-06-14 17:40:21 +00:00
|
|
|
done();
|
2017-05-31 01:04:03 +00:00
|
|
|
} else {
|
2017-06-14 17:40:21 +00:00
|
|
|
done(new Error('isTrusted returned false on an approved key'));
|
2017-05-31 01:04:03 +00:00
|
|
|
}
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
2017-05-30 22:21:56 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
2015-04-01 20:08:09 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('storePreKey', function() {
|
|
|
|
it('stores prekeys', function(done) {
|
|
|
|
store.storePreKey(1, testKey).then(function() {
|
|
|
|
return store.loadPreKey(1).then(function(key) {
|
|
|
|
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
|
|
|
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('removePreKey', function() {
|
|
|
|
before(function(done) {
|
|
|
|
store.storePreKey(2, testKey).then(done);
|
2015-04-01 20:08:09 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
it('deletes prekeys', function(done) {
|
|
|
|
store.removePreKey(2, testKey).then(function() {
|
|
|
|
return store.loadPreKey(2).then(function(key) {
|
|
|
|
assert.isUndefined(key);
|
2015-04-01 20:08:09 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
2015-04-01 20:08:09 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('storeSignedPreKey', function() {
|
|
|
|
it('stores signed prekeys', function(done) {
|
|
|
|
store.storeSignedPreKey(3, testKey).then(function() {
|
|
|
|
return store.loadSignedPreKey(3).then(function(key) {
|
|
|
|
assertEqualArrayBuffers(key.pubKey, testKey.pubKey);
|
|
|
|
assertEqualArrayBuffers(key.privKey, testKey.privKey);
|
2016-05-04 07:31:32 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('removeSignedPreKey', function() {
|
|
|
|
before(function(done) {
|
|
|
|
store.storeSignedPreKey(4, testKey).then(done);
|
|
|
|
});
|
|
|
|
it('deletes signed prekeys', function(done) {
|
|
|
|
store.removeSignedPreKey(4, testKey).then(function() {
|
|
|
|
return store.loadSignedPreKey(4).then(function(key) {
|
|
|
|
assert.isUndefined(key);
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
2015-04-01 20:08:09 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('storeSession', function() {
|
|
|
|
it('stores sessions', function(done) {
|
|
|
|
var testRecord = "an opaque string";
|
|
|
|
store.storeSession(identifier + '.1', testRecord).then(function() {
|
|
|
|
return store.loadSession(identifier + '.1').then(function(record) {
|
|
|
|
assert.deepEqual(record, testRecord);
|
2015-04-22 02:13:13 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('removeAllSessions', function() {
|
|
|
|
it('removes all sessions for a number', function(done) {
|
|
|
|
var testRecord = "an opaque string";
|
|
|
|
var devices = [1, 2, 3].map(function(deviceId) {
|
|
|
|
return [identifier, deviceId].join('.');
|
|
|
|
});
|
|
|
|
var promise = Promise.resolve();
|
|
|
|
devices.forEach(function(encodedNumber) {
|
|
|
|
promise = promise.then(function() {
|
|
|
|
return store.storeSession(encodedNumber, testRecord + encodedNumber);
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
promise.then(function() {
|
|
|
|
return store.removeAllSessions(identifier).then(function(record) {
|
|
|
|
return Promise.all(devices.map(store.loadSession.bind(store))).then(function(records) {
|
|
|
|
for (var i in records) {
|
|
|
|
assert.isUndefined(records[i]);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).then(done,done);
|
2015-04-22 02:13:13 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('clearSessionStore', function() {
|
|
|
|
it ('clears the session store', function(done) {
|
|
|
|
var testRecord = "an opaque string";
|
|
|
|
store.storeSession(identifier + '.1', testRecord).then(function() {
|
|
|
|
return store.clearSessionStore().then(function() {
|
|
|
|
return store.loadSession(identifier + '.1').then(function(record) {
|
|
|
|
assert.isUndefined(record);
|
|
|
|
});
|
2015-04-22 02:13:13 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
|
|
|
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
describe('getDeviceIds', function() {
|
|
|
|
it('returns deviceIds for a number', function(done) {
|
|
|
|
var testRecord = "an opaque string";
|
|
|
|
var devices = [1, 2, 3].map(function(deviceId) {
|
|
|
|
return [identifier, deviceId].join('.');
|
|
|
|
});
|
|
|
|
var promise = Promise.resolve();
|
|
|
|
devices.forEach(function(encodedNumber) {
|
|
|
|
promise = promise.then(function() {
|
|
|
|
return store.storeSession(encodedNumber, testRecord + encodedNumber);
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
|
|
|
promise.then(function() {
|
|
|
|
return store.getDeviceIds(identifier).then(function(deviceIds) {
|
|
|
|
assert.sameMembers(deviceIds, [1, 2, 3]);
|
2016-05-04 07:30:42 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
}).then(done,done);
|
|
|
|
});
|
|
|
|
it('returns empty array for a number with no device ids', function(done) {
|
|
|
|
return store.getDeviceIds('foo').then(function(deviceIds) {
|
|
|
|
assert.sameMembers(deviceIds,[]);
|
|
|
|
}).then(done,done);
|
2015-04-22 02:13:13 +00:00
|
|
|
});
|
2017-06-14 17:40:21 +00:00
|
|
|
});
|
2015-04-01 20:08:09 +00:00
|
|
|
});
|