diff --git a/lib/network/protocol.js b/lib/network/protocol.js index 2052aaca..e1508a7e 100644 --- a/lib/network/protocol.js +++ b/lib/network/protocol.js @@ -196,6 +196,11 @@ Protocol.prototype._handleConsign = function(params, callback) { var contract = item.contracts[params.contact.nodeID]; var t = Date.now(); + + if (!contract) { + return callback(new Error('Consignment is not authorized')); + } + item.trees[contract.get('renter_id')] = params.audit_tree; try { diff --git a/package.json b/package.json index 2b8ebed8..436266df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "storj", - "version": "1.3.3", + "version": "1.3.4", "description": "implementation of the storj protocol for node.js and the browser", "main": "index.js", "directories": { diff --git a/test/network/protocol.unit.js b/test/network/protocol.unit.js index cf8ce290..98f343ae 100644 --- a/test/network/protocol.unit.js +++ b/test/network/protocol.unit.js @@ -7,6 +7,7 @@ var Logger = require('kad').Logger; var KeyPair = require('../../lib/keypair'); var stream = require('readable-stream'); var constants = require('../../lib/constants'); +var StorageItem = require('../../lib/storage/item'); describe('Protocol', function() { @@ -234,6 +235,23 @@ describe('Protocol', function() { }); }); + it('should error if the contract is for different nodeid', function(done) { + var proto = new Protocol({ + network: { + _logger: Logger(0), + _manager: { + load: sinon.stub().callsArgWith(1, null, StorageItem({})) + } + } + }); + proto._handleConsign({ + contact: { nodeID: 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc' } + }, function(err) { + expect(err.message).to.equal('Consignment is not authorized'); + done(); + }); + }); + it('should error if the consign is early or late', function(done) { var proto = new Protocol({ network: {