remove soop 1

This commit is contained in:
Manuel Araoz 2014-08-14 14:29:59 -04:00
parent e7967486a3
commit 69edb7c7e3
3 changed files with 37 additions and 36 deletions

View File

@ -37,6 +37,8 @@ Storage.prototype._decryptObj = function(base64) {
Storage.prototype.load = function(walletId, callback) { Storage.prototype.load = function(walletId, callback) {
var self = this; var self = this;
fs.readFile(walletId, function(err, base64) { fs.readFile(walletId, function(err, base64) {
if (typeof base64 !== 'string')
base64 = base64.toString();
var data = self._decryptObj(base64); var data = self._decryptObj(base64);
if (err) return callback(err); if (err) return callback(err);

View File

@ -36,33 +36,39 @@
"bitcoin" "bitcoin"
], ],
"devDependencies": { "devDependencies": {
"mocha-lcov-reporter": "0.0.1", "async": "0.9.0",
"travis-cov": "0.2.5", "bitcore": "git://github.com/bitpay/bitcore.git#master",
"chai": "1.9.1", "blanket": "1.1.6",
"browser-pack": "2.0.1",
"browserify": "3.32.1",
"buffertools": "2.0.1", "buffertools": "2.0.1",
"chai": "1.9.1",
"cli-color": "0.3.2",
"commander": "2.1.0", "commander": "2.1.0",
"uglifyify": "1.2.3", "coveralls": "2.10.0",
"grunt-contrib-watch": "0.5.3", "express": "4.0.0",
"istanbul": "0.2.10",
"grunt-mocha-test": "0.8.2",
"github-releases": "0.2.0", "github-releases": "0.2.0",
"grunt-browserify": "2.0.8",
"grunt-contrib-watch": "0.5.3",
"grunt-markdown": "0.5.0", "grunt-markdown": "0.5.0",
"browser-pack": "2.0.1", "browser-pack": "2.0.1",
"bitcore": "0.1.35", "bitcore": "0.1.35",
"node-cryptojs-aes": "0.4.0", "node-cryptojs-aes": "0.4.0",
"blanket": "1.1.6", "blanket": "1.1.6",
"express": "4.0.0", "express": "4.0.0",
"grunt-mocha-test": "0.8.2",
"grunt-shell": "0.6.4", "grunt-shell": "0.6.4",
"karma-mocha": "0.1.3", "istanbul": "0.2.10",
"async": "0.9.0",
"mocha": "1.18.2",
"browserify": "3.32.1",
"karma-phantomjs-launcher": "^0.1.4",
"coveralls": "2.10.0",
"grunt-browserify": "2.0.8",
"karma-chrome-launcher": "0.1.3",
"karma": "0.12.9", "karma": "0.12.9",
"cli-color": "0.3.2" "karma-chrome-launcher": "0.1.3",
"karma-mocha": "0.1.3",
"karma-phantomjs-launcher": "^0.1.4",
"mocha": "1.18.2",
"mocha-lcov-reporter": "0.0.1",
"mock-fs": "^2.3.1",
"node-cryptojs-aes": "0.4.0",
"travis-cov": "0.2.5",
"uglifyify": "1.2.3"
}, },
"main": "app.js", "main": "app.js",
"homepage": "https://github.com/bitpay/copay", "homepage": "https://github.com/bitpay/copay",

View File

@ -7,25 +7,25 @@ var sinon = require('sinon');
var crypto = require('crypto'); var crypto = require('crypto');
var CryptoJS = require('node-cryptojs-aes').CryptoJS; var CryptoJS = require('node-cryptojs-aes').CryptoJS;
var mock = require('mock-fs');
describe('Storage/File', function() { describe('Storage/File', function() {
it('should exist', function() { it('should exist', function() {
should.exist(Storage); should.exist(Storage);
}); });
var obj = {
"test": "test"
};
var encryptedStr = CryptoJS.AES.encrypt(JSON.stringify(obj), 'password').toString();
console.log(encryptedStr);
mock({
'myfilename': encryptedStr
});
describe('#load', function(done) { describe('#load', function(done) {
it('should call fs.readFile', function(done) { it('should call fs.readFile', function(done) {
var fs = {}
fs.readFile = function(filename, callback) {
filename.should.equal('myfilename');
var obj = {
"test": "test"
};
var encryptedStr = CryptoJS.AES.encrypt(JSON.stringify(obj), "password").toString();
callback(null, encryptedStr);
};
var Storage = require('soop').load('../js/models/storage/File.js', {
fs: fs
});
var storage = new Storage({ var storage = new Storage({
password: 'password' password: 'password'
}); });
@ -37,18 +37,11 @@ describe('Storage/File', function() {
describe('#save', function(done) { describe('#save', function(done) {
it('should call fs.writeFile', function(done) { it('should call fs.writeFile', function(done) {
var fs = {}
fs.writeFile = function(filename, data, callback) {
filename.should.equal('myfilename');
callback();
};
var Storage = require('soop').load('../js/models/storage/File.js', {
fs: fs
});
var storage = new Storage({ var storage = new Storage({
password: 'password' password: 'password'
}); });
storage.save('myfilename', function(err) { storage.save('myfilename', function(err) {
mock.restore();
done(); done();
}); });
}); });