Skip to content

Commit

Permalink
tests: add test for multiple ips in "trust proxy"
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 2, 2022
1 parent da6cb0e commit 744564f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/req.ip.js
Expand Up @@ -21,7 +21,7 @@ describe('req', function(){
.expect('client', done);
})

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

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

it('should return the addr after trusted proxy based on list', function (done) {
var app = express()

app.set('trust proxy', '10.0.0.1, 10.0.0.2, 127.0.0.1, ::1')

app.get('/', function (req, res) {
res.send(req.ip)
})

request(app)
.get('/')
.set('X-Forwarded-For', '10.0.0.2, 10.0.0.3, 10.0.0.1', '10.0.0.4')
.expect('10.0.0.3', done)
})

it('should return the addr after trusted proxy, from sub app', function (done) {
var app = express();
var sub = express();
Expand Down

0 comments on commit 744564f

Please sign in to comment.