Permalink
Browse files

Added `req.ip` tests

  • Loading branch information...
1 parent d84d0b6 commit fd53197b46ab05017ed7b071212cb5688cba4926 @tj tj committed May 30, 2012
Showing with 57 additions and 0 deletions.
  1. +57 −0 test/req.ip.js
View
@@ -0,0 +1,57 @@
+
+var express = require('../')
+ , request = require('./support/http');
+
+describe('req', function(){
+ describe('.ip', function(){
+ describe('when X-Forwarded-For is present', function(){
+ describe('when "trust proxy" is enabled', function(){
+ it('should return the client addr', function(done){
+ var app = express();
+
+ app.enable('trust proxy');
+
+ app.use(function(req, res, next){
+ res.send(req.ip);
+ });
+
+ request(app)
+ .get('/')
+ .set('X-Forwarded-For', 'client, p1, p2')
+ .expect('client', done);
+ })
+ })
+
+ describe('when "trust proxy" is disabled', function(){
+ it('should return the remote address', function(done){
+ var app = express();
+
+ app.use(function(req, res, next){
+ res.send(req.ip);
+ });
+
+ request(app)
+ .get('/')
+ .set('X-Forwarded-For', 'client, p1, p2')
+ .expect('127.0.0.1', done);
+ })
+ })
+ })
+
+ describe('when X-Forwarded-For is not present', function(){
+ it('should return the remote address', function(done){
+ var app = express();
+
+ app.enable('trust proxy');
+
+ app.use(function(req, res, next){
+ res.send(req.ip);
+ });
+
+ request(app)
+ .get('/')
+ .expect('127.0.0.1', done);
+ })
+ })
+ })
+})

0 comments on commit fd53197

Please sign in to comment.