2014-02-26 06:03:05 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-05 18:23:47 +00:00
|
|
|
const request = require('../context').request;
|
|
|
|
const assert = require('assert');
|
2014-02-26 06:03:05 +00:00
|
|
|
|
|
|
|
describe('req.hostname', function(){
|
|
|
|
it('should return hostname void of port', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-02-26 06:03:05 +00:00
|
|
|
req.header.host = 'foo.com:3000';
|
|
|
|
req.hostname.should.equal('foo.com');
|
|
|
|
})
|
|
|
|
|
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.hostname, '');
|
2014-07-06 08:43:14 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-02-26 06:03:05 +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();
|
2014-02-26 06:03:05 +00:00
|
|
|
req.header['x-forwarded-host'] = 'bar.com';
|
|
|
|
req.header['host'] = 'foo.com';
|
|
|
|
req.hostname.should.equal('foo.com')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('and proxy is trusted', function(){
|
|
|
|
it('should be used', function(){
|
2015-10-05 18:23:47 +00:00
|
|
|
const req = request();
|
2014-02-26 06:03:05 +00:00
|
|
|
req.app.proxy = true;
|
|
|
|
req.header['x-forwarded-host'] = 'bar.com, baz.com';
|
|
|
|
req.header['host'] = 'foo.com';
|
|
|
|
req.hostname.should.equal('bar.com')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|