mirror of https://github.com/BTCPrivate/copay.git
clear namespace when removing profile
This commit is contained in:
parent
b51acf277f
commit
f5edb12d42
|
@ -356,8 +356,13 @@ Identity.prototype.remove = function(opts, cb) {
|
||||||
|
|
||||||
self.storage.removeItem(self.getId(), function(err) {
|
self.storage.removeItem(self.getId(), function(err) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
self.emitAndKeepAlive('closed');
|
|
||||||
return cb();
|
self.storage.clear(function (err) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
self.emitAndKeepAlive('closed');
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -232,8 +232,28 @@ InsightStorage.prototype.removeItem = function(key, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
InsightStorage.prototype.clear = function(callback) {
|
InsightStorage.prototype.clear = function(callback) {
|
||||||
// NOOP
|
var passphrase = this.getPassphrase();
|
||||||
callback();
|
var authHeader = new buffers.Buffer(this.email + ':' + passphrase).toString('base64');
|
||||||
|
var deleteUrl = this.storeUrl + '/delete/profile';
|
||||||
|
|
||||||
|
log.debug('Clearing storage for: ' + this.email);
|
||||||
|
this.request.post({
|
||||||
|
url: deleteUrl,
|
||||||
|
headers: {
|
||||||
|
'Authorization': authHeader
|
||||||
|
},
|
||||||
|
body: null,
|
||||||
|
}, function(err, response, body) {
|
||||||
|
if (err) {
|
||||||
|
return callback('Connection error');
|
||||||
|
}
|
||||||
|
if (response.statusCode === 409) {
|
||||||
|
return callback('BADCREDENTIALS: Invalid username or password');
|
||||||
|
} else if (response.statusCode !== 200) {
|
||||||
|
return callback('Unable to remove data on insight');
|
||||||
|
}
|
||||||
|
return callback();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = InsightStorage;
|
module.exports = InsightStorage;
|
||||||
|
|
|
@ -80,11 +80,7 @@ LocalStorage.prototype.removeItem = function(k, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalStorage.prototype.clear = function(cb) {
|
LocalStorage.prototype.clear = function(cb) {
|
||||||
if (isChromeApp) {
|
// NOP
|
||||||
chrome.storage.clear();
|
|
||||||
} else {
|
|
||||||
this.ls.clear();
|
|
||||||
}
|
|
||||||
return cb();
|
return cb();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,7 @@ describe('Identity model', function() {
|
||||||
var storage = sinon.stub();
|
var storage = sinon.stub();
|
||||||
storage.setCredentials = sinon.stub();
|
storage.setCredentials = sinon.stub();
|
||||||
storage.removeItem = sinon.stub().yields(null);
|
storage.removeItem = sinon.stub().yields(null);
|
||||||
|
storage.clear = sinon.stub().yields();
|
||||||
|
|
||||||
var opts = {
|
var opts = {
|
||||||
email: 'test@test.com',
|
email: 'test@test.com',
|
||||||
|
@ -191,6 +192,7 @@ describe('Identity model', function() {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
storage.removeItem.calledOnce.should.be.true;
|
storage.removeItem.calledOnce.should.be.true;
|
||||||
storage.removeItem.getCall(0).args[0].should.equal(iden.getId());
|
storage.removeItem.getCall(0).args[0].should.equal(iden.getId());
|
||||||
|
storage.clear.calledOnce.should.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -199,6 +201,7 @@ describe('Identity model', function() {
|
||||||
var storage = sinon.stub();
|
var storage = sinon.stub();
|
||||||
storage.setCredentials = sinon.stub();
|
storage.setCredentials = sinon.stub();
|
||||||
storage.removeItem = sinon.stub().yields(null);
|
storage.removeItem = sinon.stub().yields(null);
|
||||||
|
storage.clear = sinon.stub().yields();
|
||||||
|
|
||||||
var opts = {
|
var opts = {
|
||||||
email: 'test@test.com',
|
email: 'test@test.com',
|
||||||
|
@ -231,6 +234,7 @@ describe('Identity model', function() {
|
||||||
storage.removeItem.callCount.should.equal(4);
|
storage.removeItem.callCount.should.equal(4);
|
||||||
storage.removeItem.getCall(0).args[0].should.equal(Wallet.getStorageKey('wallet0'));
|
storage.removeItem.getCall(0).args[0].should.equal(Wallet.getStorageKey('wallet0'));
|
||||||
storage.removeItem.getCall(3).args[0].should.equal(iden.getId());
|
storage.removeItem.getCall(3).args[0].should.equal(iden.getId());
|
||||||
|
storage.clear.calledOnce.should.be.true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -63,7 +63,7 @@ describe('local storage plugin', function() {
|
||||||
it('#clear', function(done) {
|
it('#clear', function(done) {
|
||||||
storage.clear(function(err) {
|
storage.clear(function(err) {
|
||||||
assert(!err);
|
assert(!err);
|
||||||
storageMock.clear.calledOnce.should.equal(true);
|
storageMock.clear.calledOnce.should.be.false;
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue