From d036557a33b0d1c44daad38a5982719519595c62 Mon Sep 17 00:00:00 2001 From: Ryan Billingsley Date: Wed, 17 Dec 2014 14:30:04 -0500 Subject: [PATCH] Added a test for whitelists as well just to be safe --- test.js | 61 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/test.js b/test.js index 0e029ff..d45713d 100644 --- a/test.js +++ b/test.js @@ -525,28 +525,49 @@ describe('external logger function', function () { }); -describe('issue 6',function(){ - beforeEach(function(){ - this.ipfilter = ipfilter(['72.30.0.0/26', '127.0.0.1/24'], { cidr: true, mode: 'deny', log: false }); - this.req = { - session: {}, - headers: [], - connection: { - remoteAddress: '' - } - }; - }); +describe('an array of cidr blocks',function(){ + describe('blacklist',function(){ + beforeEach(function(){ + this.ipfilter = ipfilter(['72.30.0.0/26', '127.0.0.1/24'], { cidr: true, mode: 'deny', log: false }); + this.req = { + session: {}, + headers: [], + connection: { + remoteAddress: '' + } + }; + }); - it('should deny all blacklisted ips', function( done ){ - this.req.connection.remoteAddress = '127.0.0.1'; - var res = { - end: function(){ - assert.equal( 401, res.statusCode ); - done(); - } - }; + it('should deny all blacklisted ips', function( done ){ + this.req.connection.remoteAddress = '127.0.0.1'; + var res = { + end: function(){ + assert.equal( 401, res.statusCode ); + done(); + } + }; - this.ipfilter( this.req, res, function(){}); + this.ipfilter( this.req, res, function(){}); + }); }); + describe('whitelist',function(){ + beforeEach(function(){ + this.ipfilter = ipfilter(['72.30.0.0/26', '127.0.0.1/24'], { cidr: true, mode: 'allow', log: false }); + this.req = { + session: {}, + headers: [], + connection: { + remoteAddress: '' + } + }; + }); + + it('should allow all whitelisted ips', function( done ){ + this.req.connection.remoteAddress = '127.0.0.1'; + this.ipfilter( this.req, {}, function(){ + done(); + }); + }); + }); });