req.ip.js
This file
Path
test/req.ip.js
57 lines · 1.4 KiB · JavaScript
Last changed by
Added `req.ip` testsTJ Holowaychukbefore adoptionfd53197
History of this fileTake it
Added `req.ip` testsTJ Holowaychukbefore adoptionfd53197
lines 1–57why, one step back12var express = require('../')3 , request = require('./support/http');45describe('req', function(){6 describe('.ip', function(){7 describe('when X-Forwarded-For is present', function(){8 describe('when "trust proxy" is enabled', function(){9 it('should return the client addr', function(done){10 var app = express();1112 app.enable('trust proxy');1314 app.use(function(req, res, next){15 res.send(req.ip);16 });1718 request(app)19 .get('/')20 .set('X-Forwarded-For', 'client, p1, p2')21 .expect('client', done);22 })23 })2425 describe('when "trust proxy" is disabled', function(){26 it('should return the remote address', function(done){27 var app = express();2829 app.use(function(req, res, next){30 res.send(req.ip);31 });3233 request(app)34 .get('/')35 .set('X-Forwarded-For', 'client, p1, p2')36 .expect('127.0.0.1', done);37 })38 })39 })4041 describe('when X-Forwarded-For is not present', function(){42 it('should return the remote address', function(done){43 var app = express();4445 app.enable('trust proxy');4647 app.use(function(req, res, next){48 res.send(req.ip);49 });5051 request(app)52 .get('/')53 .expect('127.0.0.1', done);54 })55 })56 })57})