req.ips.js
This file
Path
test/req.ips.js
71 lines · 1.7 KiB · JavaScript
Last changed by
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
History of this fileTake it
The walk stopped after 200 commits: lines older than 2a0c35a point at it.
Merge tag '4.17.3'Douglas Christopher Wilsonbefore adoption318fd4b
line 1why, one step back1'use strict'Invoke callback for sendfile when client abortsDouglas Christopher Wilsonbefore adoption2a0c35a
lines 2–71why, one step back23var express = require('../')4 , request = require('supertest');56describe('req', function(){7 describe('.ips', function(){8 describe('when X-Forwarded-For is present', function(){9 describe('when "trust proxy" is enabled', function(){10 it('should return an array of the specified addresses', function(done){11 var app = express();1213 app.enable('trust proxy');1415 app.use(function(req, res, next){16 res.send(req.ips);17 });1819 request(app)20 .get('/')21 .set('X-Forwarded-For', 'client, p1, p2')22 .expect('["client","p1","p2"]', done);23 })2425 it('should stop at first untrusted', function(done){26 var app = express();2728 app.set('trust proxy', 2);2930 app.use(function(req, res, next){31 res.send(req.ips);32 });3334 request(app)35 .get('/')36 .set('X-Forwarded-For', 'client, p1, p2')37 .expect('["p1","p2"]', done);38 })39 })4041 describe('when "trust proxy" is disabled', function(){42 it('should return an empty array', function(done){43 var app = express();4445 app.use(function(req, res, next){46 res.send(req.ips);47 });4849 request(app)50 .get('/')51 .set('X-Forwarded-For', 'client, p1, p2')52 .expect('[]', done);53 })54 })55 })5657 describe('when X-Forwarded-For is not present', function(){58 it('should return []', function(done){59 var app = express();6061 app.use(function(req, res, next){62 res.send(req.ips);63 });6465 request(app)66 .get('/')67 .expect('[]', done);68 })69 })70 })71})