2020-04-29 16:44:27 +01:00
|
|
|
const should = require('should');
|
|
|
|
const sinon = require('sinon');
|
2017-03-14 16:03:30 +00:00
|
|
|
|
2020-04-29 16:44:27 +01:00
|
|
|
// Thing we are testing
|
|
|
|
const redirectAdminUrls = require('../../../../core/server/web/admin/middleware')[0];
|
2017-03-21 08:24:11 +00:00
|
|
|
|
2017-03-14 16:03:30 +00:00
|
|
|
describe('Admin App', function () {
|
|
|
|
afterEach(function () {
|
2019-01-21 17:53:44 +01:00
|
|
|
sinon.restore();
|
2017-03-14 16:03:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('middleware', function () {
|
|
|
|
describe('redirectAdminUrls', function () {
|
2020-04-29 16:44:27 +01:00
|
|
|
let req;
|
|
|
|
let res;
|
|
|
|
let next;
|
2017-03-14 16:03:30 +00:00
|
|
|
// Input: req.originalUrl
|
|
|
|
// Output: either next or res.redirect are called
|
|
|
|
beforeEach(function () {
|
|
|
|
req = {};
|
|
|
|
res = {};
|
2019-01-21 17:53:44 +01:00
|
|
|
next = sinon.stub();
|
|
|
|
res.redirect = sinon.stub();
|
2017-03-14 16:03:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should redirect a url which starts with ghost', function () {
|
|
|
|
req.originalUrl = '/ghost/x';
|
|
|
|
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
|
|
|
|
next.called.should.be.false();
|
|
|
|
res.redirect.called.should.be.true();
|
|
|
|
res.redirect.calledWith('/ghost/#/x').should.be.true();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not redirect /ghost/ on its owh', function () {
|
|
|
|
req.originalUrl = '/ghost/';
|
|
|
|
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
|
|
|
|
next.called.should.be.true();
|
|
|
|
res.redirect.called.should.be.false();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not redirect url that has no slash', function () {
|
|
|
|
req.originalUrl = 'ghost/x';
|
|
|
|
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
|
|
|
|
next.called.should.be.true();
|
|
|
|
res.redirect.called.should.be.false();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not redirect url that starts with something other than /ghost/', function () {
|
|
|
|
req.originalUrl = 'x/ghost/x';
|
|
|
|
|
|
|
|
redirectAdminUrls(req, res, next);
|
|
|
|
|
|
|
|
next.called.should.be.true();
|
|
|
|
res.redirect.called.should.be.false();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|