Skip to content
Myr

req.ip.js

This file

Path

test/req.ip.js

72 lines · 1.7 KiB · JavaScript

Last changed by

Merge tag '3.7.0'Douglas Christopher Wilsonbefore adoption097cd0c

History of this file

Take it

The walk stopped after 200 commits: lines older than 2e68ddb point at it.

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 1–2why, one step back
1
2var express = require('../')

remove unnecessary test/support/httpJonathan Ongbefore adoption643397e

line 3why, one step back
3 , request = require('supertest');

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 4–22why, one step back
4
5describe('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 })

Merge tag '3.7.0'Douglas Christopher Wilsonbefore adoption097cd0c

lines 23–37why, one step back
23
24 it('should return the addr after trusted proxy', function(done){25 var app = express();2627 app.set('trust proxy', 2);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('p1', done);37 })

expose connect.middleware using Object.getOwnPropertyDescriptor()Jonathan Ongbefore adoption2e68ddb

lines 38–72why, one step back
38 })
3940 describe('when "trust proxy" is disabled', function(){41 it('should return the remote address', function(done){42 var app = express();4344 app.use(function(req, res, next){45 res.send(req.ip);46 });4748 request(app)49 .get('/')50 .set('X-Forwarded-For', 'client, p1, p2')51 .expect('127.0.0.1', done);52 })53 })54 })5556 describe('when X-Forwarded-For is not present', function(){57 it('should return the remote address', function(done){58 var app = express();5960 app.enable('trust proxy');6162 app.use(function(req, res, next){63 res.send(req.ip);64 });6566 request(app)67 .get('/')68 .expect('127.0.0.1', done);69 })70 })71 })72})