Added case sensitivity coverage to DynamiRedirectsManager suites

refs https://github.com/TryGhost/Toolbox/issues/139

- These unit tests come directly from equivalent regression tests in Ghost repository - fedbfb3c67/test/regression/site/redirects.test.js
- This changeset covers case sensitivity cases in regexes
This commit is contained in:
Naz 2021-11-29 17:15:14 +04:00
parent 08e2056f6c
commit a6d86c85b6

View File

@ -168,5 +168,94 @@ describe('DynamicRedirectManager', function () {
should.equal(location, '/?something=good');
});
});
describe('Case sensitivity', function () {
it('with case insensitive', function () {
const from = '/^\\/case-insensitive/i';
const to = '/redirected-insensitive';
manager.addRedirect(from , to);
req.url = '/CaSe-InSeNsItIvE';
manager.handleRequest(req, res, function next() {
should.fail(true, 'next should NOT have been called');
});
// NOTE: max-age is "0" because it's not a permanent redirect
should.equal(headers['Cache-Control'], 'public, max-age=0');
should.equal(status, 302);
should.equal(location, '/redirected-insensitive');
});
it('with case sensitive', function () {
const from = '^\\/Case-Sensitive';
const to = '/redirected-sensitive';
manager.addRedirect(from , to);
req.url = '/Case-Sensitive';
manager.handleRequest(req, res, function next() {
should.fail(true, 'next should NOT have been called');
});
// NOTE: max-age is "0" because it's not a permanent redirect
should.equal(headers['Cache-Control'], 'public, max-age=0');
should.equal(status, 302);
should.equal(location, '/redirected-sensitive');
});
it('defaults to case sensitive', function () {
const from = '^\\/Default-Sensitive';
const to = '/redirected-default';
manager.addRedirect(from , to);
req.url = '/Default-Sensitive';
manager.handleRequest(req, res, function next() {
should.fail(true, 'next should NOT have been called');
});
should.equal(headers['Cache-Control'], 'public, max-age=0');
should.equal(status, 302);
should.equal(location, '/redirected-default');
});
it('should not redirect with case sensitive', function () {
const from = '^\\/Case-Sensitive';
const to = '/redirected-insensitive';
manager.addRedirect(from , to);
req.url = '/casE-sensitivE';
manager.handleRequest(req, res, function next() {
should.ok(true, 'next should have been called');
});
should.equal(headers, null);
should.equal(status, null);
should.equal(location, null);
});
it('should not redirect with default case sensitive', function () {
const from = '^\\/Default-Sensitive';
const to = '/redirected-default';
manager.addRedirect(from , to);
req.url = '/defaulT-sensitivE';
manager.handleRequest(req, res, function next() {
should.ok(true, 'next should have been called');
});
should.equal(headers, null);
should.equal(status, null);
should.equal(location, null);
});
});
});
});