2021-02-24 03:55:54 +03:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
|
|
|
const _ = require('lodash');
|
2021-10-08 15:50:37 +03:00
|
|
|
const testUtils = require('../../utils');
|
2021-10-20 14:27:20 +03:00
|
|
|
const localUtils = require('./utils');
|
2021-10-08 15:50:37 +03:00
|
|
|
const adminUtils = require('../../utils/admin-utils');
|
|
|
|
const configUtils = require('../../utils/configUtils');
|
|
|
|
const urlUtils = require('../../utils/urlUtils');
|
|
|
|
const themeEngine = require('../../../core/frontend/services/theme-engine');
|
2021-02-24 03:55:54 +03:00
|
|
|
|
|
|
|
describe('Integration - Web - vhosts', function () {
|
|
|
|
let app;
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
before(localUtils.urlService.resetGenerators);
|
2021-02-24 03:55:54 +03:00
|
|
|
before(testUtils.teardownDb);
|
|
|
|
before(testUtils.setup('users:roles', 'posts'));
|
2021-07-05 22:02:22 +03:00
|
|
|
before(adminUtils.stubClientFiles);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('no separate admin', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {amp: true});
|
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
|
|
|
configUtils.set('url', 'http://example.com');
|
|
|
|
configUtils.set('admin:url', null);
|
|
|
|
|
2021-10-20 12:10:50 +03:00
|
|
|
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
|
|
|
|
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 03:55:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
configUtils.set('url', 'http://example.com');
|
|
|
|
configUtils.set('admin:url', null);
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the front-end on configured url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the front-end on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the admin', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the admin on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the api', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the api on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('separate admin host', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {amp: true});
|
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
|
|
|
configUtils.set('url', 'http://example.com');
|
|
|
|
configUtils.set('admin:url', 'https://admin.example.com');
|
|
|
|
|
2021-10-20 12:10:50 +03:00
|
|
|
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
|
|
|
|
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 03:55:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the front-end on configured url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the front-end on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects /ghost/ on configured url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://admin.example.com/ghost/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('404s the api on configured url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('404s the api on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the admin on configured admin url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: true,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'admin.example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the api on configured admin url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: true,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'admin.example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects to the correct protocol on configured admin url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'admin.example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://admin.example.com/ghost/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('404s the front-end on configured admin url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'admin.example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('separate admin host w/ admin redirects disabled', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {amp: true});
|
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
|
|
|
configUtils.set('url', 'http://example.com');
|
|
|
|
configUtils.set('admin:url', 'https://admin.example.com');
|
|
|
|
configUtils.set('admin:redirects', false);
|
|
|
|
|
2021-10-20 12:10:50 +03:00
|
|
|
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
|
|
|
|
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 03:55:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not redirect /ghost/ on configured url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(404);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('same host separate protocol', function () {
|
2021-10-20 12:10:50 +03:00
|
|
|
before(async function () {
|
2021-10-20 14:27:20 +03:00
|
|
|
localUtils.urlService.resetGenerators();
|
|
|
|
localUtils.defaultMocks(sinon, {amp: true});
|
|
|
|
localUtils.overrideGhostConfig(configUtils);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
|
|
|
configUtils.set('url', 'http://example.com');
|
|
|
|
configUtils.set('admin:url', 'https://example.com');
|
|
|
|
|
2021-10-20 12:10:50 +03:00
|
|
|
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
|
|
|
|
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
|
2021-02-24 03:55:54 +03:00
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
app = await localUtils.initGhost();
|
2021-02-24 03:55:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the front-end on configured url (http)', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('404s the front-end on configured url (https)', function () {
|
|
|
|
const req = {
|
|
|
|
secure: true,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the front-end on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects /ghost/ on configured url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/ghost/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects /ghost/ on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/ghost/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects api to correct protocol on configured admin url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/ghost/api/v2/admin/site/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the admin on configured admin url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: true,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects the admin on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/ghost/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('loads the api on configured admin url', function () {
|
|
|
|
const req = {
|
|
|
|
secure: true,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'example.com'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(200);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('redirects the api on localhost', function () {
|
|
|
|
const req = {
|
|
|
|
secure: false,
|
|
|
|
method: 'GET',
|
|
|
|
url: '/ghost/api/v2/admin/site/',
|
|
|
|
host: 'localhost'
|
|
|
|
};
|
|
|
|
|
2021-10-20 14:27:20 +03:00
|
|
|
return localUtils.mockExpress.invoke(app, req)
|
2021-02-24 03:55:54 +03:00
|
|
|
.then(function (response) {
|
|
|
|
response.statusCode.should.eql(301);
|
|
|
|
response.headers.location.should.eql('https://example.com/ghost/api/v2/admin/site/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|