mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 00:15:11 +03:00
Moved useful subdir and https tests to acceptance
- These tests protect some advanced, yet important behaviour around URLs - Moved them out of regression tests into acceptance, as we're slowly trying to clean up regression tests :)
This commit is contained in:
parent
ed5fa4d3ad
commit
03bf1c9671
148
test/frontend-acceptance/advanced_url_config_spec.js
Normal file
148
test/frontend-acceptance/advanced_url_config_spec.js
Normal file
@ -0,0 +1,148 @@
|
||||
const should = require('should');
|
||||
const supertest = require('supertest');
|
||||
const testUtils = require('../utils');
|
||||
const configUtils = require('../utils/configUtils');
|
||||
const urlUtils = require('../utils/urlUtils');
|
||||
const config = require('../../core/shared/config');
|
||||
const ghost = testUtils.startGhost;
|
||||
|
||||
let request;
|
||||
|
||||
/**
|
||||
* This file contains extra acceptance tests for complex URL configurations
|
||||
* Examples of acceptance tests that belong here:
|
||||
* - subdirectories
|
||||
* - https
|
||||
* - (maybe) admin + frontend URL are different
|
||||
* - etc
|
||||
*/
|
||||
|
||||
describe('Advanced URL Configurations', function () {
|
||||
function doEnd(done) {
|
||||
return function (err, res) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
should.not.exist(res.headers['X-CSRF-Token']);
|
||||
should.not.exist(res.headers['set-cookie']);
|
||||
should.exist(res.headers.date);
|
||||
|
||||
done();
|
||||
};
|
||||
}
|
||||
|
||||
describe('Subdirectory config', function () {
|
||||
let ghostServer;
|
||||
|
||||
before(function () {
|
||||
configUtils.set('url', 'http://localhost/blog/');
|
||||
urlUtils.stubUrlUtilsFromConfig();
|
||||
|
||||
return ghost({forceStart: true, subdir: true})
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
||||
});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
configUtils.restore();
|
||||
urlUtils.restore();
|
||||
});
|
||||
|
||||
it('http://localhost should 404', function (done) {
|
||||
request.get('/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog should 301 to /blog/', function (done) {
|
||||
request.get('/blog')
|
||||
.expect(301)
|
||||
.expect('Location', '/blog/')
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/ should 200', function (done) {
|
||||
request.get('/blog/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/welcome/ should 200', function (done) {
|
||||
request.get('/blog/welcome/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/welcome/ should 404', function (done) {
|
||||
request.get('/welcome/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/tag/getting-started/ should 200', function (done) {
|
||||
request.get('/blog/tag/getting-started/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/tag/getting-started/ should 404', function (done) {
|
||||
request.get('/tag/getting-started/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/welcome/amp/ should 200', function (done) {
|
||||
request.get('/blog/welcome/amp/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/welcome/amp/ should 404', function (done) {
|
||||
request.get('/welcome/amp/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
});
|
||||
|
||||
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
|
||||
describe('HTTPS', function () {
|
||||
let ghostServer;
|
||||
|
||||
before(function () {
|
||||
configUtils.set('url', 'http://localhost:2370/');
|
||||
urlUtils.stubUrlUtilsFromConfig();
|
||||
|
||||
return ghost({forceStart: true})
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
||||
});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
configUtils.restore();
|
||||
urlUtils.restore();
|
||||
});
|
||||
|
||||
it('should set links to url over non-HTTPS', function (done) {
|
||||
request.get('/')
|
||||
.expect(200)
|
||||
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
||||
.expect(/<a href="http:\/\/localhost:2370">Ghost<\/a\>/)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('should set links over HTTPS besides canonical', function (done) {
|
||||
request.get('/')
|
||||
.set('X-Forwarded-Proto', 'https')
|
||||
.expect(200)
|
||||
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
||||
.expect(/<a href="https:\/\/localhost:2370">Ghost<\/a\>/)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
});
|
||||
});
|
@ -6,15 +6,12 @@ const should = require('should');
|
||||
|
||||
const sinon = require('sinon');
|
||||
const supertest = require('supertest');
|
||||
const moment = require('moment');
|
||||
const cheerio = require('cheerio');
|
||||
const _ = require('lodash');
|
||||
const testUtils = require('../../utils');
|
||||
const configUtils = require('../../utils/configUtils');
|
||||
const urlUtils = require('../../utils/urlUtils');
|
||||
const config = require('../../../core/shared/config');
|
||||
const settingsCache = require('../../../core/server/services/settings/cache');
|
||||
const origCache = _.cloneDeep(settingsCache);
|
||||
const ghost = testUtils.startGhost;
|
||||
let request;
|
||||
|
||||
@ -292,119 +289,6 @@ describe('Frontend Routing', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subdirectory config', function () {
|
||||
let ghostServer;
|
||||
|
||||
before(function () {
|
||||
configUtils.set('url', 'http://localhost/blog/');
|
||||
urlUtils.stubUrlUtilsFromConfig();
|
||||
|
||||
return ghost({forceStart: true, subdir: true})
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
||||
});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
configUtils.restore();
|
||||
urlUtils.restore();
|
||||
});
|
||||
|
||||
it('http://localhost should 404', function (done) {
|
||||
request.get('/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog should 301 to /blog/', function (done) {
|
||||
request.get('/blog')
|
||||
.expect(301)
|
||||
.expect('Location', '/blog/')
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/ should 200', function (done) {
|
||||
request.get('/blog/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/welcome/ should 200', function (done) {
|
||||
request.get('/blog/welcome/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/welcome/ should 404', function (done) {
|
||||
request.get('/welcome/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/tag/getting-started/ should 200', function (done) {
|
||||
request.get('/blog/tag/getting-started/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/tag/getting-started/ should 404', function (done) {
|
||||
request.get('/tag/getting-started/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/blog/welcome/amp/ should 200', function (done) {
|
||||
request.get('/blog/welcome/amp/')
|
||||
.expect(200)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('/welcome/amp/ should 404', function (done) {
|
||||
request.get('/welcome/amp/')
|
||||
.expect(404)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
});
|
||||
|
||||
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
|
||||
describe('HTTPS', function () {
|
||||
let ghostServer;
|
||||
|
||||
before(function () {
|
||||
configUtils.set('url', 'http://localhost:2370/');
|
||||
urlUtils.stubUrlUtilsFromConfig();
|
||||
|
||||
return ghost({forceStart: true})
|
||||
.then(function (_ghostServer) {
|
||||
ghostServer = _ghostServer;
|
||||
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
|
||||
});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
configUtils.restore();
|
||||
urlUtils.restore();
|
||||
});
|
||||
|
||||
it('should set links to url over non-HTTPS', function (done) {
|
||||
request.get('/')
|
||||
.expect(200)
|
||||
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
||||
.expect(/<a href="http:\/\/localhost:2370">Ghost<\/a\>/)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
|
||||
it('should set links over HTTPS besides canonical', function (done) {
|
||||
request.get('/')
|
||||
.set('X-Forwarded-Proto', 'https')
|
||||
.expect(200)
|
||||
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
|
||||
.expect(/<a href="https:\/\/localhost:2370">Ghost<\/a\>/)
|
||||
.end(doEnd(done));
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: convert to unit tests
|
||||
const redirectsFileExts = ['.json', '.yaml'];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user