2013-11-13 17:01:15 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-12 04:59:30 +00:00
|
|
|
const request = require('../helpers/context').request;
|
2015-10-05 18:23:47 +00:00
|
|
|
const assert = require('assert');
|
2013-11-13 17:01:15 +00:00
|
|
|
|
|
|
|
describe('req.host', function(){
|
2014-02-26 06:03:05 +00:00
|
|
|
it('should return host with port', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2013-11-13 17:01:15 +00:00
|
|
|
req.header.host = 'foo.com:3000';
|
2014-02-26 06:03:05 +00:00
|
|
|
req.host.should.equal('foo.com:3000');
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
|
2014-07-06 08:43:14 +00:00
|
|
|
describe('with no host present', function(){
|
2015-03-30 09:37:47 +00:00
|
|
|
it('should return ""', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2015-03-30 09:37:47 +00:00
|
|
|
assert.equal(req.host, '');
|
2014-07-06 08:43:14 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2013-11-13 17:01:15 +00:00
|
|
|
describe('when X-Forwarded-Host is present', function(){
|
|
|
|
describe('and proxy is not trusted', function(){
|
|
|
|
it('should be ignored', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2013-11-13 17:01:15 +00:00
|
|
|
req.header['x-forwarded-host'] = 'bar.com';
|
|
|
|
req.header['host'] = 'foo.com';
|
2014-05-04 14:43:58 +00:00
|
|
|
req.host.should.equal('foo.com');
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and proxy is trusted', function(){
|
|
|
|
it('should be used', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2013-11-13 17:01:15 +00:00
|
|
|
req.app.proxy = true;
|
|
|
|
req.header['x-forwarded-host'] = 'bar.com, baz.com';
|
|
|
|
req.header['host'] = 'foo.com';
|
2014-05-04 14:43:58 +00:00
|
|
|
req.host.should.equal('bar.com');
|
2013-11-13 17:01:15 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-01-07 19:01:11 +00:00
|
|
|
})
|