build: Node.js@12.3
[express.git] / test / req.ips.js
bloba7d464b8468b92079e7daa405d641cd6e1238775
2 var express = require('../')
3   , request = require('supertest');
5 describe('req', function(){
6   describe('.ips', function(){
7     describe('when X-Forwarded-For is present', function(){
8       describe('when "trust proxy" is enabled', function(){
9         it('should return an array of the specified addresses', function(done){
10           var app = express();
12           app.enable('trust proxy');
14           app.use(function(req, res, next){
15             res.send(req.ips);
16           });
18           request(app)
19           .get('/')
20           .set('X-Forwarded-For', 'client, p1, p2')
21           .expect('["client","p1","p2"]', done);
22         })
24         it('should stop at first untrusted', function(done){
25           var app = express();
27           app.set('trust proxy', 2);
29           app.use(function(req, res, next){
30             res.send(req.ips);
31           });
33           request(app)
34           .get('/')
35           .set('X-Forwarded-For', 'client, p1, p2')
36           .expect('["p1","p2"]', done);
37         })
38       })
40       describe('when "trust proxy" is disabled', function(){
41         it('should return an empty array', function(done){
42           var app = express();
44           app.use(function(req, res, next){
45             res.send(req.ips);
46           });
48           request(app)
49           .get('/')
50           .set('X-Forwarded-For', 'client, p1, p2')
51           .expect('[]', done);
52         })
53       })
54     })
56     describe('when X-Forwarded-For is not present', function(){
57       it('should return []', function(done){
58         var app = express();
60         app.use(function(req, res, next){
61           res.send(req.ips);
62         });
64         request(app)
65         .get('/')
66         .expect('[]', done);
67       })
68     })
69   })