2021-05-27 16:43:56 +03:00
|
|
|
const should = require('should');
|
2022-01-14 19:55:48 +03:00
|
|
|
const sinon = require('sinon');
|
2021-05-27 16:43:56 +03:00
|
|
|
const supertest = require('supertest');
|
|
|
|
const testUtils = require('../utils');
|
|
|
|
const configUtils = require('../utils/configUtils');
|
|
|
|
const urlUtils = require('../utils/urlUtils');
|
2022-01-14 19:55:48 +03:00
|
|
|
const settings = require('../../core/shared/settings-cache');
|
2021-05-27 16:43:56 +03:00
|
|
|
|
|
|
|
let request;
|
|
|
|
|
|
|
|
/**
|
2021-10-06 14:25:49 +03:00
|
|
|
* This file contains extra e2e tests for complex URL configurations
|
|
|
|
* Examples of e2e tests that belong here:
|
2021-05-27 16:43:56 +03:00
|
|
|
* - subdirectories
|
|
|
|
* - https
|
|
|
|
* - (maybe) admin + frontend URL are different
|
|
|
|
* - etc
|
|
|
|
*/
|
|
|
|
|
|
|
|
describe('Advanced URL Configurations', function () {
|
|
|
|
describe('Subdirectory config', function () {
|
2021-05-27 19:50:14 +03:00
|
|
|
before(async function () {
|
2021-05-27 16:43:56 +03:00
|
|
|
configUtils.set('url', 'http://localhost/blog/');
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
await testUtils.startGhost({forceStart: true});
|
|
|
|
|
|
|
|
request = supertest.agent(configUtils.config.get('server:host') + ':' + configUtils.config.get('server:port'));
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
|
|
|
|
2022-01-14 19:55:48 +03:00
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('http://localhost should 404', async function () {
|
|
|
|
await request.get('/')
|
|
|
|
.expect(404);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('/blog should 301 to /blog/', async function () {
|
|
|
|
await request.get('/blog')
|
2021-05-27 16:43:56 +03:00
|
|
|
.expect(301)
|
2021-05-27 19:50:14 +03:00
|
|
|
.expect('Location', '/blog/');
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('/blog/ should 200', async function () {
|
|
|
|
await request.get('/blog/')
|
|
|
|
.expect(200);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('/blog/welcome/ should 200', async function () {
|
|
|
|
await request.get('/blog/welcome/')
|
|
|
|
.expect(200);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('/welcome/ should 404', async function () {
|
|
|
|
await request.get('/welcome/')
|
|
|
|
.expect(404);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('/blog/tag/getting-started/ should 200', async function () {
|
|
|
|
await request.get('/blog/tag/getting-started/')
|
|
|
|
.expect(200);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('/tag/getting-started/ should 404', async function () {
|
|
|
|
await request.get('/tag/getting-started/')
|
|
|
|
.expect(404);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2022-01-14 19:55:48 +03:00
|
|
|
it('/blog/welcome/amp/ should 200 if amp is enabled', async function () {
|
|
|
|
sinon.stub(settings, 'get').callsFake(function (key, ...rest) {
|
|
|
|
if (key === 'amp') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return settings.get.wrappedMethod.call(settings, key, ...rest);
|
|
|
|
});
|
2021-05-27 19:50:14 +03:00
|
|
|
await request.get('/blog/welcome/amp/')
|
|
|
|
.expect(200);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2022-01-14 19:55:48 +03:00
|
|
|
it('/blog/welcome/amp/ should 301', async function () {
|
|
|
|
await request.get('/blog/welcome/amp/')
|
|
|
|
.expect(301);
|
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('/welcome/amp/ should 404', async function () {
|
|
|
|
await request.get('/welcome/amp/')
|
|
|
|
.expect(404);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
|
|
|
|
describe('HTTPS', function () {
|
2021-05-27 19:50:14 +03:00
|
|
|
before(async function () {
|
2021-05-27 16:43:56 +03:00
|
|
|
configUtils.set('url', 'http://localhost:2370/');
|
|
|
|
urlUtils.stubUrlUtilsFromConfig();
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
await testUtils.startGhost({forceStart: true});
|
|
|
|
|
|
|
|
request = supertest.agent(configUtils.config.get('server:host') + ':' + configUtils.config.get('server:port'));
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
configUtils.restore();
|
|
|
|
urlUtils.restore();
|
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('should set links to url over non-HTTPS', async function () {
|
|
|
|
await request.get('/')
|
2021-05-27 16:43:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
2021-05-27 19:50:14 +03:00
|
|
|
.expect(/<a href="http:\/\/localhost:2370">Ghost<\/a\>/);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
|
2021-05-27 19:50:14 +03:00
|
|
|
it('should set links over HTTPS besides canonical', async function () {
|
|
|
|
await request.get('/')
|
2021-05-27 16:43:56 +03:00
|
|
|
.set('X-Forwarded-Proto', 'https')
|
|
|
|
.expect(200)
|
|
|
|
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
2021-05-27 19:50:14 +03:00
|
|
|
.expect(/<a href="https:\/\/localhost:2370">Ghost<\/a\>/);
|
2021-05-27 16:43:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|