From 04bb2a9f8fd23e102a68d15e7277be28a22714f2 Mon Sep 17 00:00:00 2001 From: webzwo0i Date: Wed, 23 Dec 2020 15:02:14 +0100 Subject: [PATCH] caching_middleware: add test for unsupported methods --- tests/backend/specs/caching_middleware.js | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/backend/specs/caching_middleware.js b/tests/backend/specs/caching_middleware.js index e8e14a5cf..0b1b34f93 100644 --- a/tests/backend/specs/caching_middleware.js +++ b/tests/backend/specs/caching_middleware.js @@ -51,6 +51,7 @@ describe(__filename, function () { '/javascripts/lib/ep_etherpad-lite/static/js/pad.js?callback=require.define', '/javascripts/lib/ep_etherpad-lite/static/js/timeslider.js?callback=require.define', ]; + const unsupportedMethods = ['post', 'put', 'delete', 'options', 'trace', 'patch']; before(async function () { agent = await common.init(); @@ -68,7 +69,7 @@ describe(__filename, function () { settings.minify = false; }); it('gets packages uncompressed without Accept-Encoding gzip', async function () { - await Promise.all(packages.map(async (resource) => agent.get(resource) + await Promise.all(packages.map(async (resource) => await agent.get(resource) .set('Accept-Encoding', fantasyEncoding) .use(disableAutoDeflate) .then((res) => { @@ -80,7 +81,7 @@ describe(__filename, function () { }); it('gets packages compressed with Accept-Encoding gzip', async function () { - await Promise.all(packages.map(async (resource) => agent.get(resource) + await Promise.all(packages.map(async (resource) => await agent.get(resource) .set('Accept-Encoding', 'gzip') .use(disableAutoDeflate) .then((res) => { @@ -102,6 +103,15 @@ describe(__filename, function () { .set('Accept-Encoding', fantasyEncoding) .then((res) => assert.equal(res.header['content-encoding'], undefined)); }); + + it('only HEAD and GET are supported', async function() { + await Promise.all(unsupportedMethods.map(async (method) => { + await agent[method](packages[0]) + .then((res) => { + assert.equal(res.statusCode, 405) + }) + })); + }); }); context('when minify is true', function () { @@ -109,7 +119,7 @@ describe(__filename, function () { settings.minify = true; }); it('gets packages uncompressed without Accept-Encoding gzip', async function () { - await Promise.all(packages.map(async (resource) => agent.get(resource) + await Promise.all(packages.map(async (resource) => await agent.get(resource) .set('Accept-Encoding', fantasyEncoding) .use(disableAutoDeflate) .then((res) => { @@ -121,7 +131,7 @@ describe(__filename, function () { }); it('gets packages compressed with Accept-Encoding gzip', async function () { - await Promise.all(packages.map(async (resource) => agent.get(resource) + await Promise.all(packages.map(async (resource) => await agent.get(resource) .set('Accept-Encoding', 'gzip') .use(disableAutoDeflate) .then((res) => { @@ -143,5 +153,14 @@ describe(__filename, function () { .set('Accept-Encoding', fantasyEncoding) .then((res) => assert.equal(res.header['content-encoding'], undefined)); }); + + it('only HEAD and GET are supported', async function() { + await Promise.all(unsupportedMethods.map(async (method) => { + await agent[method](packages[0]) + .then((res) => { + assert.equal(res.statusCode, 405) + }) + })); + }); }); });