req.ip.js
This file
Path
test/req.ip.js
72 lines · 1.7 KiB · JavaScript
Last changed by
remove unnecessary test/support/httpJonathan Ongbefore adoption328c6d3
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
var express = require('../') , request = require('supertest');
describe('req', function(){ describe('.ip', function(){ describe('when X-Forwarded-For is present', function(){ describe('when "trust proxy" is enabled', function(){ it('should return the client addr', function(done){ var app = express();
app.enable('trust proxy');
app.use(function(req, res, next){ res.send(req.ip); });
request(app) .get('/') .set('X-Forwarded-For', 'client, p1, p2') .expect('client', done); })
it('should return the addr after trusted proxy', function(done){ var app = express();
app.set('trust proxy', 2);
app.use(function(req, res, next){ res.send(req.ip); });
request(app) .get('/') .set('X-Forwarded-For', 'client, p1, p2') .expect('p1', done); }) })
describe('when "trust proxy" is disabled', function(){ it('should return the remote address', function(done){ var app = express();
app.use(function(req, res, next){ res.send(req.ip); });
request(app) .get('/') .set('X-Forwarded-For', 'client, p1, p2') .expect('127.0.0.1', done); }) }) })
describe('when X-Forwarded-For is not present', function(){ it('should return the remote address', function(done){ var app = express();
app.enable('trust proxy');
app.use(function(req, res, next){ res.send(req.ip); });
request(app) .get('/') .expect('127.0.0.1', done); }) }) })})