diff --git a/js/models/Identity.js b/js/models/Identity.js index 83797c218..c7912e35f 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -343,11 +343,13 @@ Identity.prototype.closeWallet = function(wid, cb) { */ Identity.import = function(str, password, opts, cb) { preconditions.checkArgument(str); -console.log('[Identity.js.347:str::]',str); //TODO - - var json = JSON.parse(str); - preconditions.checkArgument(_.isNumber(json.iterations)); + + if (!_.isNumber(json.iterations)) + return cb('BADSTR: Missing iterations'); + + if (!json.profile) + return cb('BADSTR: Missing profile'); var iden = new Identity(password, opts); @@ -383,7 +385,7 @@ Identity.prototype.export = function() { ret.wallets = {}; _.each(this.openWallets, function(w) { - ret.wallets[w.getId()] = w.toEncryptedObj(); + ret.wallets[w.getId()] = w.export(); }); var r = JSON.stringify(ret); diff --git a/js/models/Storage.js b/js/models/Storage.js index cf440d561..fe43d2580 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -233,17 +233,17 @@ Storage.prototype.clearAll = function(cb) { Storage.prototype.decrypt = function(base64, password, iterations) { if (password) { - this.storage.savePassphrase(); + this.savePassphrase(); var opts = iterations ? {iterations: iterations} : {}; - this.storage.setPassword(password, opts); + this.setPassword(password, opts); } var decryptedStr = this._decrypt(base64); var ret = JSON.parse(decryptedStr); if (password) - this.storage.restorePassphrase(); + this.restorePassphrase(); return ret; }; diff --git a/test/Identity.js b/test/Identity.js index f40140a9c..a7f055f9b 100644 --- a/test/Identity.js +++ b/test/Identity.js @@ -108,7 +108,7 @@ describe('Identity model', function() { describe('#constructors', function() { describe('#new', function() { it('should create an identity', function() { - var iden = new Identity(email, password, config); + var iden = new Identity(password, config); should.exist(iden); iden.walletDefaults.should.deep.equal(config.walletDefaults); }); @@ -358,7 +358,7 @@ describe('Identity model', function() { }); }); - describe.only('#import', function() { + describe('#import', function() { beforeEach(function() { var ws = []; @@ -375,14 +375,37 @@ describe('Identity model', function() { email: '1@1.com', hash: 'hash1234' }); + }); - it('should create an encrypted object', function(done) { + + it('should check the import string', function(done) { Identity.import(JSON.stringify({ - iterations: 10 + profile: '1234' }), '1234', config, function(err, ret) { + err.should.contain('BADSTR'); + done(); + }); + }); + + + it('should check the import string 2', function(done) { + Identity.import(JSON.stringify({ + iterations: 10, + }), '1234', config, function(err, ret) { + err.should.contain('BADSTR'); + done(); + }); + }); + + it('should import a simple wallet', function(done) { + Identity.import(JSON.stringify({ + iterations: 10, + profile: '1234' + }), '1234', config, function(err, iden) { should.not.exist(err); - should.exist(ret); + should.exist(iden); + iden.profile.email.should.equal('1@1.com'); done(); }); }); diff --git a/test/Storage.js b/test/Storage.js index 517c1a384..458035441 100644 --- a/test/Storage.js +++ b/test/Storage.js @@ -420,10 +420,11 @@ describe('Storage model', function() { should.not.exist(wo); }); it('should call save / restorePassphrase', function() { - var wo = s.decrypt(encryptedLegacy1, 'xxx'); + sinon.spy(s,'savePassphrase'); + sinon.spy(s,'restorePassphrase'); + s.decrypt(encryptedLegacy1, 'xxx'); s.savePassphrase.calledOnce.should.equal(true); s.restorePassphrase.calledOnce.should.equal(true); - should.not.exist(wo); });