0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -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;
isPrivateSessionAuth: function isPrivateSessionAuth(req, res, next) {
redirectPrivateToHomeIfLoggedIn: function redirectPrivateToHomeIfLoggedIn(req, res, next) {
if (!res.isPrivateBlog) {
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 (res.error) {
return next();

View file

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

View file

@ -58,12 +58,12 @@ describe('Private Blogging', function () {
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 = {
redirect: sinon.spy(),
isPrivateBlog: false
};
privateBlogging.isPrivateSessionAuth(req, res, next);
privateBlogging.redirectPrivateToHomeIfLoggedIn(req, res, next);
res.redirect.called.should.be.true();
});
});
@ -146,9 +146,9 @@ describe('Private Blogging', function () {
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';
privateBlogging.authenticateProtection(req, res, next);
privateBlogging.doLoginToPrivateSite(req, res, next);
next.called.should.be.true();
});
@ -181,7 +181,7 @@ describe('Private Blogging', function () {
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();
req.session = {
@ -190,38 +190,38 @@ describe('Private Blogging', function () {
};
res.redirect = sinon.spy();
privateBlogging.isPrivateSessionAuth(req, res, next);
privateBlogging.redirectPrivateToHomeIfLoggedIn(req, res, next);
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 = {
token: 'wrongpassword',
salt: Date.now().toString()
};
privateBlogging.isPrivateSessionAuth(req, res, next);
privateBlogging.redirectPrivateToHomeIfLoggedIn(req, res, next);
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'};
privateBlogging.authenticateProtection(req, res, next);
privateBlogging.doLoginToPrivateSite(req, res, next);
res.error.should.not.be.empty();
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.session = {};
res.redirect = sinon.spy();
privateBlogging.authenticateProtection(req, res, next);
privateBlogging.doLoginToPrivateSite(req, res, next);
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.session = {};
req.query = {
@ -229,7 +229,7 @@ describe('Private Blogging', function () {
};
res.redirect = sinon.spy();
privateBlogging.authenticateProtection(req, res, next);
privateBlogging.doLoginToPrivateSite(req, res, next);
res.redirect.called.should.be.true();
res.redirect.args[0][0].should.be.equal('/');
});