Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #759 from littleskunk/datahash
Browse files Browse the repository at this point in the history
Change some error message to hide informations about existing contracts
  • Loading branch information
braydonf authored Feb 28, 2018
2 parents ea3ee03 + d6df630 commit 3d23f02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions lib/network/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ Protocol.prototype.handleConsign = function(params, callback) {

self._network.storageManager.load(params.data_hash, function(err, item) {
if (err) {
return callback(err);
return callback(new Error('Contract not found or not authorized'));
}

var contract = item.getContract(params.contact);
var t = Date.now();

if (!contract) {
return callback(new Error('Consignment is not authorized'));
return callback(new Error('Contract not found or not authorized'));
}

item.trees[contract.get('renter_id')] = params.audit_tree;
Expand Down Expand Up @@ -335,14 +335,14 @@ Protocol.prototype.handleMirror = function(params, callback) {
// eslint-disable-next-line max-statements
self._network.storageManager.load(hash, function(err, item) {
if (err) {
return callback(err);
return callback(new Error('Contract not found or not authorized'));
}

let contract = item.getContract(params.contact);

// NB: Don't mirror data we are not contracted for
if (!contract) {
return callback(new Error('No contract found for shard'));
return callback(new Error('Contract not found or not authorized'));
}

const bridgeExtendedKey = contract.get('renter_hd_key');
Expand Down Expand Up @@ -455,11 +455,11 @@ Protocol.prototype.handleRetrieve = function(params, callback) {

self._network.storageManager.load(hash, function(err, item) {
if (err) {
return callback(err);
return callback(new Error('Contract not found or not authorized'));
}

if (!item.getContract(params.contact)) {
return callback(new Error('Retrieval is not authorized'));
return callback(new Error('Contract not found or not authorized'));
}

if (typeof item.shard.write === 'function') {
Expand Down Expand Up @@ -703,13 +703,13 @@ Protocol.prototype.handleRenew = function(params, callback) {

this._network.storageManager.load(dataHash, function(err, item) {
if (err) {
return callback(err);
return callback(new Error('Contract not found or not authorized'));
}

var originalContract = item.getContract(params.contact);

if (!originalContract) {
return callback(new Error('No contract found for renter_id'));
return callback(new Error('Contract not found or not authorized'));
}

var changedProperties = Contract.diff(originalContract, updatedContract);
Expand Down
16 changes: 8 additions & 8 deletions test/network/protocol.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ describe('Protocol', function() {
proto.handleConsign({
contact: { nodeID: 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc' }
}, function(err) {
expect(err.message).to.equal('Failed');
expect(err.message).to.equal('Contract not found or not authorized');
done();
});
});
Expand All @@ -614,7 +614,7 @@ describe('Protocol', function() {
proto.handleConsign({
contact: { nodeID: 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc' }
}, function(err) {
expect(err.message).to.equal('Consignment is not authorized');
expect(err.message).to.equal('Contract not found or not authorized');
done();
});
});
Expand Down Expand Up @@ -759,7 +759,7 @@ describe('Protocol', function() {
data_hash: utils.rmd160(''),
contact: { nodeID: 'nodeid' }
}, function(err) {
expect(err.message).to.equal('Failed');
expect(err.message).to.equal('Contract not found or not authorized');
done();
});
});
Expand Down Expand Up @@ -799,7 +799,7 @@ describe('Protocol', function() {
contact: {}
}, function(err) {
expect(err).to.be.instanceOf(Error);
expect(err.message).to.equal('Retrieval is not authorized');
expect(err.message).to.equal('Contract not found or not authorized');
});
});

Expand Down Expand Up @@ -896,7 +896,7 @@ describe('Protocol', function() {
proto.handleMirror({
contact: { address: '0.0.0.0', port: 4321, nodeID: 'nodeid' }
}, function(err) {
expect(err.message).to.equal('Failed');
expect(err.message).to.equal('Contract not found or not authorized');
done();
});
});
Expand Down Expand Up @@ -925,7 +925,7 @@ describe('Protocol', function() {
proto.handleMirror({
contact: { nodeID: 'test' }
}, function(err) {
expect(err.message).to.equal('No contract found for shard');
expect(err.message).to.equal('Contract not found or not authorized');
done();
});
});
Expand Down Expand Up @@ -1774,7 +1774,7 @@ describe('Protocol', function() {
renter_signature: contract.signExternal(renterKp.getPrivateKey()),
contract: contract.toObject()
}, function(err) {
expect(err.message).to.equal('Not found');
expect(err.message).to.equal('Contract not found or not authorized');
done();
});
});
Expand Down Expand Up @@ -1808,7 +1808,7 @@ describe('Protocol', function() {
renter_signature: oldContract.signExternal(renterKp.getPrivateKey()),
contract: oldContract.toObject()
}, function(err) {
expect(err.message).to.equal('No contract found for renter_id');
expect(err.message).to.equal('Contract not found or not authorized');
done();
});
});
Expand Down

0 comments on commit 3d23f02

Please sign in to comment.