mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
81 lines
1.7 KiB
JavaScript
81 lines
1.7 KiB
JavaScript
|
|
var express = require('../')
|
|
, request = require('supertest');
|
|
|
|
describe('req', function(){
|
|
describe('.protocol', function(){
|
|
it('should return the protocol string', function(done){
|
|
var app = express();
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.expect('http', done);
|
|
})
|
|
|
|
describe('when "trust proxy" is enabled', function(){
|
|
it('should respect X-Forwarded-Proto', function(done){
|
|
var app = express();
|
|
|
|
app.enable('trust proxy');
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.set('X-Forwarded-Proto', 'https')
|
|
.expect('https', done);
|
|
})
|
|
|
|
it('should ignore X-Forwarded-Proto if socket addr not trusted', function(done){
|
|
var app = express();
|
|
|
|
app.set('trust proxy', '10.0.0.1');
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.set('X-Forwarded-Proto', 'https')
|
|
.expect('http', done);
|
|
})
|
|
|
|
it('should default to http', function(done){
|
|
var app = express();
|
|
|
|
app.enable('trust proxy');
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.expect('http', done);
|
|
})
|
|
})
|
|
|
|
describe('when "trust proxy" is disabled', function(){
|
|
it('should ignore X-Forwarded-Proto', function(done){
|
|
var app = express();
|
|
|
|
app.use(function(req, res){
|
|
res.end(req.protocol);
|
|
});
|
|
|
|
request(app)
|
|
.get('/')
|
|
.set('X-Forwarded-Proto', 'https')
|
|
.expect('http', done);
|
|
})
|
|
})
|
|
})
|
|
})
|