forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
req.ip.js
57 lines (45 loc) · 1.37 KB
/
req.ip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var express = require('../')
, request = require('./support/http');
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);
})
})
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);
})
})
})
})