2020-03-20 13:23:56 +03:00
|
|
|
// # Default Frontend Routing Test
|
|
|
|
// These tests check the default out-of-the-box behaviour of Ghost is working as expected.
|
|
|
|
|
|
|
|
// Test Structure
|
|
|
|
// As it stands, these tests depend on the database, and as such are integration tests.
|
|
|
|
// Mocking out the models to not touch the DB would turn these into unit tests, and should probably be done in future,
|
|
|
|
// But then again testing real code, rather than mock code, might be more useful...
|
2020-04-25 23:06:33 +03:00
|
|
|
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');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../core/shared/config');
|
2020-04-25 23:06:33 +03:00
|
|
|
const settingsCache = require('../../core/server/services/settings/cache');
|
|
|
|
const origCache = _.cloneDeep(settingsCache);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
|
|
|
describe('Default Frontend routing', function () {
|
2020-04-25 23:06:33 +03:00
|
|
|
let request;
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
function doEnd(res) {
|
|
|
|
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);
|
2020-03-20 13:23:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
|
|
|
await testUtils.startGhost();
|
|
|
|
request = supertest.agent(config.get('url'));
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Error', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should 404 for unknown post', async function () {
|
|
|
|
const res = await request.get('/spectacular/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(/Page not found/);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should 404 for unknown file', async function () {
|
|
|
|
const res = await request.get('/content/images/some/file/that/doesnt-exist.jpg')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(/404 Image not found/);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Main Routes', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/ should respond with valid HTML', async function () {
|
|
|
|
const res = await request.get('/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const $ = cheerio.load(res.text);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
// NOTE: "Ghost" is the title from the settings.
|
|
|
|
$('title').text().should.equal('Ghost');
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
$('body.home-template').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(7);
|
|
|
|
$('article.tag-getting-started').length.should.equal(7);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/author/ghost/ should respond with valid HTML', async function () {
|
|
|
|
const res = await request.get('/author/ghost/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const $ = cheerio.load(res.text);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
// NOTE: "Ghost" is the title from the settings.
|
|
|
|
$('title').text().should.equal('Ghost - Ghost');
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
$('body.author-template').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(7);
|
|
|
|
$('article.tag-getting-started').length.should.equal(7);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/tag/getting-started/ should respond with valid HTML', async function () {
|
|
|
|
const res = await request.get('/tag/getting-started/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const $ = cheerio.load(res.text);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
// NOTE: "Ghost" is the title from the settings.
|
|
|
|
$('title').text().should.equal('Getting Started - Ghost');
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
$('body.tag-template').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(7);
|
|
|
|
$('article.tag-getting-started').length.should.equal(7);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Single post', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/welcome/ should respond with valid HTML', async function () {
|
|
|
|
const res = await request.get('/welcome/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const $ = cheerio.load(res.text);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
// NOTE: This is the title from the settings.
|
|
|
|
$('title').text().should.equal('Welcome to Ghost');
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
$('body.post-template').length.should.equal(1);
|
|
|
|
$('body.tag-getting-started').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(2);
|
|
|
|
$('article.tag-getting-started').length.should.equal(2);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not work with date permalinks', async function () {
|
2020-03-20 13:23:56 +03:00
|
|
|
// get today's date
|
2020-04-25 23:06:33 +03:00
|
|
|
const date = moment().format('YYYY/MM/DD');
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request.get('/' + date + '/welcome/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(/Page not found/);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Post edit', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should redirect to editor', async function () {
|
|
|
|
const res = await request.get('/welcome/edit/')
|
2020-05-30 11:40:11 +03:00
|
|
|
.expect('Location', /ghost\/#\/editor\/\w+/)
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(302);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should 404 for non-edit parameter', async function () {
|
|
|
|
const res = await request.get('/welcome/notedit/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(/Page not found/);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Admin Redirects Disabled', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
2020-03-20 13:23:56 +03:00
|
|
|
configUtils.set('admin:redirects', false);
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
await testUtils.startGhost({forceStart: true});
|
|
|
|
request = supertest.agent(config.get('url'));
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
after(async function () {
|
2020-03-20 13:23:56 +03:00
|
|
|
configUtils.restore();
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
await testUtils.startGhost({forceStart: true});
|
|
|
|
request = supertest.agent(config.get('url'));
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/edit/ should NOT redirect to the editor', async function () {
|
|
|
|
const res = await request.get('/welcome/edit/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(404);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('AMP post', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should respond with html for valid url', async function () {
|
|
|
|
const res = await request.get('/welcome/amp/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Content-Type', /html/)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const $ = cheerio.load(res.text);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
$('.post-title').text().should.equal('Welcome to Ghost');
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
$('.content .post').length.should.equal(1);
|
|
|
|
$('.powered').text().should.equal(' Published with Ghost');
|
|
|
|
$('body.amp-template').length.should.equal(1);
|
|
|
|
$('article.post').length.should.equal(1);
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should not work with date permalinks', async function () {
|
2020-03-20 13:23:56 +03:00
|
|
|
// get today's date
|
2020-04-25 23:06:33 +03:00
|
|
|
const date = moment().format('YYYY/MM/DD');
|
2020-03-20 13:23:56 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request.get('/' + date + '/welcome/amp/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
|
|
|
.expect(404)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(/Page not found/);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('AMP Disabled', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/amp/ should redirect to regular post, including any query params', async function () {
|
2020-03-20 13:23:56 +03:00
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
|
|
|
if (key === 'amp' && !options) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return origCache.get(key, options);
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request.get('/welcome/amp/?q=a')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Location', '/welcome/?q=a')
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(301);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('RSS', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/rss/ should serve an RSS feed', async function () {
|
|
|
|
const res = await request.get('/rss/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/<!\[CDATA\[Welcome to Ghost\]\]>/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/author/ghost/rss/ should serve an RSS feed', async function () {
|
|
|
|
const res = await request.get('/author/ghost/rss/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/<!\[CDATA\[Welcome to Ghost\]\]>/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/tag/getting-started/rss/ should serve an RSS feed', async function () {
|
|
|
|
const res = await request.get('/tag/getting-started/rss/')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.public)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/<!\[CDATA\[Welcome to Ghost\]\]>/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Static assets', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should retrieve theme assets', async function () {
|
|
|
|
const res = await request.get('/assets/css/screen.css')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.year)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should retrieve default robots.txt', async function () {
|
|
|
|
const res = await request.get('/robots.txt')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
|
|
|
.expect('ETag', /[0-9a-f]{32}/i)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should retrieve default favicon.ico', async function () {
|
|
|
|
const res = await request.get('/favicon.ico')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect('Cache-Control', testUtils.cacheRules.day)
|
|
|
|
.expect('ETag', /[0-9a-f]{32}/i)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Site Map', function () {
|
2020-11-30 17:25:22 +03:00
|
|
|
before(async function () {
|
|
|
|
await testUtils.clearData();
|
|
|
|
await testUtils.initData();
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve sitemap.xml', async function () {
|
|
|
|
const res = await request.get('/sitemap.xml')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/sitemapindex/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve sitemap-posts.xml', async function () {
|
|
|
|
const res = await request.get('/sitemap-posts.xml')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve sitemap-pages.xml', async function () {
|
|
|
|
const res = await request.get('/sitemap-pages.xml')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve sitemap-tags.xml', async function () {
|
|
|
|
const res = await request.get('/sitemap-tags.xml')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve sitemap-users.xml', async function () {
|
|
|
|
const res = await request.get('/sitemap-users.xml')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.hour)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve sitemap.xsl', async function () {
|
|
|
|
const res = await request.get('/sitemap.xsl')
|
2020-03-20 13:23:56 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.day)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xsl');
|
|
|
|
|
|
|
|
res.text.should.match(/urlset/);
|
|
|
|
doEnd(res);
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|
|
|
|
});
|
2020-03-20 14:16:59 +03:00
|
|
|
|
|
|
|
describe('Private Blogging', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
sinon.stub(settingsCache, 'get').callsFake(function (key, options) {
|
|
|
|
if (key === 'is_private') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return origCache.get(key, options);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/ should redirect to /private/', async function () {
|
|
|
|
const res = await request.get('/')
|
2020-03-20 14:16:59 +03:00
|
|
|
.expect('Location', '/private/?r=%2F')
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(302);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 14:16:59 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/welcome/ should redirect to /private/', async function () {
|
|
|
|
const res = await request.get('/welcome/')
|
2020-03-20 14:16:59 +03:00
|
|
|
.expect('Location', '/private/?r=%2Fwelcome%2F')
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(302);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-03-20 14:16:59 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('/private/?r=%2Fwelcome%2F should not redirect', async function () {
|
|
|
|
const res = await request.get('/private/?r=%2Fwelcome%2F')
|
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-06-16 13:42:32 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should redirect, NOT 404 for private route with extra path', async function () {
|
|
|
|
const res = await request.get('/private/welcome/')
|
2020-06-16 13:42:32 +03:00
|
|
|
.expect('Location', '/private/?r=%2Fprivate%2Fwelcome%2F')
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(302);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-06-16 13:42:32 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should still serve private RSS feed', async function () {
|
|
|
|
const res = await request.get(`/${settingsCache.get('public_hash')}/rss/`)
|
2020-03-20 14:16:59 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/<!\[CDATA\[Welcome to Ghost\]\]>/);
|
|
|
|
doEnd(res);
|
2020-03-20 14:16:59 +03:00
|
|
|
});
|
2020-06-16 13:42:32 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should still serve private tag RSS feed', async function () {
|
|
|
|
const res = await request.get(`/tag/getting-started/${settingsCache.get('public_hash')}/rss/`)
|
2020-06-16 13:42:32 +03:00
|
|
|
.expect(200)
|
|
|
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect('Content-Type', 'text/xml; charset=utf-8');
|
|
|
|
|
|
|
|
res.text.should.match(/<!\[CDATA\[Welcome to Ghost\]\]>/);
|
|
|
|
doEnd(res);
|
2020-06-16 13:42:32 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should redirect, NOT 404 for private tag RSS feed with extra path', async function () {
|
|
|
|
const res = await request.get(`/tag/getting-started/${settingsCache.get('public_hash')}/rss/hack/`)
|
2020-06-16 13:42:32 +03:00
|
|
|
.expect('Location', `/private/?r=%2Ftag%2Fgetting-started%2F${settingsCache.get('public_hash')}%2Frss%2Fhack%2F`)
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(302);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-06-16 13:42:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: this case is covered by extra error handling, and cannot be unit tested
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should redirect, NOT 404 for unknown private RSS feed', async function () {
|
2020-06-16 13:42:32 +03:00
|
|
|
// NOTE: the redirect will be to /hack/rss because we strip the hash from the URL before trying to serve RSS
|
|
|
|
// This isn't ideal, but it's better to expose this internal logic than it is a 404 page
|
2020-11-30 17:25:22 +03:00
|
|
|
const res = await request.get(`/hack/${settingsCache.get('public_hash')}/rss/`)
|
2020-06-16 13:42:32 +03:00
|
|
|
.expect('Location', '/private/?r=%2Fhack%2Frss%2F')
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(302);
|
|
|
|
|
|
|
|
doEnd(res);
|
2020-06-16 13:42:32 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// NOTE: this test extends the unit test, checking that there is no other robots.txt middleware overriding private blogging
|
2020-11-30 17:25:22 +03:00
|
|
|
it('should serve private robots.txt', async function () {
|
|
|
|
const res = await request.get('/robots.txt')
|
2020-06-16 13:42:32 +03:00
|
|
|
.expect('Cache-Control', 'public, max-age=3600000')
|
2020-11-30 17:25:22 +03:00
|
|
|
.expect(200);
|
|
|
|
|
|
|
|
res.text.should.match('User-agent: *\nDisallow: /');
|
|
|
|
doEnd(res);
|
2020-06-16 13:42:32 +03:00
|
|
|
});
|
2020-03-20 14:16:59 +03:00
|
|
|
});
|
2020-03-20 13:23:56 +03:00
|
|
|
});
|