0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Rename private blogging mw functions

- This is just a nicety, trying to make it easier to follow the logic of private blogging
This commit is contained in:
Hannah Wolfe 2020-06-15 20:55:59 +01:00
parent 4ae907781a
commit f4641aabe4
3 changed files with 19 additions and 19 deletions

View file

@ -106,7 +106,7 @@ const privateBlogging = {
}, },
// This is here so a call to /private/ after a session is verified will redirect to home; // This is here so a call to /private/ after a session is verified will redirect to home;
isPrivateSessionAuth: function isPrivateSessionAuth(req, res, next) { redirectPrivateToHomeIfLoggedIn: function redirectPrivateToHomeIfLoggedIn(req, res, next) {
if (!res.isPrivateBlog) { if (!res.isPrivateBlog) {
return res.redirect(urlUtils.urlFor('home', true)); return res.redirect(urlUtils.urlFor('home', true));
} }
@ -123,7 +123,7 @@ const privateBlogging = {
} }
}, },
authenticateProtection: function authenticateProtection(req, res, next) { doLoginToPrivateSite: function doLoginToPrivateSite(req, res, next) {
// if errors have been generated from the previous call // if errors have been generated from the previous call
if (res.error) { if (res.error) {
return next(); return next();

View file

@ -30,14 +30,14 @@ function _renderer(req, res) {
privateRouter privateRouter
.route('/') .route('/')
.get( .get(
middleware.isPrivateSessionAuth, middleware.redirectPrivateToHomeIfLoggedIn,
_renderer _renderer
) )
.post( .post(
bodyParser.urlencoded({extended: true}), bodyParser.urlencoded({extended: true}),
middleware.isPrivateSessionAuth, middleware.redirectPrivateToHomeIfLoggedIn,
web.shared.middlewares.brute.privateBlog, web.shared.middlewares.brute.privateBlog,
middleware.authenticateProtection, middleware.doLoginToPrivateSite,
_renderer _renderer
); );

View file

@ -58,12 +58,12 @@ describe('Private Blogging', function () {
next.called.should.be.true(); next.called.should.be.true();
}); });
it('isPrivateSessionAuth should redirect if blog is not private', function () { it('redirectPrivateToHomeIfLoggedIn should redirect if blog is not private', function () {
res = { res = {
redirect: sinon.spy(), redirect: sinon.spy(),
isPrivateBlog: false isPrivateBlog: false
}; };
privateBlogging.isPrivateSessionAuth(req, res, next); privateBlogging.redirectPrivateToHomeIfLoggedIn(req, res, next);
res.redirect.called.should.be.true(); res.redirect.called.should.be.true();
}); });
}); });
@ -146,9 +146,9 @@ describe('Private Blogging', function () {
res.end.called.should.be.true(); res.end.called.should.be.true();
}); });
it('authenticateProtection should call next if error', function () { it('doLoginToPrivateSite should call next if error', function () {
res.error = 'Test Error'; res.error = 'Test Error';
privateBlogging.authenticateProtection(req, res, next); privateBlogging.doLoginToPrivateSite(req, res, next);
next.called.should.be.true(); next.called.should.be.true();
}); });
@ -181,7 +181,7 @@ describe('Private Blogging', function () {
res.redirect.called.should.be.true(); res.redirect.called.should.be.true();
}); });
it('isPrivateSessionAuth should redirect if hash is verified', function () { it('redirectPrivateToHomeIfLoggedIn should redirect if hash is verified', function () {
const salt = Date.now().toString(); const salt = Date.now().toString();
req.session = { req.session = {
@ -190,38 +190,38 @@ describe('Private Blogging', function () {
}; };
res.redirect = sinon.spy(); res.redirect = sinon.spy();
privateBlogging.isPrivateSessionAuth(req, res, next); privateBlogging.redirectPrivateToHomeIfLoggedIn(req, res, next);
res.redirect.called.should.be.true(); res.redirect.called.should.be.true();
}); });
it('isPrivateSessionAuth should return next if hash is not verified', function () { it('redirectPrivateToHomeIfLoggedIn should return next if hash is not verified', function () {
req.session = { req.session = {
token: 'wrongpassword', token: 'wrongpassword',
salt: Date.now().toString() salt: Date.now().toString()
}; };
privateBlogging.isPrivateSessionAuth(req, res, next); privateBlogging.redirectPrivateToHomeIfLoggedIn(req, res, next);
next.called.should.be.true(); next.called.should.be.true();
}); });
it('authenticateProtection should return next if password is incorrect', function () { it('doLoginToPrivateSite should return next if password is incorrect', function () {
req.body = {password: 'wrongpassword'}; req.body = {password: 'wrongpassword'};
privateBlogging.authenticateProtection(req, res, next); privateBlogging.doLoginToPrivateSite(req, res, next);
res.error.should.not.be.empty(); res.error.should.not.be.empty();
next.called.should.be.true(); next.called.should.be.true();
}); });
it('authenticateProtection should redirect if password is correct', function () { it('doLoginToPrivateSite should redirect if password is correct', function () {
req.body = {password: 'rightpassword'}; req.body = {password: 'rightpassword'};
req.session = {}; req.session = {};
res.redirect = sinon.spy(); res.redirect = sinon.spy();
privateBlogging.authenticateProtection(req, res, next); privateBlogging.doLoginToPrivateSite(req, res, next);
res.redirect.called.should.be.true(); res.redirect.called.should.be.true();
}); });
it('authenticateProtection should redirect to "/" if r param is a full url', function () { it('doLoginToPrivateSite should redirect to "/" if r param is a full url', function () {
req.body = {password: 'rightpassword'}; req.body = {password: 'rightpassword'};
req.session = {}; req.session = {};
req.query = { req.query = {
@ -229,7 +229,7 @@ describe('Private Blogging', function () {
}; };
res.redirect = sinon.spy(); res.redirect = sinon.spy();
privateBlogging.authenticateProtection(req, res, next); privateBlogging.doLoginToPrivateSite(req, res, next);
res.redirect.called.should.be.true(); res.redirect.called.should.be.true();
res.redirect.args[0][0].should.be.equal('/'); res.redirect.args[0][0].should.be.equal('/');
}); });