koa-lite/test/request/subdomains.js

29 lines
765 B
JavaScript
Raw Permalink Normal View History

2014-07-06 08:43:14 +00:00
'use strict';
2017-05-11 03:30:32 +00:00
const assert = require('assert');
const request = require('../helpers/context').request;
2014-07-06 08:43:14 +00:00
describe('req.subdomains', () => {
it('should return subdomain array', () => {
const req = request();
2014-07-06 08:43:14 +00:00
req.header.host = 'tobi.ferrets.example.com';
req.app.subdomainOffset = 2;
2017-05-11 03:30:32 +00:00
assert.deepEqual(req.subdomains, ['ferrets', 'tobi']);
2014-07-06 08:43:14 +00:00
req.app.subdomainOffset = 3;
2017-05-11 03:30:32 +00:00
assert.deepEqual(req.subdomains, ['tobi']);
2015-10-12 20:36:41 +00:00
});
2014-07-06 08:43:14 +00:00
it('should work with no host present', () => {
const req = request();
2017-05-11 03:30:32 +00:00
assert.deepEqual(req.subdomains, []);
2015-10-12 20:36:41 +00:00
});
it('should check if the host is an ip address, even with a port', () => {
const req = request();
req.header.host = '127.0.0.1:3000';
2017-05-11 03:30:32 +00:00
assert.deepEqual(req.subdomains, []);
});
2015-10-12 20:36:41 +00:00
});