2018-06-02 22:48:23 +03:00
|
|
|
var should = require('should'),
|
2017-03-14 19:03:30 +03:00
|
|
|
sinon = require('sinon'),
|
|
|
|
|
|
|
|
// Thing we are testing
|
2020-03-30 18:26:47 +03:00
|
|
|
redirectAdminUrls = require('../../../../core/server/web/admin/middleware')[0];
|
2017-03-21 11:24:11 +03:00
|
|
|
|
2017-03-14 19:03:30 +03:00
|
|
|
describe('Admin App', function () {
|
|
|
|
afterEach(function () {
|
2019-01-21 19:53:44 +03:00
|
|
|
sinon.restore();
|
2017-03-14 19:03:30 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('middleware', function () {
|
|
|
|
describe('redirectAdminUrls', function () {
|
|
|
|
var req, res, next;
|
|
|
|
// Input: req.originalUrl
|
|
|
|
// Output: either next or res.redirect are called
|
|
|
|
beforeEach(function () {
|
|
|
|
req = {};
|
|
|
|
res = {};
|
2019-01-21 19:53:44 +03:00
|
|
|
next = sinon.stub();
|
|
|
|
res.redirect = sinon.stub();
|
2017-03-14 19:03:30 +03: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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|