mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Private blogging misc cleanup
This is a bunch of small changes, that simplifies working with the private blogging module: - remove reference to really old paginated RSS behaviour - remove handling for /rss and allow our standard redirects to redirect to /rss/ and then execute - readd should to tests so that they can be run standalone - fix eslint warning
This commit is contained in:
parent
e0d1763424
commit
4ae907781a
@ -81,7 +81,7 @@ const privateBlogging = {
|
||||
// NOTE: Redirect to /private if the session does not exist.
|
||||
privateBlogging.authenticatePrivateSession(req, res, function onSessionVerified() {
|
||||
// CASE: RSS is disabled for private blogging e.g. they create overhead
|
||||
if (req.path.match(/\/rss(\/?|\/\d+\/?)$/)) {
|
||||
if (req.path.match(/\/rss\/$/)) {
|
||||
return next(new errors.NotFoundError({
|
||||
message: i18n.t('errors.errors.pageNotFound')
|
||||
}));
|
||||
@ -95,14 +95,13 @@ const privateBlogging = {
|
||||
const hash = req.session.token || '';
|
||||
const salt = req.session.salt || '';
|
||||
const isVerified = verifySessionHash(salt, hash);
|
||||
let url;
|
||||
|
||||
if (isVerified) {
|
||||
return next();
|
||||
} else {
|
||||
url = urlUtils.urlFor({relativeUrl: privateRoute});
|
||||
url += '?r=' + encodeURIComponent(req.url);
|
||||
return res.redirect(url);
|
||||
let redirectUrl = urlUtils.urlFor({relativeUrl: privateRoute});
|
||||
redirectUrl += '?r=' + encodeURIComponent(req.url);
|
||||
return res.redirect(redirectUrl);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
const errors = require('@tryghost/errors');
|
||||
const should = require('should');
|
||||
const sinon = require('sinon');
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs-extra');
|
||||
@ -250,40 +251,6 @@ describe('Private Blogging', function () {
|
||||
(next.firstCall.args[0] instanceof errors.NotFoundError).should.eql(true);
|
||||
});
|
||||
|
||||
it('filterPrivateRoutes should 404 for /rss requests', function () {
|
||||
const salt = Date.now().toString();
|
||||
req.url = req.path = '/rss';
|
||||
|
||||
req.session = {
|
||||
token: hash('rightpassword', salt),
|
||||
salt: salt
|
||||
};
|
||||
|
||||
res.isPrivateBlog = true;
|
||||
res.redirect = sinon.spy();
|
||||
|
||||
privateBlogging.filterPrivateRoutes(req, res, next);
|
||||
next.called.should.be.true();
|
||||
(next.firstCall.args[0] instanceof errors.NotFoundError).should.eql(true);
|
||||
});
|
||||
|
||||
it('filterPrivateRoutes should 404 for rss with pagination requests', function () {
|
||||
const salt = Date.now().toString();
|
||||
req.url = req.path = '/rss/1';
|
||||
|
||||
req.session = {
|
||||
token: hash('rightpassword', salt),
|
||||
salt: salt
|
||||
};
|
||||
|
||||
res.isPrivateBlog = true;
|
||||
res.redirect = sinon.spy();
|
||||
|
||||
privateBlogging.filterPrivateRoutes(req, res, next);
|
||||
next.called.should.be.true();
|
||||
(next.firstCall.args[0] instanceof errors.NotFoundError).should.eql(true);
|
||||
});
|
||||
|
||||
it('filterPrivateRoutes should 404 for tag rss requests', function () {
|
||||
const salt = Date.now().toString();
|
||||
req.url = req.path = '/tag/welcome/rss/';
|
||||
@ -349,20 +316,6 @@ describe('Private Blogging', function () {
|
||||
req.url.should.eql('/rss/');
|
||||
});
|
||||
|
||||
it('filterPrivateRoutes: allow private /rss feed', function () {
|
||||
settingsStub.withArgs('public_hash').returns('777aaa');
|
||||
|
||||
req.url = req.originalUrl = req.path = '/777aaa/rss';
|
||||
req.params = {};
|
||||
|
||||
res.isPrivateBlog = true;
|
||||
res.locals = {};
|
||||
|
||||
privateBlogging.filterPrivateRoutes(req, res, next);
|
||||
next.called.should.be.true();
|
||||
req.url.should.eql('/rss');
|
||||
});
|
||||
|
||||
it('filterPrivateRoutes: allow private rss feed e.g. tags', function () {
|
||||
settingsStub.withArgs('public_hash').returns('777aaa');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user