Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Commit

Permalink
Added a test for whitelists as well just to be safe
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbillingsley committed Dec 17, 2014
1 parent cc7de42 commit d036557
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});

0 comments on commit d036557

Please sign in to comment.