mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Updated vhost middleware upstream test
refs 8255bfdfda
- the original project had a commit which fixes a specific test for
missing host headers
- funnily enough, this was our only missing coverage on this package, so
we achieve 100% with this
This commit is contained in:
parent
ac4ff8ada4
commit
590bd7bdb8
1 changed files with 13 additions and 5 deletions
|
@ -102,7 +102,16 @@ describe('vhost(hostname, server)', function () {
|
||||||
vhosts.push(vhost('tobi.com', tobi));
|
vhosts.push(vhost('tobi.com', tobi));
|
||||||
vhosts.push(vhost('loki.com', loki));
|
vhosts.push(vhost('loki.com', loki));
|
||||||
|
|
||||||
const app = createServer(vhosts);
|
const server = createServer(vhosts);
|
||||||
|
const listeners = server.listeners('request');
|
||||||
|
|
||||||
|
server.removeAllListeners('request');
|
||||||
|
listeners.unshift(function (req) {
|
||||||
|
req.headers.host = undefined;
|
||||||
|
});
|
||||||
|
listeners.forEach(function (l) {
|
||||||
|
server.addListener('request', l);
|
||||||
|
});
|
||||||
|
|
||||||
function tobi(req, res) {
|
function tobi(req, res) {
|
||||||
res.end('tobi');
|
res.end('tobi');
|
||||||
|
@ -111,10 +120,9 @@ describe('vhost(hostname, server)', function () {
|
||||||
res.end('loki');
|
res.end('loki');
|
||||||
}
|
}
|
||||||
|
|
||||||
request(app)
|
request(server)
|
||||||
.get('/')
|
.get('/')
|
||||||
.unset('Host')
|
.expect(404, 'no vhost for "undefined"', done);
|
||||||
.expect(404, done);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('arguments', function () {
|
describe('arguments', function () {
|
||||||
|
@ -277,7 +285,7 @@ function createServer(hostname, server, pretest) {
|
||||||
|
|
||||||
if (!vhost || err) {
|
if (!vhost || err) {
|
||||||
res.statusCode = err ? (err.status || 500) : 404;
|
res.statusCode = err ? (err.status || 500) : 404;
|
||||||
res.end(err ? err.message : 'oops');
|
res.end(err ? err.message : `no vhost for "${req.headers.host}"`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue