Merge pull request #84 from ryanxcharles/feature/wallet-file-consistency
WIP: add setFromObj and getEncryptedObj to storage classes
This commit is contained in:
commit
9319c7f93f
8 changed files with 140 additions and 6 deletions
|
|
@ -1,9 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
var chai = chai || require('chai');
|
||||
var chai = require('chai');
|
||||
var should = chai.should();
|
||||
var Storage = Storage || require('../js/models/storage/File.js');
|
||||
var sinon = sinon || require('sinon');
|
||||
var Storage = require('../js/models/storage/File.js');
|
||||
var sinon = require('sinon');
|
||||
var crypto = require('crypto');
|
||||
var CryptoJS = require('node-cryptojs-aes').CryptoJS;
|
||||
|
||||
describe('Storage/File', function() {
|
||||
it('should exist', function() {
|
||||
|
|
@ -135,6 +137,37 @@ describe('Storage/File', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#setFromObj', function() {
|
||||
it('should set this object for a wallet', function(done) {
|
||||
var obj = {test:'testval'};
|
||||
var storage = new Storage();
|
||||
storage.save = function(walletId, callback) {
|
||||
callback();
|
||||
};
|
||||
storage.setFromObj('walletId', obj, function() {
|
||||
storage.data.walletId.test.should.equal('testval');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getEncryptedObj', function() {
|
||||
it('should give an encrypted object', function() {
|
||||
var obj = {test:'testval'};
|
||||
var data = JSON.stringify(obj);
|
||||
var encrypted = CryptoJS.AES.encrypt(data, 'password');
|
||||
var hex = CryptoJS.enc.Hex.stringify(CryptoJS.enc.Base64.parse(encrypted.toString()));
|
||||
|
||||
var storage = new Storage({password: 'password'});
|
||||
storage.data['walletId'] = obj;
|
||||
|
||||
var enc = storage.getEncryptedObj('walletId');
|
||||
enc.length.should.equal(96);
|
||||
enc.slice(0,10).should.equal(hex.slice(0,10));
|
||||
enc.slice(0,6).should.equal("53616c");
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clearAll', function() {
|
||||
it('should set data to {}', function() {
|
||||
|
||||
|
|
|
|||
|
|
@ -45,5 +45,17 @@ if (typeof process === 'undefined' || !process.version) {
|
|||
JSON.stringify(obj2).should.equal(JSON.stringify(obj));
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
encrypted.length.should.equal(96);
|
||||
encrypted.slice(0,6).should.equal("53616c");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,5 +13,15 @@ if (typeof process === 'undefined' || !process.version) {
|
|||
var s = new LocalPlain();
|
||||
should.exist(s);
|
||||
});
|
||||
|
||||
describe('#setFromObj', function() {
|
||||
it('should set keys from an object', function() {
|
||||
localStorage.clear();
|
||||
var obj = {test:'testval'};
|
||||
var storage = new LocalPlain();
|
||||
storage.setFromObj('walletId', obj);
|
||||
storage.get('walletId', 'test').should.equal('testval');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue