2014-04-15 14:13:25 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
if (typeof process === 'undefined' || !process.version) {
|
|
|
|
// browser
|
|
|
|
var chai = chai || require('chai');
|
|
|
|
var should = chai.should();
|
|
|
|
var copay = copay || require('../copay');
|
2014-04-16 07:55:18 -07:00
|
|
|
var LocalEncrypted = copay.StorageLocalEncrypted;
|
2014-04-15 14:13:25 -07:00
|
|
|
|
2014-04-16 07:55:18 -07:00
|
|
|
describe('Storage/LocalEncrypted model', function() {
|
2014-04-15 14:13:25 -07:00
|
|
|
var wid = 'fake-wallet-id';
|
2014-04-16 07:55:18 -07:00
|
|
|
var s = new LocalEncrypted();
|
2014-04-15 14:13:25 -07:00
|
|
|
s._setPassphrase('mysupercoolpassword');
|
|
|
|
|
|
|
|
it('should create an instance', function() {
|
2014-04-16 07:55:18 -07:00
|
|
|
var s = new LocalEncrypted();
|
2014-04-15 14:13:25 -07:00
|
|
|
should.exist(s);
|
|
|
|
});
|
2014-04-15 15:14:42 -07:00
|
|
|
it('should fail when encrypting without a password', function() {
|
2014-04-16 07:55:18 -07:00
|
|
|
var s = new LocalEncrypted();
|
2014-04-15 14:13:25 -07:00
|
|
|
(function(){s.set(wid, 'x', 1);}).should.throw();
|
|
|
|
});
|
|
|
|
it('should be able to encrypt and decrypt', function() {
|
|
|
|
s._write('key', 'value');
|
|
|
|
s._read('key').should.equal('value');
|
|
|
|
});
|
|
|
|
it('should be able to set a value', function() {
|
|
|
|
s.set(wid, 'x', 1);
|
|
|
|
});
|
|
|
|
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() {
|
|
|
|
s.set(wid, 'x', obj);
|
|
|
|
var obj2 = s.get(wid, 'x');
|
|
|
|
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
|
|
|
|
});
|
|
|
|
});
|
2014-04-17 14:04:56 -07:00
|
|
|
|
|
|
|
describe('#getEncryptedObj', function() {
|
|
|
|
it('should encrypt the wallet', function() {
|
|
|
|
localStorage.clear();
|
|
|
|
var storage = new LocalEncrypted({password: 'password'});
|
|
|
|
storage.set('walletId', 'test', 'testval');
|
|
|
|
var obj = {test:'testval'};
|
|
|
|
var encrypted = storage.getEncryptedObj('walletId');
|
2014-04-18 15:19:38 -07:00
|
|
|
encrypted.length.should.be.greaterThan(10);
|
|
|
|
//encrypted.slice(0,6).should.equal("53616c");
|
2014-04-17 14:04:56 -07:00
|
|
|
});
|
|
|
|
});
|
2014-04-15 14:13:25 -07:00
|
|
|
});
|
|
|
|
}
|