diff --git a/test/unit/web/shared/middleware/custom-redirects.test.js b/test/unit/web/shared/middleware/custom-redirects.test.js index 6ed5fbdacf..65d9a9bafa 100644 --- a/test/unit/web/shared/middleware/custom-redirects.test.js +++ b/test/unit/web/shared/middleware/custom-redirects.test.js @@ -5,6 +5,7 @@ const express = require('express'); const customRedirects = rewire('../../../../../core/server/web/shared/middlewares/custom-redirects'); const registerRoutes = customRedirects.__get__('_private.registerRoutes'); +const supertest = require('supertest'); describe('UNIT: custom redirects', function () { let res; @@ -17,7 +18,8 @@ describe('UNIT: custom redirects', function () { }; res = { redirect: sinon.spy(), - set: sinon.spy() + set: sinon.spy(), + writeHead: sinon.spy() }; next = sinon.spy(); @@ -46,4 +48,22 @@ describe('UNIT: custom redirects', function () { 'Cache-Control': `public, max-age=0` }); }); + + it('the parent app functions even when the middleware gets an invalid redirects configuration', function (done) { + const redirectsConfig = [{ + permanent: true, + from: '/invalid_regex/(/size/[a-zA-Z0-9_-.]*/[a-zA-Z0-9_-.]*/[0-9]*/[0-9]*/)([a-zA-Z0-9_-.]*)', + to: '/' + }]; + const redirectsService = customRedirects.__get__('redirectsService'); + sinon.stub(redirectsService, 'loadRedirectsFile').returns(redirectsConfig); + + const app = express('test'); + customRedirects.use(app); + app.get('/', (_req, _res) => _res.status(200).end()); + + supertest(app) + .get('/') + .expect(200, done); + }); });