express-ipfilter
Advanced tools
Comparing version 0.2.6 to 0.3.0
@@ -13,2 +13,6 @@ # Contributing | ||
Build the libraries: | ||
grunt | ||
Make sure the tests pass: | ||
@@ -15,0 +19,0 @@ |
@@ -29,4 +29,6 @@ /*! | ||
* ips = ['127.0.0.1']; | ||
* getIps = function() { return ['127.0.0.1']; }; | ||
* | ||
* app.use(ipfilter(ips)); | ||
* app.use(ipfilter(getIps)); | ||
* | ||
@@ -42,3 +44,3 @@ * Options: | ||
* | ||
* @param [ips] {Array} IP addresses | ||
* @param [ips] {Array} IP addresses or {Function} that returns the array of IP addresses | ||
* @param [opts] {Object} options | ||
@@ -50,2 +52,3 @@ * @api public | ||
var ipsIsFunction = _.isFunction(ips); | ||
var logger = function logger(message) { | ||
@@ -64,2 +67,6 @@ console.log(message); | ||
function getIps() { | ||
return ipsIsFunction ? ips() : ips; | ||
} | ||
function getClientIp(req) { | ||
@@ -104,3 +111,3 @@ var ipAddress; | ||
var result = _.invoke(ips, testIp, ip, mode); | ||
var result = _.invoke(getIps(), testIp, ip, mode); | ||
@@ -148,3 +155,3 @@ if (mode === 'allow') { | ||
var testRange = function testRange(ip, constraint, mode) { | ||
var filteredSet = _.filter(ips, function (constraint) { | ||
var filteredSet = _.filter(getIps(), function (constraint) { | ||
if (constraint.length > 1) { | ||
@@ -185,3 +192,4 @@ var startIp = iputil.toLong(constraint[0]); | ||
// this middleware | ||
if (!ips || !ips.length) { | ||
var _ips = getIps(); | ||
if (!_ips || !_ips.length) { | ||
return next(); | ||
@@ -188,0 +196,0 @@ } |
{ | ||
"name": "express-ipfilter", | ||
"description": "A light-weight IP address based filtering system", | ||
"version": "0.2.6", | ||
"version": "0.3.0", | ||
"author": "BaM Interactive", | ||
@@ -6,0 +6,0 @@ "dependencies": { |
@@ -9,3 +9,3 @@ express-ipfilter: A light-weight IP address based filtering system | ||
## Version | ||
0.2.6 | ||
0.3.0 | ||
@@ -76,2 +76,13 @@ ## Installation | ||
Using a function to get Ips: | ||
```javascript | ||
var ips = function() { return ['127.0.0.1']; }; | ||
// Create the server | ||
app.use(ipfilter(ips, {mode: 'allow'})); | ||
module.exports = app; | ||
``` | ||
## Error Handling | ||
@@ -150,2 +161,5 @@ | ||
0.3.0 | ||
* Adds the ability to pass IPs by function so that we can dynamically retrieve white/black listed addresses. | ||
0.2.6 | ||
@@ -152,0 +166,0 @@ - Minor change to the Contributing Guidelines to include updating the version numbers |
@@ -26,4 +26,6 @@ /*! | ||
* ips = ['127.0.0.1']; | ||
* getIps = function() { return ['127.0.0.1']; }; | ||
* | ||
* app.use(ipfilter(ips)); | ||
* app.use(ipfilter(getIps)); | ||
* | ||
@@ -39,3 +41,3 @@ * Options: | ||
* | ||
* @param [ips] {Array} IP addresses | ||
* @param [ips] {Array} IP addresses or {Function} that returns the array of IP addresses | ||
* @param [opts] {Object} options | ||
@@ -47,2 +49,3 @@ * @api public | ||
var ipsIsFunction = _.isFunction(ips); | ||
var logger = function(message){ console.log(message);}; | ||
@@ -59,2 +62,6 @@ var settings = _.defaults( opts || {}, { | ||
function getIps() { | ||
return ipsIsFunction ? ips() : ips; | ||
} | ||
function getClientIp(req) { | ||
@@ -99,3 +106,3 @@ var ipAddress; | ||
var result = _.invoke(ips,testIp,ip,mode); | ||
var result = _.invoke(getIps(),testIp,ip,mode); | ||
@@ -143,3 +150,3 @@ if(mode === 'allow'){ | ||
var testRange = function(ip,constraint,mode){ | ||
var filteredSet = _.filter(ips,function(constraint){ | ||
var filteredSet = _.filter(getIps(),function(constraint){ | ||
if(constraint.length > 1){ | ||
@@ -180,3 +187,4 @@ var startIp = iputil.toLong(constraint[0]); | ||
// this middleware | ||
if(!ips || !ips.length) { return next(); } | ||
var _ips = getIps(); | ||
if(!_ips || !_ips.length) { return next(); } | ||
@@ -183,0 +191,0 @@ if(matchClientIp(ip,req)) { |
@@ -1051,2 +1051,56 @@ /* global describe, it, beforeEach */ | ||
} | ||
describe('using ips as a function', function () { | ||
var ips = function() { return ['127.0.0.1']; }; | ||
describe('with a whitelist', function () { | ||
beforeEach(function () { | ||
this.ipfilter = ipfilter(ips, { mode: 'allow', log: false }); | ||
this.req = { | ||
session: {}, | ||
headers: [], | ||
connection: { | ||
remoteAddress: '' | ||
} | ||
}; | ||
}); | ||
it('should allow', function (done) { | ||
this.req.connection.remoteAddress = '127.0.0.1'; | ||
this.ipfilter(this.req, {}, function () { | ||
done(); | ||
}); | ||
}); | ||
it('should deny', function (done) { | ||
this.req.connection.remoteAddress = '127.0.0.2'; | ||
checkError(this.ipfilter, this.req, done); | ||
}); | ||
}); | ||
describe('with a blacklist', function () { | ||
beforeEach(function () { | ||
this.ipfilter = ipfilter(ips, { mode: 'deny', log: false }); | ||
this.req = { | ||
session: {}, | ||
headers: [], | ||
connection: { | ||
remoteAddress: '' | ||
} | ||
}; | ||
}); | ||
it('should allow', function (done) { | ||
this.req.connection.remoteAddress = '127.0.0.2'; | ||
this.ipfilter(this.req, {}, function () { | ||
done(); | ||
}); | ||
}); | ||
it('should deny', function (done) { | ||
this.req.connection.remoteAddress = '127.0.0.1'; | ||
checkError(this.ipfilter, this.req, done); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=ipfilter.spec.js.map |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119605
1483
281