🔥 Removed support for http/https mixed mode (#14783)

closes: https://github.com/TryGhost/Toolbox/issues/324
refs: https://github.com/TryGhost/Ghost/issues/14446

- Currently, if url is configured to http but a request is marked secure, Ghost will handle upgrading all internal URLs to https so that there are no mixed content warnings
- From 5.0 that feature is going away, in favour of strictly honouring the configured URL
- Ghost will serve URLs exactly as configured and won't upgrade http to https anymore
- This use case was common when Ghost was first built, but in 2022 the web is mostly https.
- The code needed to support the feature creates a lot of additional complexity & maintenance overhead, so removing this gives us space to do more cool and useful stuff in 2022
This commit is contained in:
Hannah Wolfe 2022-05-11 14:53:23 +01:00 committed by GitHub
parent 84a10daebf
commit b29852b012
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 78 additions and 456 deletions

View File

@ -29,7 +29,6 @@ module.exports = function navigation(options) {
const navigationData = options.data.site[key];
const currentUrl = options.data.root.relativeUrl;
const self = this;
let output;
if (!_.isObject(navigationData) || _.isFunction(navigationData)) {
@ -78,7 +77,6 @@ module.exports = function navigation(options) {
out.label = e.label;
out.slug = slugify(e.label);
out.url = e.url;
out.secure = self.secure;
return out;
});

View File

@ -7,11 +7,11 @@ function getAuthorUrl(data, absolute) {
const contextObject = getContextObject(data, context);
if (data.author) {
return urlService.getUrlByResourceId(data.author.id, {absolute: absolute, secure: data.author.secure, withSubdirectory: true});
return urlService.getUrlByResourceId(data.author.id, {absolute: absolute, withSubdirectory: true});
}
if (contextObject && contextObject.primary_author) {
return urlService.getUrlByResourceId(contextObject.primary_author.id, {absolute: absolute, secure: contextObject.secure, withSubdirectory: true});
return urlService.getUrlByResourceId(contextObject.primary_author.id, {absolute: absolute, withSubdirectory: true});
}
return null;

View File

@ -35,7 +35,7 @@ function getPaginatedUrl(page, data, absolute) {
// baseUrl can be undefined, if there was nothing preceding the pagePath (e.g. first page of the index channel)
newRelativeUrl = baseUrl ? urlUtils.urlJoin(baseUrl, newRelativeUrl) : newRelativeUrl;
return urlUtils.urlFor({relativeUrl: newRelativeUrl, secure: data.secure}, absolute);
return urlUtils.urlFor({relativeUrl: newRelativeUrl}, absolute);
}
module.exports = getPaginatedUrl;

View File

@ -2,7 +2,6 @@ const routingService = require('../services/routing');
function getRssUrl(data, absolute) {
return routingService.registry.getRssUrl({
secure: data.secure,
absolute: absolute
});
}

View File

@ -27,18 +27,18 @@ function getUrl(data, absolute) {
* A long term solution should be part of the final version of Dynamic Routing.
*/
if (data.status !== 'published' && urlService.getUrlByResourceId(data.id) === '/404/') {
return urlUtils.urlFor({relativeUrl: urlUtils.urlJoin('/p', data.uuid, '/'), secure: data.secure}, null, absolute);
return urlUtils.urlFor({relativeUrl: urlUtils.urlJoin('/p', data.uuid, '/')}, null, absolute);
}
return urlService.getUrlByResourceId(data.id, {secure: data.secure, absolute: absolute, withSubdirectory: true});
return urlService.getUrlByResourceId(data.id, {absolute: absolute, withSubdirectory: true});
}
if (checks.isTag(data) || checks.isUser(data)) {
return urlService.getUrlByResourceId(data.id, {secure: data.secure, absolute: absolute, withSubdirectory: true});
return urlService.getUrlByResourceId(data.id, {absolute: absolute, withSubdirectory: true});
}
if (checks.isNav(data)) {
return urlUtils.urlFor('nav', {nav: data, secure: data.secure}, absolute);
return urlUtils.urlFor('nav', {nav: data}, absolute);
}
// sanitize any trailing `/amp` in the url

View File

@ -19,10 +19,6 @@ module.exports = {
return require('./templates');
},
get secure() {
return require('./secure');
},
get handleError() {
return require('./error');
},

View File

@ -1,19 +0,0 @@
/**
* @description Tiny/Weird helper to attach the information if the request is HTTPS or HTTP.
*
* It's used in services/url/utils (search for ".secure").
*
* We forward the resource into handlebars and if you use the URL helper, we want to know if the original request
* was https or not to generate the correct URL...but that is only true, if your blog url is set to HTTP, but NGINX supports HTTPS.
*
* @TODO: Drop in Ghost 3.0, because we will only support https.
* @param {Object} req
* @param {Object} data
*/
function setRequestIsSecure(req, data) {
(Array.isArray(data) ? data : [data]).forEach(function forEach(d) {
d.secure = req.secure;
});
}
module.exports = setRequestIsSecure;

View File

@ -140,7 +140,7 @@ class CollectionRouter extends ParentRouter {
getRoute(options) {
options = options || {};
return urlUtils.createUrl(this.route.value, options.absolute, options.secure);
return urlUtils.createUrl(this.route.value, options.absolute);
}
/**
@ -153,7 +153,7 @@ class CollectionRouter extends ParentRouter {
return null;
}
return urlUtils.createUrl(urlUtils.urlJoin(this.route.value, this.rssRouter.route.value), options.absolute, options.secure);
return urlUtils.createUrl(urlUtils.urlJoin(this.route.value, this.rssRouter.route.value), options.absolute);
}
}

View File

@ -192,7 +192,7 @@ class ParentRouter {
getRoute(options) {
options = options || {};
return urlUtils.createUrl(this.route.value, options.absolute, options.secure);
return urlUtils.createUrl(this.route.value, options.absolute);
}
/**

View File

@ -1,4 +1,3 @@
const _ = require('lodash');
const debug = require('@tryghost/debug')('services:routing:controllers:channel');
const tpl = require('@tryghost/tpl');
const errors = require('@tryghost/errors');
@ -60,15 +59,6 @@ module.exports = function channelController(req, res, next) {
}));
}
// Format data 1
// @TODO: See renderer/secure for explanation.
renderer.secure(req, result.posts);
// @TODO: See renderer/secure for explanation.
_.each(result.data, function (data) {
renderer.secure(req, data);
});
return renderer.renderEntries(req, res)(result);
})
.catch(renderer.handleError(next));

View File

@ -80,15 +80,6 @@ module.exports = function collectionController(req, res, next) {
debug(`'${post.slug}' is not owned by this collection`);
});
// Format data 1
// @TODO: See renderer/secure for explanation.
renderer.secure(req, result.posts);
// @TODO: See renderer/secure for explanation.
_.each(result.data, function (data) {
renderer.secure(req, data);
});
return renderer.renderEntries(req, res)(result);
})
.catch(renderer.handleError(next));

View File

@ -53,9 +53,6 @@ module.exports = function emailPostController(req, res, next) {
post.access = !!post.html;
// @TODO: See renderer/secure
renderer.secure(req, post);
return renderer.renderEntry(req, res)(post);
})
.catch(renderer.handleError(next));

View File

@ -84,8 +84,6 @@ module.exports = function entryController(req, res, next) {
}));
}
renderer.secure(req, entry);
return renderer.renderEntry(req, res)(entry);
})
.catch(renderer.handleError(next));

View File

@ -55,9 +55,6 @@ module.exports = function previewController(req, res, next) {
post.access = !!post.html;
// @TODO: See renderer/secure
renderer.secure(req, post);
return renderer.renderEntry(req, res)(post);
})
.catch(renderer.handleError(next));

View File

@ -60,11 +60,6 @@ module.exports = function staticController(req, res, next) {
});
}
// @TODO: See renderer/secure for more context.
_.each(response.data, function (data) {
renderer.secure(req, data);
});
renderer.renderer(req, res, renderer.formatResponse.entries(response));
})
.catch(renderer.handleError(next));

View File

@ -17,10 +17,10 @@ const generateTags = function generateTags(data) {
return [];
};
const generateItem = function generateItem(post, secure) {
const generateItem = function generateItem(post) {
const cheerio = require('cheerio');
const itemUrl = routerManager.getUrlByResourceId(post.id, {secure, absolute: true});
const itemUrl = routerManager.getUrlByResourceId(post.id, {absolute: true});
const htmlContent = cheerio.load(post.html || '');
const item = {
title: post.title,
@ -35,7 +35,7 @@ const generateItem = function generateItem(post, secure) {
};
if (post.feature_image) {
const imageUrl = urlUtils.urlFor('image', {image: post.feature_image, secure}, true);
const imageUrl = urlUtils.urlFor('image', {image: post.feature_image}, true);
// Add a media content tag
item.custom_elements.push({
@ -67,17 +67,15 @@ const generateItem = function generateItem(post, secure) {
* Data is an object which contains the res.locals + results from fetching a collection, but without related data.
*
* @param {string} baseUrl
* @param {{title, description, safeVersion, secure, posts}} data
* @param {{title, description, safeVersion, posts}} data
*/
const generateFeed = function generateFeed(baseUrl, data) {
const {secure} = data;
const feed = new RSS({
title: data.title,
description: data.description,
generator: 'Ghost ' + data.safeVersion,
feed_url: urlUtils.urlFor({relativeUrl: baseUrl, secure}, true),
site_url: urlUtils.urlFor('home', {secure}, true),
feed_url: urlUtils.urlFor({relativeUrl: baseUrl}, true),
site_url: urlUtils.urlFor('home', true),
image_url: urlUtils.urlFor({relativeUrl: 'favicon.png'}, true),
ttl: '60',
custom_namespaces: {
@ -88,7 +86,7 @@ const generateFeed = function generateFeed(baseUrl, data) {
return data.posts.reduce((feedPromise, post) => {
return feedPromise.then(() => {
const item = generateItem(post, secure);
const item = generateItem(post);
return feed.item(item);
});
}, Promise.resolve()).then(() => {

View File

@ -1,6 +1,5 @@
module.exports = [
require('./ensure-active-theme'),
require('./update-global-template-options'),
require('./update-local-template-data'),
require('./update-local-template-options')
];

View File

@ -1,9 +0,0 @@
function updateLocalTemplateData(req, res, next) {
// Pass 'secure' flag to the view engine
// so that templates can choose to render https or http 'url', see url utility
res.locals.secure = req.secure;
next();
}
module.exports = updateLocalTemplateData;

View File

@ -9,7 +9,7 @@ function updateLocalTemplateOptions(req, res, next) {
// adjust @site.url for http/https based on the incoming request
const siteData = {
url: urlUtils.urlFor('home', {secure: req.secure, trailingSlash: false}, true)
url: urlUtils.urlFor('home', {trailingSlash: false}, true)
};
// @TODO: it would be nicer if this was proper middleware somehow...

View File

@ -218,6 +218,8 @@ class UrlService {
*
* @param {String} id
* @param {Object} options
* @param {Object} [options.absolute]
* @param {Object} [options.withSubdirectory]
* @returns {String}
*/
getUrlByResourceId(id, options) {
@ -227,22 +229,22 @@ class UrlService {
if (obj) {
if (options.absolute) {
return this.utils.createUrl(obj.url, options.absolute, options.secure);
return this.utils.createUrl(obj.url, options.absolute);
}
if (options.withSubdirectory) {
return this.utils.createUrl(obj.url, false, options.secure, true);
return this.utils.createUrl(obj.url, false, true);
}
return obj.url;
}
if (options.absolute) {
return this.utils.createUrl('/404/', options.absolute, options.secure);
return this.utils.createUrl('/404/', options.absolute);
}
if (options.withSubdirectory) {
return this.utils.createUrl('/404/', false, options.secure);
return this.utils.createUrl('/404/', false);
}
return '/404/';

View File

@ -62,7 +62,7 @@
"@tryghost/bookshelf-plugins": "0.4.1",
"@tryghost/bootstrap-socket": "0.2.19",
"@tryghost/color-utils": "0.1.16",
"@tryghost/config-url-helpers": "0.1.7",
"@tryghost/config-url-helpers": "1.0.0",
"@tryghost/constants": "1.0.4",
"@tryghost/custom-theme-settings-service": "0.3.2",
"@tryghost/database-info": "0.3.4",
@ -110,7 +110,7 @@
"@tryghost/string": "0.1.25",
"@tryghost/tpl": "0.1.16",
"@tryghost/update-check-service": "0.3.3",
"@tryghost/url-utils": "3.0.1",
"@tryghost/url-utils": "4.0.0",
"@tryghost/validator": "0.1.24",
"@tryghost/verification-trigger": "0.2.3",
"@tryghost/version": "0.1.14",

View File

@ -94,36 +94,4 @@ describe('Advanced URL Configurations', function () {
.expect(404);
});
});
// we'll use X-Forwarded-Proto: https to simulate an 'https://' request behind a proxy
describe('HTTPS', function () {
before(async function () {
configUtils.set('url', 'http://localhost:2370/');
urlUtils.stubUrlUtilsFromConfig();
await testUtils.startGhost({forceStart: true});
request = supertest.agent(configUtils.config.get('server:host') + ':' + configUtils.config.get('server:port'));
});
after(function () {
configUtils.restore();
urlUtils.restore();
});
it('should set links to url over non-HTTPS', async function () {
await request.get('/')
.expect(200)
.expect(/<link rel="canonical" href="http:\/\/localhost:2370\/" \/\>/)
.expect(/<a href="http:\/\/localhost:2370">Ghost<\/a\>/);
});
it('should set links over HTTPS besides canonical', async function () {
await 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\>/);
});
});
});

View File

@ -10,7 +10,7 @@ const urlUtils = require('../../utils/urlUtils');
const routeSettingsService = require('../../../core/server/services/route-settings');
const themeEngine = require('../../../core/frontend/services/theme-engine');
describe('Integration - Web - Site canary', function () {
describe('Frontend behaviour tests', function () {
let app;
before(localUtils.urlService.resetGenerators);
@ -52,7 +52,6 @@ describe('Integration - Web - Site canary', function () {
describe('behaviour: default cases', function () {
it('serve post', function () {
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/',
host: 'example.com'
@ -69,7 +68,6 @@ describe('Integration - Web - Site canary', function () {
it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: true});
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/amp/',
host: 'example.com'
@ -88,7 +86,6 @@ describe('Integration - Web - Site canary', function () {
it('serve amp', function () {
localUtils.defaultMocks(sinon, {amp: false});
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/amp/',
host: 'example.com'
@ -103,7 +100,6 @@ describe('Integration - Web - Site canary', function () {
it('post not found', function () {
const req = {
secure: true,
method: 'GET',
url: '/not-found/',
host: 'example.com'
@ -118,7 +114,6 @@ describe('Integration - Web - Site canary', function () {
it('serve static page', function () {
const req = {
secure: true,
method: 'GET',
url: '/static-page-test/',
host: 'example.com'
@ -133,7 +128,6 @@ describe('Integration - Web - Site canary', function () {
it('serve author', function () {
const req = {
secure: true,
method: 'GET',
url: '/author/joe-bloggs/',
host: 'example.com'
@ -152,7 +146,6 @@ describe('Integration - Web - Site canary', function () {
it('serve tag', function () {
const req = {
secure: true,
method: 'GET',
url: '/tag/bacon/',
host: 'example.com'
@ -171,7 +164,6 @@ describe('Integration - Web - Site canary', function () {
it('serve tag rss', function () {
const req = {
secure: true,
method: 'GET',
url: '/tag/bacon/rss/',
host: 'example.com'
@ -185,7 +177,6 @@ describe('Integration - Web - Site canary', function () {
it('serve collection', function () {
const req = {
secure: true,
method: 'GET',
url: '/',
host: 'example.com'
@ -205,14 +196,12 @@ describe('Integration - Web - Site canary', function () {
should.exist(response.res.locals.safeVersion);
should.exist(response.res.locals.safeVersion);
should.exist(response.res.locals.relativeUrl);
should.exist(response.res.locals.secure);
should.exist(response.res.routerOptions);
});
});
it('serve collection: page 2', function () {
const req = {
secure: true,
method: 'GET',
url: '/page/2/',
host: 'example.com'
@ -230,10 +219,7 @@ describe('Integration - Web - Site canary', function () {
});
it('serve theme asset', function () {
//configUtils.set('url', 'https://example.com');
const req = {
secure: true,
method: 'GET',
url: '/assets/built/screen.css',
host: 'example.com'
@ -300,7 +286,7 @@ describe('Integration - Web - Site canary', function () {
});
});
describe('https', function () {
describe('https site: http requests redirect to https', function () {
before(function () {
configUtils.set('url', 'https://example.com');
urlUtils.stubUrlUtilsFromConfig();
@ -423,7 +409,6 @@ describe('Integration - Web - Site canary', function () {
it('serve static route', function () {
const req = {
secure: true,
method: 'GET',
url: '/',
host: 'example.com'
@ -438,7 +423,6 @@ describe('Integration - Web - Site canary', function () {
it('serve rss', function () {
const req = {
secure: true,
method: 'GET',
url: '/podcast/rss/',
host: 'example.com'
@ -452,7 +436,6 @@ describe('Integration - Web - Site canary', function () {
it('serve post', function () {
const req = {
secure: true,
method: 'GET',
url: '/something/html-ipsum/',
host: 'example.com'
@ -467,7 +450,6 @@ describe('Integration - Web - Site canary', function () {
it('serve collection: podcast with default template', function () {
const req = {
secure: true,
method: 'GET',
url: '/podcast/',
host: 'example.com'
@ -486,7 +468,6 @@ describe('Integration - Web - Site canary', function () {
it('serve collection: something with custom template', function () {
const req = {
secure: true,
method: 'GET',
url: '/something/',
host: 'example.com'
@ -535,7 +516,6 @@ describe('Integration - Web - Site canary', function () {
it('serve route', function () {
const req = {
secure: true,
method: 'GET',
url: '/something/',
host: 'example.com'
@ -589,7 +569,7 @@ describe('Integration - Web - Site canary', function () {
it('serve post', function () {
const req = {
secure: true,
method: 'GET',
url: '/featured/',
host: 'example.com'
@ -605,7 +585,6 @@ describe('Integration - Web - Site canary', function () {
it('serve post', function () {
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/',
host: 'example.com'
@ -620,7 +599,6 @@ describe('Integration - Web - Site canary', function () {
it('serve author', function () {
const req = {
secure: true,
method: 'GET',
url: '/author/joe-bloggs/',
host: 'example.com'
@ -635,7 +613,6 @@ describe('Integration - Web - Site canary', function () {
it('serve tag', function () {
const req = {
secure: true,
method: 'GET',
url: '/tag/bacon/',
host: 'example.com'
@ -684,7 +661,6 @@ describe('Integration - Web - Site canary', function () {
it('serve post', function () {
const req = {
secure: true,
method: 'GET',
url: '/joe-bloggs/html-ipsum/',
host: 'example.com'
@ -699,7 +675,6 @@ describe('Integration - Web - Site canary', function () {
it('post without author', function () {
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/',
host: 'example.com'
@ -714,7 +689,6 @@ describe('Integration - Web - Site canary', function () {
it('page', function () {
const req = {
secure: true,
method: 'GET',
url: '/static-page-test/',
host: 'example.com'
@ -763,7 +737,6 @@ describe('Integration - Web - Site canary', function () {
it('serve post', function () {
const req = {
secure: true,
method: 'GET',
url: '/something/kitchen-sink/html-ipsum/',
host: 'example.com'
@ -778,7 +751,6 @@ describe('Integration - Web - Site canary', function () {
it('post without tag', function () {
const req = {
secure: true,
method: 'GET',
url: '/something/html-ipsum/',
host: 'example.com'
@ -793,7 +765,6 @@ describe('Integration - Web - Site canary', function () {
it('post without tag', function () {
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/',
host: 'example.com'
@ -808,7 +779,6 @@ describe('Integration - Web - Site canary', function () {
it('page', function () {
const req = {
secure: true,
method: 'GET',
url: '/static-page-test/',
host: 'example.com'
@ -914,7 +884,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /food/', function () {
const req = {
secure: true,
method: 'GET',
url: '/food/',
host: 'example.com'
@ -929,7 +898,6 @@ describe('Integration - Web - Site canary', function () {
it('serve bacon tag', function () {
const req = {
secure: true,
method: 'GET',
url: '/categories/bacon/',
host: 'example.com'
@ -943,7 +911,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /sport/', function () {
const req = {
secure: true,
method: 'GET',
url: '/sport/',
host: 'example.com'
@ -958,7 +925,6 @@ describe('Integration - Web - Site canary', function () {
it('serve chorizo tag', function () {
const req = {
secure: true,
method: 'GET',
url: '/categories/chorizo/',
host: 'example.com'
@ -972,7 +938,6 @@ describe('Integration - Web - Site canary', function () {
it('serve my-page', function () {
const req = {
secure: true,
method: 'GET',
url: '/my-page/',
host: 'example.com'
@ -1021,7 +986,6 @@ describe('Integration - Web - Site canary', function () {
it('serve collection', function () {
const req = {
secure: true,
method: 'GET',
url: '/',
host: 'example.com'
@ -1036,7 +1000,6 @@ describe('Integration - Web - Site canary', function () {
it('serve second collectiom', function () {
const req = {
secure: true,
method: 'GET',
url: '/magic/',
host: 'example.com'
@ -1084,7 +1047,6 @@ describe('Integration - Web - Site canary', function () {
it('serve collection', function () {
const req = {
secure: true,
method: 'GET',
url: '/',
host: 'example.com'
@ -1133,7 +1095,6 @@ describe('Integration - Web - Site canary', function () {
it('serve collection', function () {
const req = {
secure: true,
method: 'GET',
url: '/',
host: 'example.com'
@ -1148,7 +1109,6 @@ describe('Integration - Web - Site canary', function () {
it('serve second page collection: should use index.hbs', function () {
const req = {
secure: true,
method: 'GET',
url: '/magic/',
host: 'example.com'
@ -1313,7 +1273,6 @@ describe('Integration - Web - Site canary', function () {
it('serve channel 1', function () {
const req = {
secure: true,
method: 'GET',
url: '/channel1/',
host: 'example.com'
@ -1332,7 +1291,6 @@ describe('Integration - Web - Site canary', function () {
it('serve channel 1: rss', function () {
const req = {
secure: true,
method: 'GET',
url: '/channel1/rss/',
host: 'example.com'
@ -1347,7 +1305,6 @@ describe('Integration - Web - Site canary', function () {
it('serve channel 2', function () {
const req = {
secure: true,
method: 'GET',
url: '/channel2/',
host: 'example.com'
@ -1367,7 +1324,6 @@ describe('Integration - Web - Site canary', function () {
it('serve channel 3', function () {
const req = {
secure: true,
method: 'GET',
url: '/channel3/',
host: 'example.com'
@ -1384,7 +1340,6 @@ describe('Integration - Web - Site canary', function () {
it('serve channel 4', function () {
const req = {
secure: true,
method: 'GET',
url: '/channel4/',
host: 'example.com'
@ -1403,7 +1358,6 @@ describe('Integration - Web - Site canary', function () {
it('serve channel 5', function () {
const req = {
secure: true,
method: 'GET',
url: '/channel5/',
host: 'example.com'
@ -1422,7 +1376,6 @@ describe('Integration - Web - Site canary', function () {
it('serve channel 6', function () {
const req = {
secure: true,
method: 'GET',
url: '/channel6/',
host: 'example.com'
@ -1441,7 +1394,6 @@ describe('Integration - Web - Site canary', function () {
it('serve kitching-sink: redirect', function () {
const req = {
secure: true,
method: 'GET',
url: '/tag/kitchen-sink/',
host: 'example.com'
@ -1456,7 +1408,6 @@ describe('Integration - Web - Site canary', function () {
it('serve html-ipsum: redirect', function () {
const req = {
secure: true,
method: 'GET',
url: '/html-ipsum/',
host: 'example.com'
@ -1471,7 +1422,6 @@ describe('Integration - Web - Site canary', function () {
it('serve chorizo: no redirect', function () {
const req = {
secure: true,
method: 'GET',
url: '/tag/chorizo/',
host: 'example.com'
@ -1485,7 +1435,7 @@ describe('Integration - Web - Site canary', function () {
it('serve joe-bloggs', function () {
const req = {
secure: true,
method: 'GET',
url: '/author/joe-bloggs/',
host: 'example.com'
@ -1556,7 +1506,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /rss/', function () {
const req = {
secure: true,
method: 'GET',
url: '/rss/',
host: 'example.com'
@ -1570,7 +1519,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /music/rss/', function () {
const req = {
secure: true,
method: 'GET',
url: '/music/rss/',
host: 'example.com'
@ -1584,7 +1532,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /cooking/rss/', function () {
const req = {
secure: true,
method: 'GET',
url: '/cooking/rss/',
host: 'example.com'
@ -1598,7 +1545,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /flat/rss/', function () {
const req = {
secure: true,
method: 'GET',
url: '/flat/rss/',
host: 'example.com'
@ -1612,7 +1558,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /podcast/rss/', function () {
const req = {
secure: true,
method: 'GET',
url: '/podcast/rss/',
host: 'example.com'
@ -1629,7 +1574,6 @@ describe('Integration - Web - Site canary', function () {
it('serve /podcast/', function () {
const req = {
secure: true,
method: 'GET',
url: '/podcast/',
host: 'example.com'
@ -1639,7 +1583,7 @@ describe('Integration - Web - Site canary', function () {
.then(function (response) {
const $ = cheerio.load(response.body);
response.statusCode.should.eql(200);
$('head link')[1].attribs.href.should.eql('https://127.0.0.1:2369/rss/');
$('head link')[1].attribs.href.should.eql('http://127.0.0.1:2369/rss/');
});
});
});

View File

@ -45,7 +45,7 @@ describe('{{url}} helper', function () {
url: '/slug/'
});
urlService.getUrlByResourceId.withArgs(post.id, {absolute: undefined, secure: undefined, withSubdirectory: true}).returns('/slug/');
urlService.getUrlByResourceId.withArgs(post.id, {absolute: undefined, withSubdirectory: true}).returns('/slug/');
rendered = url.call(post);
should.exist(rendered);
@ -62,31 +62,13 @@ describe('{{url}} helper', function () {
created_at: new Date(0)
});
urlService.getUrlByResourceId.withArgs(post.id, {absolute: true, secure: undefined, withSubdirectory: true}).returns('http://localhost:65535/slug/');
urlService.getUrlByResourceId.withArgs(post.id, {absolute: true, withSubdirectory: true}).returns('http://localhost:65535/slug/');
rendered = url.call(post, {hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('http://localhost:65535/slug/');
});
it('should output an absolute URL with https if the option is present and secure', function () {
const post = testUtils.DataGenerator.forKnex.createPost({
html: 'content',
mobiledoc: markdownToMobiledoc('ff'),
title: 'title',
slug: 'slug',
url: '/slug/',
created_at: new Date(0),
secure: true
});
urlService.getUrlByResourceId.withArgs(post.id, {absolute: true, secure: true, withSubdirectory: true}).returns('https://localhost:65535/slug/');
rendered = url.call(post, {hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('https://localhost:65535/slug/');
});
it('should return the slug with a prefixed /tag/ if the context is a tag', function () {
const tag = testUtils.DataGenerator.forKnex.createTag({
name: 'the tag',
@ -95,7 +77,7 @@ describe('{{url}} helper', function () {
parent: null
});
urlService.getUrlByResourceId.withArgs(tag.id, {absolute: undefined, secure: undefined, withSubdirectory: true}).returns('/tag/the-tag/');
urlService.getUrlByResourceId.withArgs(tag.id, {absolute: undefined, withSubdirectory: true}).returns('/tag/the-tag/');
rendered = url.call(tag);
should.exist(rendered);
@ -111,7 +93,7 @@ describe('{{url}} helper', function () {
slug: 'some-author'
});
urlService.getUrlByResourceId.withArgs(user.id, {absolute: undefined, secure: undefined, withSubdirectory: true}).returns('/author/some-author/');
urlService.getUrlByResourceId.withArgs(user.id, {absolute: undefined, withSubdirectory: true}).returns('/author/some-author/');
rendered = url.call(user);
should.exist(rendered);
@ -139,14 +121,6 @@ describe('{{url}} helper', function () {
rendered.string.should.equal('http://localhost:65535/bar');
});
it('should return an absolute url with https if context is secure', function () {
rendered = url.call(
{url: '/bar', label: 'Bar', slug: 'bar', current: true, secure: true},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('https://localhost:65535/bar');
});
it('external urls should be retained in a nav context', function () {
rendered = url.call(
{url: 'http://casper.website/baz', label: 'Baz', slug: 'baz', current: true},
@ -163,28 +137,6 @@ describe('{{url}} helper', function () {
rendered.string.should.equal('http://localhost:65535/qux');
});
it('should handle hosted urls in a nav context with secure', function () {
rendered = url.call(
{
url: 'http://localhost:65535/qux', label: 'Qux', slug: 'qux', current: true,
secure: true
},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('https://localhost:65535/qux');
});
it('should handle hosted https urls in a nav context with secure', function () {
rendered = url.call(
{
url: 'https://localhost:65535/qux', label: 'Qux', slug: 'qux', current: true,
secure: true
},
{hash: {absolute: 'true'}});
should.exist(rendered);
rendered.string.should.equal('https://localhost:65535/qux');
});
it('should handle hosted urls with the wrong protocol in a nav context', function () {
rendered = url.call(
{url: 'https://localhost:65535/quux', label: 'Quux', slug: 'quux', current: true},

View File

@ -21,7 +21,7 @@ describe('getAuthorUrl', function () {
}
};
urlService.getUrlByResourceId.withArgs(post.primary_author.id, {absolute: undefined, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(post.primary_author.id, {absolute: undefined, withSubdirectory: true})
.returns('author url');
should.exist(getAuthorUrl({
@ -38,7 +38,7 @@ describe('getAuthorUrl', function () {
}
};
urlService.getUrlByResourceId.withArgs(post.primary_author.id, {absolute: true, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(post.primary_author.id, {absolute: true, withSubdirectory: true})
.returns('absolute author url');
should.exist(getAuthorUrl({
@ -55,7 +55,7 @@ describe('getAuthorUrl', function () {
}
};
urlService.getUrlByResourceId.withArgs(post.primary_author.id, {absolute: undefined, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(post.primary_author.id, {absolute: undefined, withSubdirectory: true})
.returns('author url');
should.exist(getAuthorUrl({
@ -70,7 +70,7 @@ describe('getAuthorUrl', function () {
slug: 'test-author'
};
urlService.getUrlByResourceId.withArgs(author.id, {absolute: undefined, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(author.id, {absolute: undefined, withSubdirectory: true})
.returns('author url');
should.exist(getAuthorUrl({

View File

@ -20,11 +20,9 @@ describe('getRssUrl', function () {
should.equal(rssUrl, '/rss/');
});
it('forwards absolute/secure flags', function () {
const rssUrl = getRssUrl({
secure: false
}, true);
it('forwards absolute flags', function () {
const rssUrl = getRssUrl({}, true);
routing.registry.getRssUrl.calledWith({secure: false, absolute: true}).should.be.true();
routing.registry.getRssUrl.calledWith({absolute: true}).should.be.true();
});
});

View File

@ -18,58 +18,44 @@ describe('getUrl', function () {
it('should return url for a post', function () {
const post = testUtils.DataGenerator.forKnex.createPost();
urlService.getUrlByResourceId.withArgs(post.id, {absolute: undefined, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(post.id, {absolute: undefined, withSubdirectory: true})
.returns('post url');
getUrl(post).should.eql('post url');
});
describe('preview url: drafts/scheduled posts', function () {
it('not absolute, not secure', function () {
it('relative', function () {
const post = testUtils.DataGenerator.forKnex.createPost({status: 'draft'});
urlService.getUrlByResourceId.withArgs(post.id).returns('/404/');
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/', secure: undefined}, null, undefined).returns('relative');
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/'}, null, undefined).returns('relative');
let url = getUrl(post);
urlService.getUrlByResourceId.calledOnce.should.be.true();
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/', secure: undefined}, null, undefined)
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/'}, null, undefined)
.calledOnce.should.be.true();
url.should.eql('relative');
});
it('absolute, not secure', function () {
it('absolute', function () {
const post = testUtils.DataGenerator.forKnex.createPost({status: 'draft'});
urlService.getUrlByResourceId.withArgs(post.id).returns('/404/');
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/', secure: undefined}, null, true).returns('absolute');
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/'}, null, true).returns('absolute');
let url = getUrl(post, true);
urlService.getUrlByResourceId.calledOnce.should.be.true();
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/', secure: undefined}, null, true)
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/'}, null, true)
.calledOnce.should.be.true();
url.should.eql('absolute');
});
it('absolute, secure', function () {
const post = testUtils.DataGenerator.forKnex.createPost({status: 'draft'});
post.secure = true;
urlService.getUrlByResourceId.withArgs(post.id).returns('/404/');
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/', secure: true}, null, true).returns('absolute secure');
let url = getUrl(post, true);
urlService.getUrlByResourceId.calledOnce.should.be.true();
urlUtils.urlFor.withArgs({relativeUrl: '/p/' + post.uuid + '/', secure: true}, null, true)
.calledOnce.should.be.true();
url.should.eql('absolute secure');
});
});
it('should return absolute url for a post', function () {
const post = testUtils.DataGenerator.forKnex.createPost();
urlService.getUrlByResourceId.withArgs(post.id, {absolute: true, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(post.id, {absolute: true, withSubdirectory: true})
.returns('absolute post url');
getUrl(post, true).should.eql('absolute post url');
@ -91,48 +77,28 @@ describe('getUrl', function () {
// the tag object contains a `parent` attribute. the tag model contains a `parent_id` attr.
tag.parent = null;
urlService.getUrlByResourceId.withArgs(tag.id, {absolute: undefined, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(tag.id, {absolute: undefined, withSubdirectory: true})
.returns('tag url');
getUrl(tag).should.eql('tag url');
});
it('should return secure url for a tag', function () {
const tag = testUtils.DataGenerator.forKnex.createTag();
// @NOTE: we currently have no way to generate a test model which is correctly jsonified
// e.g. testUtils.DataGenerator.forModel.createTag().toJSON()
// the tag object contains a `parent` attribute. the tag model contains a `parent_id` attr.
tag.parent = null;
// @TODO: WTF O_O
tag.secure = true;
urlService.getUrlByResourceId.withArgs(tag.id, {absolute: undefined, secure: true, withSubdirectory: true})
.returns('secure tag url');
getUrl(tag).should.eql('secure tag url');
});
it('should return url for a author', function () {
const author = testUtils.DataGenerator.forKnex.createUser();
urlService.getUrlByResourceId.withArgs(author.id, {absolute: undefined, secure: undefined, withSubdirectory: true})
urlService.getUrlByResourceId.withArgs(author.id, {absolute: undefined, withSubdirectory: true})
.returns('author url');
getUrl(author).should.eql('author url');
});
it('should return secure absolute url for a author', function () {
it('should return absolute url for a author', function () {
const author = testUtils.DataGenerator.forKnex.createUser();
// @TODO: WTF
author.secure = true;
urlService.getUrlByResourceId.withArgs(author.id, {absolute: true, withSubdirectory: true})
.returns('absolute author url');
urlService.getUrlByResourceId.withArgs(author.id, {absolute: true, secure: true, withSubdirectory: true})
.returns('absolute secure author url');
getUrl(author, true).should.eql('absolute secure author url');
getUrl(author, true).should.eql('absolute author url');
});
it('should return url for a nav', function () {
@ -143,7 +109,7 @@ describe('getUrl', function () {
current: true
};
urlUtils.urlFor.withArgs('nav', {nav: data, secure: data.secure}, undefined)
urlUtils.urlFor.withArgs('nav', {nav: data}, undefined)
.returns('nav url');
getUrl(data).should.equal('nav url');
@ -157,7 +123,7 @@ describe('getUrl', function () {
current: true
};
urlUtils.urlFor.withArgs('nav', {nav: data, secure: data.secure}, true)
urlUtils.urlFor.withArgs('nav', {nav: data}, true)
.returns('absolute nav url');
getUrl(data, true).should.equal('absolute nav url');

View File

@ -19,7 +19,6 @@ describe('Unit - services/routing/controllers/channel', function () {
let req;
let res;
let fetchDataStub;
let secureStub;
let renderStub;
let posts;
let postsPerPage;
@ -31,7 +30,6 @@ describe('Unit - services/routing/controllers/channel', function () {
testUtils.DataGenerator.forKnex.createPost()
];
secureStub = sinon.stub();
fetchDataStub = sinon.stub();
renderStub = sinon.stub();
@ -41,10 +39,6 @@ describe('Unit - services/routing/controllers/channel', function () {
sinon.stub(security.string, 'safe').returns('safe');
sinon.stub(renderer, 'secure').get(function () {
return secureStub;
});
sinon.stub(themeEngine, 'getActive').returns({
updateTemplateOptions: sinon.stub(),
config: function (key) {
@ -87,7 +81,6 @@ describe('Unit - services/routing/controllers/channel', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
done();
}).catch(done);
});
@ -109,7 +102,6 @@ describe('Unit - services/routing/controllers/channel', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
done();
}).catch(done);
});
@ -133,7 +125,6 @@ describe('Unit - services/routing/controllers/channel', function () {
themeEngine.getActive().updateTemplateOptions.withArgs({data: {config: {posts_per_page: 3}}}).calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
done();
}).catch(done);
});
@ -158,7 +149,6 @@ describe('Unit - services/routing/controllers/channel', function () {
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
renderStub.calledOnce.should.be.false();
secureStub.calledOnce.should.be.false();
done();
});
});
@ -180,7 +170,6 @@ describe('Unit - services/routing/controllers/channel', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.true();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
done();
}).catch(done);
});
@ -202,30 +191,6 @@ describe('Unit - services/routing/controllers/channel', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
done();
}).catch(done);
});
it('ensure secure helper get\'s called for data object', function (done) {
fetchDataStub.withArgs({page: 1, slug: undefined, limit: postsPerPage}, res.routerOptions)
.resolves({
posts: posts,
data: {
tag: [testUtils.DataGenerator.forKnex.createTag()]
},
meta: {
pagination: {
pages: 5
}
}
});
controllers.channel(req, res, failTest(done)).then(function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledTwice.should.be.true();
done();
}).catch(done);
});

View File

@ -20,7 +20,6 @@ describe('Unit - services/routing/controllers/collection', function () {
let req;
let res;
let fetchDataStub;
let secureStub;
let renderStub;
let posts;
let postsPerPage;
@ -33,7 +32,6 @@ describe('Unit - services/routing/controllers/collection', function () {
testUtils.DataGenerator.forKnex.createPost()
];
secureStub = sinon.stub();
fetchDataStub = sinon.stub();
renderStub = sinon.stub();
@ -43,10 +41,6 @@ describe('Unit - services/routing/controllers/collection', function () {
sinon.stub(security.string, 'safe').returns('safe');
sinon.stub(renderer, 'secure').get(function () {
return secureStub;
});
sinon.stub(themeEngine, 'getActive').returns({
updateTemplateOptions: sinon.stub(),
config: function (key) {
@ -94,7 +88,6 @@ describe('Unit - services/routing/controllers/collection', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
ownsStub.calledOnce.should.be.true();
done();
}).catch(done);
@ -117,7 +110,6 @@ describe('Unit - services/routing/controllers/collection', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
ownsStub.calledOnce.should.be.true();
done();
}).catch(done);
@ -142,7 +134,6 @@ describe('Unit - services/routing/controllers/collection', function () {
themeEngine.getActive().updateTemplateOptions.withArgs({data: {config: {posts_per_page: 3}}}).calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
ownsStub.calledOnce.should.be.true();
done();
}).catch(done);
@ -168,7 +159,6 @@ describe('Unit - services/routing/controllers/collection', function () {
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
renderStub.calledOnce.should.be.false();
secureStub.calledOnce.should.be.false();
ownsStub.calledOnce.should.be.false();
done();
});
@ -191,7 +181,6 @@ describe('Unit - services/routing/controllers/collection', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.true();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
ownsStub.calledOnce.should.be.true();
done();
}).catch(done);
@ -214,31 +203,6 @@ describe('Unit - services/routing/controllers/collection', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledOnce.should.be.true();
ownsStub.calledOnce.should.be.true();
done();
}).catch(done);
});
it('ensure secure helper get\'s called for data object', function (done) {
fetchDataStub.withArgs({page: 1, slug: undefined, limit: postsPerPage}, res.routerOptions)
.resolves({
posts: posts,
data: {
tag: [testUtils.DataGenerator.forKnex.createTag()]
},
meta: {
pagination: {
pages: 5
}
}
});
controllers.collection(req, res, failTest(done)).then(function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledTwice.should.be.true();
ownsStub.calledOnce.should.be.true();
done();
}).catch(done);
@ -277,7 +241,6 @@ describe('Unit - services/routing/controllers/collection', function () {
themeEngine.getActive.calledOnce.should.be.true();
security.string.safe.calledOnce.should.be.false();
fetchDataStub.calledOnce.should.be.true();
secureStub.calledTwice.should.be.true();
ownsStub.callCount.should.eql(4);
done();
}).catch(done);

View File

@ -13,7 +13,6 @@ describe('Unit - services/routing/controllers/entry', function () {
let req;
let res;
let entryLookUpStub;
let secureStub;
let renderStub;
let post;
let page;
@ -24,7 +23,6 @@ describe('Unit - services/routing/controllers/entry', function () {
page = testUtils.DataGenerator.forKnex.createPost({page: 1});
secureStub = sinon.stub();
entryLookUpStub = sinon.stub();
renderStub = sinon.stub();
@ -32,10 +30,6 @@ describe('Unit - services/routing/controllers/entry', function () {
return entryLookUpStub;
});
sinon.stub(renderer, 'secure').get(function () {
return secureStub;
});
sinon.stub(renderer, 'renderEntry').get(function () {
return renderStub;
});
@ -94,7 +88,6 @@ describe('Unit - services/routing/controllers/entry', function () {
});
controllers.entry(req, res, function () {
secureStub.calledOnce.should.be.true();
done();
}).catch(done);
});

View File

@ -10,7 +10,6 @@ const urlService = require('../../../../../../core/server/services/url');
const urlUtils = require('../../../../../../core/shared/url-utils');
describe('Unit - services/routing/controllers/previews', function () {
let secureStub;
let renderStub;
let req;
let res;
@ -56,16 +55,10 @@ describe('Unit - services/routing/controllers/previews', function () {
set: sinon.spy()
};
secureStub = sinon.stub();
sinon.stub(urlUtils, 'redirectToAdmin');
sinon.stub(urlUtils, 'redirect301');
sinon.stub(urlService, 'getUrlByResourceId');
sinon.stub(renderer, 'secure').get(function () {
return secureStub;
});
renderStub = sinon.stub();
sinon.stub(renderer, 'renderEntry').get(function () {
return function () {
@ -90,7 +83,6 @@ describe('Unit - services/routing/controllers/previews', function () {
it('should render post', function (done) {
controllers.previews(req, res, failTest(done)).then(function () {
renderStub.called.should.be.true();
secureStub.called.should.be.true();
done();
}).catch(done);
});

View File

@ -16,7 +16,6 @@ function failTest(done) {
describe('Unit - services/routing/controllers/static', function () {
let req;
let res;
let secureStub;
let renderStub;
let handleErrorStub;
let formatResponseStub;
@ -26,7 +25,6 @@ describe('Unit - services/routing/controllers/static', function () {
beforeEach(function () {
postsPerPage = 5;
secureStub = sinon.stub();
renderStub = sinon.stub();
handleErrorStub = sinon.stub();
formatResponseStub = sinon.stub();
@ -39,10 +37,6 @@ describe('Unit - services/routing/controllers/static', function () {
};
});
sinon.stub(renderer, 'secure').get(function () {
return secureStub;
});
sinon.stub(renderer, 'handleError').get(function () {
return handleErrorStub;
});
@ -85,7 +79,6 @@ describe('Unit - services/routing/controllers/static', function () {
renderer.renderer.callsFake(function () {
renderer.formatResponse.entries.calledOnce.should.be.true();
tagsReadStub.called.should.be.false();
renderer.secure.called.should.be.false();
done();
});
@ -109,7 +102,6 @@ describe('Unit - services/routing/controllers/static', function () {
renderer.renderer.callsFake(function () {
tagsReadStub.called.should.be.true();
renderer.formatResponse.entries.calledOnce.should.be.true();
renderer.secure.calledOnce.should.be.true();
done();
});

View File

@ -92,7 +92,7 @@ describe('RSS: Generate Feed', function () {
data.posts = posts;
_.each(data.posts, function (post) {
routerManager.getUrlByResourceId.withArgs(post.id, {secure: undefined, absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/');
routerManager.getUrlByResourceId.withArgs(post.id, {absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/');
});
generateFeed(baseUrl, data).then(function (xmlData) {
@ -204,7 +204,7 @@ describe('RSS: Generate Feed', function () {
data.posts = [posts[0]];
_.each(data.posts, function (post) {
routerManager.getUrlByResourceId.withArgs(post.id, {secure: undefined, absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/');
routerManager.getUrlByResourceId.withArgs(post.id, {absolute: true}).returns('http://my-ghost-blog.com/' + post.slug + '/');
});
generateFeed(baseUrl, data).then(function (xmlData) {

View File

@ -135,22 +135,6 @@ describe('Themes middleware', function () {
});
});
it('Sets res.locals.secure to the value of req.secure', function (done) {
req.secure = Math.random() < 0.5;
executeMiddleware(middleware, req, res, function next(err) {
try {
should.not.exist(err);
should.equal(res.locals.secure, req.secure);
done();
} catch (error) {
done(error);
}
});
});
describe('updateTemplateOptions', function () {
it('is called with correct data', function (done) {
const themeDataExpectedProps = ['posts_per_page', 'image_sizes'];

View File

@ -200,7 +200,7 @@ describe('Unit: services/url/UrlService', function () {
urlService.urls.getByResourceId.withArgs(1).returns(null);
urlService.getUrlByResourceId(1, {absolute: true});
urlService.utils.createUrl.calledWith('/404/', true, undefined).should.be.true();
urlService.utils.createUrl.calledWith('/404/', true).should.be.true();
});
it('found', function () {
@ -214,16 +214,7 @@ describe('Unit: services/url/UrlService', function () {
urlService.urls.getByResourceId.withArgs(1).returns({url: '/post/'});
urlService.getUrlByResourceId(1, {absolute: true});
urlService.utils.createUrl.calledWith('/post/', true, undefined).should.be.true();
});
it('found: absolute + secure', function () {
urlService.utils = sinon.stub();
urlService.utils.createUrl = sinon.stub();
urlService.urls.getByResourceId.withArgs(1).returns({url: '/post/'});
urlService.getUrlByResourceId(1, {absolute: true, secure: true});
urlService.utils.createUrl.calledWith('/post/', true, true).should.be.true();
urlService.utils.createUrl.calledWith('/post/', true).should.be.true();
});
it('not found: withSubdirectory', function () {
@ -232,25 +223,16 @@ describe('Unit: services/url/UrlService', function () {
urlService.urls.getByResourceId.withArgs(1).returns(null);
urlService.getUrlByResourceId(1, {withSubdirectory: true});
urlService.utils.createUrl.calledWith('/404/', false, undefined).should.be.true();
urlService.utils.createUrl.calledWith('/404/', false).should.be.true();
});
it('not found: withSubdirectory + secure', function () {
it('not found: withSubdirectory + absolute', function () {
urlService.utils = sinon.stub();
urlService.utils.createUrl = sinon.stub();
urlService.urls.getByResourceId.withArgs(1).returns(null);
urlService.getUrlByResourceId(1, {withSubdirectory: true, secure: true});
urlService.utils.createUrl.calledWith('/404/', false, true).should.be.true();
});
it('not found: withSubdirectory + secure + absolute', function () {
urlService.utils = sinon.stub();
urlService.utils.createUrl = sinon.stub();
urlService.urls.getByResourceId.withArgs(1).returns(null);
urlService.getUrlByResourceId(1, {withSubdirectory: true, secure: true, absolute: true});
urlService.utils.createUrl.calledWith('/404/', true, true).should.be.true();
urlService.getUrlByResourceId(1, {withSubdirectory: true, absolute: true});
urlService.utils.createUrl.calledWith('/404/', true).should.be.true();
});
it('found: withSubdirectory', function () {
@ -259,25 +241,16 @@ describe('Unit: services/url/UrlService', function () {
urlService.urls.getByResourceId.withArgs(1).returns({url: '/post/'});
urlService.getUrlByResourceId(1, {withSubdirectory: true});
urlService.utils.createUrl.calledWith('/post/', false, undefined).should.be.true();
urlService.utils.createUrl.calledWith('/post/', false).should.be.true();
});
it('found: withSubdirectory + secure', function () {
it('found: withSubdirectory + absolute', function () {
urlService.utils = sinon.stub();
urlService.utils.createUrl = sinon.stub();
urlService.urls.getByResourceId.withArgs(1).returns({url: '/post/'});
urlService.getUrlByResourceId(1, {withSubdirectory: true, secure: true});
urlService.utils.createUrl.calledWith('/post/', false, true).should.be.true();
});
it('found: withSubdirectory + secure + absolute', function () {
urlService.utils = sinon.stub();
urlService.utils.createUrl = sinon.stub();
urlService.urls.getByResourceId.withArgs(1).returns({url: '/post/'});
urlService.getUrlByResourceId(1, {withSubdirectory: true, secure: true, absolute: true});
urlService.utils.createUrl.calledWith('/post/', true, true).should.be.true();
urlService.getUrlByResourceId(1, {withSubdirectory: true, absolute: true});
urlService.utils.createUrl.calledWith('/post/', true).should.be.true();
});
});
});

View File

@ -1846,10 +1846,10 @@
dependencies:
color "^3.2.1"
"@tryghost/config-url-helpers@0.1.7":
version "0.1.7"
resolved "https://registry.yarnpkg.com/@tryghost/config-url-helpers/-/config-url-helpers-0.1.7.tgz#197c9c5d25e201cdede4e5f5c2bb84a4e773c33e"
integrity sha512-cKYbXDk/6efbK+maMy3bBigs1ERWZKcpzy8tYXDhoKyJ0xfnjeX51T0PVaWgP70TWZWz46iAs3jbqVJG8pR+2A==
"@tryghost/config-url-helpers@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@tryghost/config-url-helpers/-/config-url-helpers-1.0.0.tgz#29482570d5d89061f2b0e31774bb749b13e8d393"
integrity sha512-zObMS4LkPz8nZweOK6j1lKMPMzNpkqncPTA+e0UusSd8hjfgVgPFPT3qTmD7r/8o9moA+tw+F/guAO2nL/OYYA==
"@tryghost/config@0.2.2":
version "0.2.2"
@ -2498,10 +2498,10 @@
lodash "^4.17.21"
moment "^2.24.0"
"@tryghost/url-utils@3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@tryghost/url-utils/-/url-utils-3.0.1.tgz#3a8fa7c03f69acec23d8322767cfed912e0cd123"
integrity sha512-/ELG4/rfTXV3cstLhihxVTmb30OIkmFVN9nDOs1cl0x+vF5QxdQqxgIFqNUQWI5Ha7XH7wVa8UGhmXUAAKxGig==
"@tryghost/url-utils@4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@tryghost/url-utils/-/url-utils-4.0.0.tgz#5b68409e8edaa687235f1e9d11ea28292b8e6505"
integrity sha512-ASaQQTDPmFFWS4Futfum6ZxMrcqkLoxYe0uERGROOElTwFie3q6M2jdcnJdWTnU3Kpy5yOPRmZcP/rNnejs9Yw==
dependencies:
cheerio "^0.22.0"
moment "^2.27.0"