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 #63 from gordonwritescode/hotfix/contact-validator
Browse files Browse the repository at this point in the history
fix bug with incorrectly invalidating public addresses
  • Loading branch information
gordonwritescode committed Apr 28, 2016
2 parents be550a2 + f51e459 commit f4685f0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/interfaces/renter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
46 changes: 46 additions & 0 deletions test/utils.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

});

0 comments on commit f4685f0

Please sign in to comment.