From f51e459e8ad7ecebeee1f7a3a867690375c11f43 Mon Sep 17 00:00:00 2001 From: Gordon Hall Date: Thu, 28 Apr 2016 14:35:10 -0400 Subject: [PATCH] fix bug with incorrectly invalidating public addresses --- lib/interfaces/renter.js | 1 + lib/utils.js | 6 ++++-- package.json | 2 +- test/utils.unit.js | 46 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/lib/interfaces/renter.js b/lib/interfaces/renter.js index a7faad22..ba9ae2c4 100644 --- a/lib/interfaces/renter.js +++ b/lib/interfaces/renter.js @@ -157,6 +157,7 @@ RenterInterface.prototype.retrieve = function(hash, callback) { * on the network. Keep track of the pending contract until it becomes * fulfilled by an OFFER, then issue a CONSIGN RPC to the offerer and * callback when the data is stored. + * @deprecated Since v0.6.4 - TODO: Explain alternative solution * @param {Buffer} data - Raw binary blob to store * @param {Number} duration - Time in milliseconds for storage contract * @param {Function} callback - Called on successful store diff --git a/lib/utils.js b/lib/utils.js index 69158f24..d04c4f29 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -116,9 +116,11 @@ module.exports.createCipherKeyAndIv = function(keypair) { */ module.exports.isValidContact = function(contact, loopback) { var address = contact.address; - var isValidAddr = ip.isV4Format(address) || ip.isV6Format(address); + var isValidAddr = ip.isV4Format(address) || + ip.isV6Format(address) || + ip.isPublic(address); var isValidPort = contact.port > 0; - var isAllowedAddr = loopback ? ip.isLoopback(address) : ip.isPublic(address); + var isAllowedAddr = ip.isLoopback(address) ? !!loopback : true; return isValidPort && isValidAddr && isAllowedAddr; }; diff --git a/package.json b/package.json index 5264c4a1..51605304 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "storj", - "version": "0.6.3", + "version": "0.6.4", "description": "implementation of the storj protocol for node.js and the browser", "main": "index.js", "directories": { diff --git a/test/utils.unit.js b/test/utils.unit.js index 041e05fc..4b0b2ffc 100644 --- a/test/utils.unit.js +++ b/test/utils.unit.js @@ -43,4 +43,50 @@ describe('utils', function() { }); + describe('#isValidContact', function() { + + it('should allow loopback iface if enabled', function() { + expect(utils.isValidContact({ + address: '127.0.0.1', + port: 1337 + }, true)).to.equal(true); + }); + + it('should not allow loopback iface if disabled', function() { + expect(utils.isValidContact({ + address: '127.0.0.1', + port: 1337 + })).to.equal(false); + }); + + it('should allow valid public address', function() { + expect(utils.isValidContact({ + address: '104.200.143.243', + port: 1337 + })).to.equal(true); + }); + + it('should allow valid public hostname', function() { + expect(utils.isValidContact({ + address: 'some.domain.name', + port: 1337 + })).to.equal(true); + }); + + it('should allow valid port', function() { + expect(utils.isValidContact({ + address: 'some.domain.name', + port: 80 + })).to.equal(true); + }); + + it('should not allow invalid port', function() { + expect(utils.isValidContact({ + address: 'some.domain.name', + port: 0 + })).to.equal(false); + }); + + }); + });