Skip to content
Myr

req.ip.js

This file

Path

test/req.ip.js

97 lines · 2.4 KiB · JavaScript

Last changed by

Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024

History of this file

Take it

The walk stopped after 200 commits: lines older than 6bc7574 point at it.

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 1–37why, one step back
1
2var express = require('../')3 , request = require('supertest');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 })2324 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 })

Merge tag '3.20.0'Douglas Christopher Wilsonbefore adoption531f024

lines 38–54why, one step back
38
39 it('should return the addr after trusted proxy, from sub app', function (done) {40 var app = express();41 var sub = express();4243 app.set('trust proxy', 2);44 app.use(sub);4546 sub.use(function (req, res, next) {47 res.send(req.ip);48 });4950 request(app)51 .get('/')52 .set('X-Forwarded-For', 'client, p1, p2')53 .expect(200, 'p1', done);54 })

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 55–64why, one step back
55 })
5657 describe('when "trust proxy" is disabled', function(){58 it('should return the remote address', function(done){59 var app = express();6061 app.use(function(req, res, next){62 res.send(req.ip);63 });64

Merge tag '3.17.2'Douglas Christopher Wilsonbefore adoption916a75c

lines 65–67why, one step back
65 var test = request(app).get('/')
66 test.set('X-Forwarded-For', 'client, p1, p2')67 test.expect(200, getExpectedClientAddress(test._server), done);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 68–81why, one step back
68 })
69 })70 })7172 describe('when X-Forwarded-For is not present', function(){73 it('should return the remote address', function(done){74 var app = express();7576 app.enable('trust proxy');7778 app.use(function(req, res, next){79 res.send(req.ip);80 });81

Merge tag '3.17.2'Douglas Christopher Wilsonbefore adoption916a75c

lines 82–83why, one step back
82 var test = request(app).get('/')
83 test.expect(200, getExpectedClientAddress(test._server), done);

docs: typo fixesDouglas Christopher Wilsonbefore adoption6bc7574

lines 84–87why, one step back
84 })
85 })86 })87})

Merge tag '3.17.2'Douglas Christopher Wilsonbefore adoption916a75c

lines 88–97why, one step back
88
89/**90 * Get the local client address depending on AF_NET of server91 */9293function getExpectedClientAddress(server) {94 return server.address().address === '::'95 ? '::ffff:127.0.0.1'96 : '127.0.0.1';97}