fix walletlock tests

This commit is contained in:
Matias Alejo Garcia 2014-09-17 12:10:26 -03:00
commit 1ab7a4f8e8
7 changed files with 122 additions and 176 deletions

View file

@ -118,6 +118,10 @@ Storage.prototype.getSessionId = function(cb) {
}); });
}; };
Storage.prototype.setSessionId = function(sessionId, cb) {
this.sessionStorage.setItem('sessionId', sessionId, cb);
};
Storage.prototype._key = function(walletId, k) { Storage.prototype._key = function(walletId, k) {
return walletId + '::' + k; return walletId + '::' + k;
}; };
@ -285,7 +289,10 @@ Storage.prototype.setFromObj = function(walletId, obj, cb) {
for (var k in obj) { for (var k in obj) {
self.set(walletId, k, obj[k], function() { self.set(walletId, k, obj[k], function() {
if (++i == l) { if (++i == l) {
self.setName(walletId, obj.opts.name, cb); if (obj.opts.name)
self.setName(walletId, obj.opts.name, cb);
else
return cb();
} }
}); });
} }

View file

@ -54,11 +54,13 @@ WalletLock.prototype._isLockedByOther = function(cb) {
WalletLock.prototype._setLock = function(cb) { WalletLock.prototype._setLock = function(cb) {
preconditions.checkArgument(cb); preconditions.checkArgument(cb);
preconditions.checkState(this.sessionId); preconditions.checkState(this.sessionId);
var self = this;
this.storage.setGlobal(this.key, { this.storage.setGlobal(this.key, {
sessionId: this.sessionId, sessionId: this.sessionId,
expireTs: Date.now() + this.timeoutMin * 60 * 1000, expireTs: Date.now() + this.timeoutMin * 60 * 1000,
}, function() { }, function() {
cb(null); cb(null);
}); });
}; };

View file

@ -1,27 +1,33 @@
//localstorage Mock //localstorage Mock
ls = {};
function LocalStorage(opts) {
}
FakeLocalStorage = {}; function FakeLocalStorage() {
FakeLocalStorage.length = 0; this.ls = {};
FakeLocalStorage.removeItem = function(key,cb) { };
delete ls[key]; FakeLocalStorage.prototype.removeItem = function(key, cb) {
delete this.ls[key];
cb(); cb();
}; };
FakeLocalStorage.getItem = function(k,cb) { FakeLocalStorage.prototype.getItem = function(k, cb) {
return cb(ls[k]); return cb(this.ls[k]);
}; };
FakeLocalStorage.allKeys = function(cb) { FakeLocalStorage.prototype.allKeys = function(cb) {
return cb(Object.keys(ls)); return cb(Object.keys(this.ls));
}; };
FakeLocalStorage.setItem = function(k, v,cb) { FakeLocalStorage.prototype.setItem = function(k, v, cb) {
ls[k] = v; this.ls[k] = v;
return cb(); return cb();
}; };
FakeLocalStorage.prototype.clear = function() {
this.ls = {};
}
module.exports = FakeLocalStorage; module.exports = FakeLocalStorage;
module.exports.storageParams = {
storage: new FakeLocalStorage(),
sessionStorage: new FakeLocalStorage(),
};

View file

@ -33,10 +33,7 @@ var walletConfig = {
spendUnconfirmed: true, spendUnconfirmed: true,
reconnectDelay: 100, reconnectDelay: 100,
networkName: 'testnet', networkName: 'testnet',
storage: { storage: require('./mocks/FakeLocalStorage').storageParams,
storage: localMock,
sessionStorage: sessionMock,
}
}; };
var getNewEpk = function() { var getNewEpk = function() {
@ -48,6 +45,7 @@ var getNewEpk = function() {
}; };
describe('PayPro (in Wallet) model', function() { describe('PayPro (in Wallet) model', function() {
if (!is_browser) { if (!is_browser) {
var createW = function(N, conf) { var createW = function(N, conf) {
var c = JSON.parse(JSON.stringify(conf || walletConfig)); var c = JSON.parse(JSON.stringify(conf || walletConfig));
@ -71,6 +69,7 @@ describe('PayPro (in Wallet) model', function() {
}); });
var storage = new Storage(walletConfig.storage); var storage = new Storage(walletConfig.storage);
storage.setPassphrase('xxx');
var network = new Network(walletConfig.network); var network = new Network(walletConfig.network);
var blockchain = new Blockchain(walletConfig.blockchain); var blockchain = new Blockchain(walletConfig.blockchain);
c.storage = storage; c.storage = storage;

View file

@ -7,99 +7,84 @@ var Storage = copay.Storage;
var fakeWallet = 'fake-wallet-id'; var fakeWallet = 'fake-wallet-id';
var timeStamp = Date.now(); var timeStamp = Date.now();
var localMock = require('./mocks/FakeLocalStorage');
var sessionMock = require('./mocks/FakeLocalStorage');
describe('Storage model', function() { describe('Storage model', function() {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
});
s.setPassphrase('mysupercoolpassword');
it('should create an instance', function() { var s;
var s2 = new Storage({ beforeEach(function() {
storage: localMock, s = new Storage(require('./mocks/FakeLocalStorage').storageParams);
sessionStorage: sessionMock, s.setPassphrase('mysupercoolpassword');
s.storage.clear();
s.sessionStorage.clear();
}); });
should.exist(s2);
});
it('should fail when encrypting without a password', function() { it('should create an instance', function() {
var s2 = new Storage({ var s2 = new Storage(require('./mocks/FakeLocalStorage').storageParams);
storage: localMock, should.exist(s2);
sessionStorage: sessionMock,
}); });
(function() { it('should fail when encrypting without a password', function() {
s2.set(fakeWallet, timeStamp, 1, function() {}); var s2 = new Storage(require('./mocks/FakeLocalStorage').storageParams);
}).should.throw('NOPASSPHRASE'); (function() {
}); s2.set(fakeWallet, timeStamp, 1, function() {});
it('should be able to encrypt and decrypt', function(done) { }).should.throw('NOPASSPHRASE');
s._write(fakeWallet + timeStamp, 'value', function() {
s._read(fakeWallet + timeStamp, function(v) {
v.should.equal('value');
localMock.removeItem(fakeWallet + timeStamp, done);
});
}); });
}); it('should be able to encrypt and decrypt', function(done) {
it('should be able to set a value', function(done) { s._write(fakeWallet + timeStamp, 'value', function() {
s.set(fakeWallet, timeStamp, 1, function() { s._read(fakeWallet + timeStamp, function(v) {
localMock.removeItem(fakeWallet + '::' + timeStamp, done); v.should.equal('value');
}); done();
});
var getSetData = [
1, 1000, -15, -1000,
0.1, -0.5, -0.5e-10, Math.PI,
'hi', 'auydoaiusyodaisudyoa', '0b5b8556a0c2ce828c9ccfa58b3dd0a1ae879b9b',
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC', 'OP_DUP OP_HASH160 80ad90d4035', [1, 2, 3, 4, 5, 6], {
x: 1,
y: 2
}, {
x: 'hi',
y: null
}, {
a: {},
b: [],
c: [1, 2, 'hi']
},
null
];
getSetData.forEach(function(obj) {
it('should be able to set a value and get it for ' + JSON.stringify(obj), function(done) {
s.set(fakeWallet, timeStamp, obj, function() {
s.get(fakeWallet, timeStamp, function(obj2) {
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
localMock.removeItem(fakeWallet + '::' + timeStamp, done);
}); });
}); });
}); });
}); it('should be able to set a value', function(done) {
s.set(fakeWallet, timeStamp, 1, function() {
done();
});
});
var getSetData = [
1, 1000, -15, -1000,
0.1, -0.5, -0.5e-10, Math.PI,
'hi', 'auydoaiusyodaisudyoa', '0b5b8556a0c2ce828c9ccfa58b3dd0a1ae879b9b',
'1CjPR7Z5ZSyWk6WtXvSFgkptmpoi4UM9BC', 'OP_DUP OP_HASH160 80ad90d4035', [1, 2, 3, 4, 5, 6], {
x: 1,
y: 2
}, {
x: 'hi',
y: null
}, {
a: {},
b: [],
c: [1, 2, 'hi']
},
null
];
getSetData.forEach(function(obj) {
it('should be able to set a value and get it for ' + JSON.stringify(obj), function(done) {
s.set(fakeWallet, timeStamp, obj, function() {
s.get(fakeWallet, timeStamp, function(obj2) {
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
done();
});
});
});
});
describe('#export', function() { describe('#export', function() {
it('should export the encrypted wallet', function(done) { it('should export the encrypted wallet', function(done) {
var storage = new Storage({ s.set(fakeWallet, timeStamp, 'testval', function() {
storage: localMock,
sessionStorage: sessionMock,
password: 'password',
});
storage.set(fakeWallet, timeStamp, 'testval', function() {
var obj = { var obj = {
test: 'testval' test: 'testval'
}; };
var encrypted = storage.export(obj); var encrypted = s.export(obj);
encrypted.length.should.be.greaterThan(10); encrypted.length.should.be.greaterThan(10);
localMock.removeItem(fakeWallet + '::' + timeStamp, done); done();
}); });
}); });
}); });
describe('#remove', function() { describe('#remove', function() {
it('should remove an item', function(done) { it('should remove an item', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.set('1', "hola", 'juan', function() { s.set('1', "hola", 'juan', function() {
s.get('1', 'hola', function(v) { s.get('1', 'hola', function(v) {
v.should.equal('juan'); v.should.equal('juan');
@ -117,11 +102,6 @@ describe('Storage model', function() {
describe('#getWalletIds', function() { describe('#getWalletIds', function() {
it('should get wallet ids', function(done) { it('should get wallet ids', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.set('1', "hola", 'juan', function() { s.set('1', "hola", 'juan', function() {
s.set('2', "hola", 'juan', function() { s.set('2', "hola", 'juan', function() {
s.getWalletIds(function(v) { s.getWalletIds(function(v) {
@ -135,11 +115,6 @@ describe('Storage model', function() {
describe('#getName #setName', function() { describe('#getName #setName', function() {
it('should get/set names', function(done) { it('should get/set names', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.setName(1, 'hola', function() { s.setName(1, 'hola', function() {
s.getName(1, function(v) { s.getName(1, function(v) {
v.should.equal('hola'); v.should.equal('hola');
@ -151,11 +126,6 @@ describe('Storage model', function() {
describe('#getLastOpened #setLastOpened', function() { describe('#getLastOpened #setLastOpened', function() {
it('should get/set last opened', function() { it('should get/set last opened', function() {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.setLastOpened('hey', function() { s.setLastOpened('hey', function() {
s.getLastOpened(function(v) { s.getLastOpened(function(v) {
v.should.equal('hey'); v.should.equal('hey');
@ -167,11 +137,6 @@ describe('Storage model', function() {
if (is_browser) { if (is_browser) {
describe('#getSessionId', function() { describe('#getSessionId', function() {
it('should get SessionId', function(done) { it('should get SessionId', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.getSessionId(function(sid) { s.getSessionId(function(sid) {
should.exist(sid); should.exist(sid);
s.getSessionId(function(sid2) { s.getSessionId(function(sid2) {
@ -185,11 +150,6 @@ describe('Storage model', function() {
describe('#getWallets', function() { describe('#getWallets', function() {
it('should retreive wallets from storage', function(done) { it('should retreive wallets from storage', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.set('1', "hola", 'juan', function() { s.set('1', "hola", 'juan', function() {
s.set('2', "hola", 'juan', function() { s.set('2', "hola", 'juan', function() {
s.setName(1, 'hola', function() { s.setName(1, 'hola', function() {
@ -208,14 +168,8 @@ describe('Storage model', function() {
}); });
}); });
}); });
}); }); describe('#deleteWallet', function() {
describe('#deleteWallet', function() {
it('should fail to delete a unexisting wallet', function(done) { it('should fail to delete a unexisting wallet', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.set('1', "hola", 'juan', function() { s.set('1', "hola", 'juan', function() {
s.set('2', "hola", 'juan', function() { s.set('2', "hola", 'juan', function() {
s.deleteWallet('3', function(err) { s.deleteWallet('3', function(err) {
@ -227,11 +181,6 @@ describe('Storage model', function() {
}); });
it('should delete a wallet', function(done) { it('should delete a wallet', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.set('1', "hola", 'juan', function() { s.set('1', "hola", 'juan', function() {
s.set('2', "hola", 'juan', function() { s.set('2', "hola", 'juan', function() {
s.deleteWallet('1', function(err) { s.deleteWallet('1', function(err) {
@ -252,11 +201,6 @@ describe('Storage model', function() {
describe('#setFromObj', function() { describe('#setFromObj', function() {
it('set localstorage from an object', function(done) { it('set localstorage from an object', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.setFromObj('id1', { s.setFromObj('id1', {
'key': 'val', 'key': 'val',
'opts': { 'opts': {
@ -274,12 +218,6 @@ describe('Storage model', function() {
describe('#globals', function() { describe('#globals', function() {
it('should set, get and remove keys', function(done) { it('should set, get and remove keys', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.setGlobal('a', { s.setGlobal('a', {
b: 1 b: 1
}, function() { }, function() {
@ -302,11 +240,6 @@ describe('Storage model', function() {
describe('session storage', function() { describe('session storage', function() {
it('should get a session ID', function(done) { it('should get a session ID', function(done) {
var s = new Storage({
storage: localMock,
sessionStorage: sessionMock,
password: 'password'
});
s.getSessionId(function(s) { s.getSessionId(function(s) {
should.exist(s); should.exist(s);
s.length.should.equal(16); s.length.should.equal(16);
@ -317,12 +250,14 @@ describe('Storage model', function() {
}); });
describe('#import', function() { describe('#import', function() {
it('should not be able to decrypt with wrong password', function() {
s.setPassphrase('xxx');
var wo = s.import(encryptedLegacy1);
should.not.exist(wo);
});
it('should be able to decrypt an old backup', function() { it('should be able to decrypt an old backup', function() {
var s = new Storage({ s.setPassphrase(legacyPassword1);
storage: localMock,
sessionStorage: sessionMock,
password: legacyPassword1 ,
});
var wo = s.import(encryptedLegacy1); var wo = s.import(encryptedLegacy1);
should.exist(wo); should.exist(wo);
wo.opts.id.should.equal('48ba2f1ffdfe9708'); wo.opts.id.should.equal('48ba2f1ffdfe9708');
@ -353,5 +288,3 @@ describe('Storage model', function() {
var legacyPassword1 = '1DUpLRbuVpgLkcEY8gY8iod/SmA7+OheGZJ9PtvmTlvNE0FkEWpCKW9STdzXYJqbn0wiAapE4ojHNYj2hjYYAQ=='; var legacyPassword1 = '1DUpLRbuVpgLkcEY8gY8iod/SmA7+OheGZJ9PtvmTlvNE0FkEWpCKW9STdzXYJqbn0wiAapE4ojHNYj2hjYYAQ==';
var encryptedLegacy1 = 'U2FsdGVkX19yGM1uBAIzQa8Po/dvUicmxt1YyRk/S97PcZ6I6rHMp9dMagIrehg4Qd6JHn/ustmFHS7vmBYj0EBpf6rdXiQezaWnVAJS9/xYjAO36EFUbl+NmUanuwujAxgYdSP/sNssRLeInvExmZYW993EEclxkwL6YUyX66kKsxGQo2oWng0NreBJNhFmrbOEWeFje2PiWP57oUjKsurFzwpluAAarUTYSLud+nXeabC7opzOP5yqniWBMJz0Ou8gpNCWCMhG/P9F9ccVPY7juyd0Hf41FVse8nd2++axKB57+paozLdO+HRfV6zkMqC3h8gWY7LkS75j3bvqcTw9LhXmzE0Sz21n9yDnRpA4chiAvtwQvvBGgj1pFMKhNQU6Obac9ZwKYzUTgdDn3Uzg1UlDzgyOh9S89rbRTV84WB+hXwhuVluWzbNNYV3vXe5PFrocVktIrtS3xQh+k/7my4A6/gRRrzNYpKrUASJqDS/9u9WBkG35xD63J/qXjtG2M0YPwbI57BK1IK4K510b8V72lz5U2XQrIC4ldBwni1rpSavwCJV9xF6hUdOmNV8fZsVHP0NeN1PYlLkSb2QgfuoWnkcsJerwuFR7GZC/i6efrswtpO0wMEQr/J0CLbeXlHAru6xxjCBhWoJvZpMGw72zgnDLoyMNsEVglNhx/VlV9ZMYkkdaEYAxPOEIyZdQ5MS+2jEAlXf818n/xzJSVrniCn9be8EPePvkw35pivprvy09vbW4cKsWBKvgIyoT6A3OhUOCCS8E9cg0WAjjav2EymrbKmGWRHaiD+EoJqaDg6s20zhHn1YEa/YwvGGSB5+Hg8baLHD8ZASvxz4cFFAAVZrBUedRFgHzqwaMUlFXLgueivWUj7RXlIw6GuNhLoo1QkhZMacf23hrFxxQYvGBRw1hekBuDmcsGWljA28udBxBd5f9i+3gErttMLJ6IPaud590uvrxRIclu0Sz9R2EQX64YJxqDtLpMY0PjddSMu8vaDRpK9/ZSrnz/xrXsyabaafz4rE/ItFXjwFUFkvtmuauHTz6nmuKjVfxvNLNAiKb/gI7vQyUhnTbKIApe7XyJsjedNDtZqsPoJRIzdDmrZYxGStbAZ7HThqFJlSJ9NPNhH+E2jm3TwL5mwt0fFZ5h+p497lHMtIcKffESo7KNa2juSVNMDREk0NcyxGXGiVB2FWl4sLdvyhcsVq0I7tmW6OGZKRf8W49GCJXq6Ie69DJ9LB1DO67NV1jsYbsLx9uhE2yEmpWZ3jkoCV/Eas4grxt0CGN6EavzQ=='; var encryptedLegacy1 = 'U2FsdGVkX19yGM1uBAIzQa8Po/dvUicmxt1YyRk/S97PcZ6I6rHMp9dMagIrehg4Qd6JHn/ustmFHS7vmBYj0EBpf6rdXiQezaWnVAJS9/xYjAO36EFUbl+NmUanuwujAxgYdSP/sNssRLeInvExmZYW993EEclxkwL6YUyX66kKsxGQo2oWng0NreBJNhFmrbOEWeFje2PiWP57oUjKsurFzwpluAAarUTYSLud+nXeabC7opzOP5yqniWBMJz0Ou8gpNCWCMhG/P9F9ccVPY7juyd0Hf41FVse8nd2++axKB57+paozLdO+HRfV6zkMqC3h8gWY7LkS75j3bvqcTw9LhXmzE0Sz21n9yDnRpA4chiAvtwQvvBGgj1pFMKhNQU6Obac9ZwKYzUTgdDn3Uzg1UlDzgyOh9S89rbRTV84WB+hXwhuVluWzbNNYV3vXe5PFrocVktIrtS3xQh+k/7my4A6/gRRrzNYpKrUASJqDS/9u9WBkG35xD63J/qXjtG2M0YPwbI57BK1IK4K510b8V72lz5U2XQrIC4ldBwni1rpSavwCJV9xF6hUdOmNV8fZsVHP0NeN1PYlLkSb2QgfuoWnkcsJerwuFR7GZC/i6efrswtpO0wMEQr/J0CLbeXlHAru6xxjCBhWoJvZpMGw72zgnDLoyMNsEVglNhx/VlV9ZMYkkdaEYAxPOEIyZdQ5MS+2jEAlXf818n/xzJSVrniCn9be8EPePvkw35pivprvy09vbW4cKsWBKvgIyoT6A3OhUOCCS8E9cg0WAjjav2EymrbKmGWRHaiD+EoJqaDg6s20zhHn1YEa/YwvGGSB5+Hg8baLHD8ZASvxz4cFFAAVZrBUedRFgHzqwaMUlFXLgueivWUj7RXlIw6GuNhLoo1QkhZMacf23hrFxxQYvGBRw1hekBuDmcsGWljA28udBxBd5f9i+3gErttMLJ6IPaud590uvrxRIclu0Sz9R2EQX64YJxqDtLpMY0PjddSMu8vaDRpK9/ZSrnz/xrXsyabaafz4rE/ItFXjwFUFkvtmuauHTz6nmuKjVfxvNLNAiKb/gI7vQyUhnTbKIApe7XyJsjedNDtZqsPoJRIzdDmrZYxGStbAZ7HThqFJlSJ9NPNhH+E2jm3TwL5mwt0fFZ5h+p497lHMtIcKffESo7KNa2juSVNMDREk0NcyxGXGiVB2FWl4sLdvyhcsVq0I7tmW6OGZKRf8W49GCJXq6Ie69DJ9LB1DO67NV1jsYbsLx9uhE2yEmpWZ3jkoCV/Eas4grxt0CGN6EavzQ==';

View file

@ -87,6 +87,7 @@ describe('Wallet model', function() {
}); });
var storage = new Storage(walletConfig.storage); var storage = new Storage(walletConfig.storage);
storage.setPassphrase('xxx');
var network = new Network(walletConfig.network); var network = new Network(walletConfig.network);
var blockchain = new Blockchain(walletConfig.blockchain); var blockchain = new Blockchain(walletConfig.blockchain);
c.storage = storage; c.storage = storage;
@ -347,8 +348,10 @@ describe('Wallet model', function() {
// non stored options // non stored options
o.opts.reconnectDelay = 100; o.opts.reconnectDelay = 100;
var s = new Storage(walletConfig.storage);
s.setPassphrase('xxx');
var w2 = Wallet.fromObj(o, var w2 = Wallet.fromObj(o,
new Storage(walletConfig.storage), s,
new Network(walletConfig.network), new Network(walletConfig.network),
new Blockchain(walletConfig.blockchain)); new Blockchain(walletConfig.blockchain));
should.exist(w2); should.exist(w2);

View file

@ -11,21 +11,19 @@ if (is_browser) {
} }
var copayConfig = require('../config'); var copayConfig = require('../config');
var WalletLock = copay.WalletLock; var WalletLock = copay.WalletLock;
var PrivateKey = copay.PrivateKey; var PrivateKey = copay.PrivateKey;
var localMock = require('./mocks/FakeLocalStorage');
var sessionMock = require('./mocks/FakeLocalStorage');
var Storage = copay.Storage; var Storage = copay.Storage;
var storage; var storage;
describe('WalletLock model', function() { describe('WalletLock model', function() {
beforeEach(function() { beforeEach(function() {
storage = new Storage({ storage = new Storage(require('./mocks/FakeLocalStorage').storageParams);
storage: localMock, storage.setPassphrase('mysupercoolpassword');
sessionStorage: sessionMock, storage.storage.clear();
}); storage.sessionStorage.clear();
}); });
it('should fail with missing args', function() { it('should fail with missing args', function() {
@ -80,36 +78,34 @@ describe('WalletLock model', function() {
}); });
it('should FAIL if locked by someone else', function(done) { it('should FAIL if locked by someone else', function(done) {
storage.sessionId = 'session1';
var w = new WalletLock(storage, 'walletId'); var w = new WalletLock(storage, 'walletId');
w.keepAlive(function() { w.keepAlive(function() {
storage.sessionId = 'session2'; storage.setSessionId('session2', function() {
var w2 = new WalletLock(storage, 'walletId'); var w2 = new WalletLock(storage, 'walletId');
w2.keepAlive(function(locked) { w2.keepAlive(function(locked) {
w2.sessionId.should.equal('session2'); should.exist(locked);
should.exist(locked); locked.message.should.contain('LOCKED');
locked.message.should.contain('LOCKED'); done();
done(); });
}); });
}); });
}) })
it('should FAIL if locked by someone else but expired', function(done) { it('should FAIL if locked by someone else but expired', function(done) {
storage.sessionId = 'session1';
var w = new WalletLock(storage, 'walletId'); var w = new WalletLock(storage, 'walletId');
w.keepAlive(function() { w.keepAlive(function() {
storage.sessionId = 'session2'; storage.setSessionId('session2', function() {
var json = JSON.parse(storage.storage['lock::walletId']);
json.expireTs -= 3600 * 1000; var json = JSON.parse(storage.storage.ls['lock::walletId']);
storage.storage['lock::walletId'] = JSON.stringify(json); json.expireTs -= 3600 * 1000;
var w2 = new WalletLock(storage, 'walletId'); storage.storage.ls['lock::walletId'] = JSON.stringify(json);
w2.keepAlive(function(locked) { var w2 = new WalletLock(storage, 'walletId');
w2.sessionId.should.equal('session2'); w2.keepAlive(function(locked) {
should.not.exist(locked); w2.sessionId.should.equal('session2');
done(); should.not.exist(locked);
done();
});
}); });
}); });
}) })
}); });