Skip to content

Commit 1d41c1d

Browse files
dougwilsonhimanshiLt
authored andcommitted
tests: add test for multiple ips in "trust proxy"
1 parent 7078514 commit 1d41c1d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/req.ip.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('req', function(){
2121
.expect('client', done);
2222
})
2323

24-
it('should return the addr after trusted proxy', function(done){
24+
it('should return the addr after trusted proxy based on count', function (done) {
2525
var app = express();
2626

2727
app.set('trust proxy', 2);
@@ -36,6 +36,21 @@ describe('req', function(){
3636
.expect('p1', done);
3737
})
3838

39+
it('should return the addr after trusted proxy based on list', function (done) {
40+
var app = express()
41+
42+
app.set('trust proxy', '10.0.0.1, 10.0.0.2, 127.0.0.1, ::1')
43+
44+
app.get('/', function (req, res) {
45+
res.send(req.ip)
46+
})
47+
48+
request(app)
49+
.get('/')
50+
.set('X-Forwarded-For', '10.0.0.2, 10.0.0.3, 10.0.0.1', '10.0.0.4')
51+
.expect('10.0.0.3', done)
52+
})
53+
3954
it('should return the addr after trusted proxy, from sub app', function (done) {
4055
var app = express();
4156
var sub = express();

0 commit comments

Comments
 (0)