From 00fcc2d3d0ad292f60b308b46570589e2f2fefe6 Mon Sep 17 00:00:00 2001 From: Pierre Gayvallet Date: Wed, 10 Mar 2021 13:34:34 +0100 Subject: [PATCH] remove HAPI plugins registration from legacy (#94262) * remove HAPI plugins registration from legacy * remove duplicate legacy integration tests --- package.json | 1 - src/legacy/server/http/index.js | 11 ++-- .../max_payload_size.test.js | 52 ------------------- .../server/http/register_hapi_plugins.js | 21 -------- .../server/http/setup_base_path_provider.js | 14 ----- yarn.lock | 10 ---- 6 files changed, 3 insertions(+), 106 deletions(-) delete mode 100644 src/legacy/server/http/integration_tests/max_payload_size.test.js delete mode 100644 src/legacy/server/http/register_hapi_plugins.js delete mode 100644 src/legacy/server/http/setup_base_path_provider.js diff --git a/package.json b/package.json index 6a836d52ed69e..51ff46968ea36 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,6 @@ "@hapi/hoek": "^9.1.1", "@hapi/inert": "^6.0.3", "@hapi/podium": "^4.1.1", - "@hapi/vision": "^6.0.1", "@hapi/wreck": "^17.1.0", "@kbn/ace": "link:packages/kbn-ace", "@kbn/analytics": "link:packages/kbn-analytics", diff --git a/src/legacy/server/http/index.js b/src/legacy/server/http/index.js index f2083e045d90f..0fb51b341c3dd 100644 --- a/src/legacy/server/http/index.js +++ b/src/legacy/server/http/index.js @@ -9,15 +9,10 @@ import { format } from 'url'; import Boom from '@hapi/boom'; -import { registerHapiPlugins } from './register_hapi_plugins'; -import { setupBasePathProvider } from './setup_base_path_provider'; - export default async function (kbnServer, server) { server = kbnServer.server; - setupBasePathProvider(kbnServer); - - await registerHapiPlugins(server); + const getBasePath = (request) => kbnServer.newPlatform.setup.core.http.basePath.get(request); server.route({ method: 'GET', @@ -27,8 +22,8 @@ export default async function (kbnServer, server) { if (path === '/' || path.charAt(path.length - 1) !== '/') { throw Boom.notFound(); } - - const pathPrefix = req.getBasePath() ? `${req.getBasePath()}/` : ''; + const basePath = getBasePath(req); + const pathPrefix = basePath ? `${basePath}/` : ''; return h .redirect( format({ diff --git a/src/legacy/server/http/integration_tests/max_payload_size.test.js b/src/legacy/server/http/integration_tests/max_payload_size.test.js deleted file mode 100644 index 78886729f764c..0000000000000 --- a/src/legacy/server/http/integration_tests/max_payload_size.test.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import * as kbnTestServer from '../../../../core/test_helpers/kbn_server'; - -let root; -beforeAll(async () => { - root = kbnTestServer.createRoot({ - server: { maxPayloadBytes: 100 }, - migrations: { skip: true }, - plugins: { initialize: false }, - }); - - await root.setup(); - await root.start(); - - kbnTestServer.getKbnServer(root).server.route({ - path: '/payload_size_check/test/route', - method: 'POST', - config: { payload: { maxBytes: 200 } }, - handler: (req) => req.payload.data.slice(0, 5), - }); -}, 30000); - -afterAll(async () => await root.shutdown()); - -test('accepts payload with a size larger than default but smaller than route config allows', async () => { - await kbnTestServer.request - .post(root, '/payload_size_check/test/route') - .send({ - data: Array(150).fill('+').join(''), - }) - .expect(200, '+++++'); -}); - -test('fails with 413 if payload size is larger than default and route config allows', async () => { - await kbnTestServer.request - .post(root, '/payload_size_check/test/route') - .send({ - data: Array(250).fill('+').join(''), - }) - .expect(413, { - statusCode: 413, - error: 'Request Entity Too Large', - message: 'Payload content length greater than maximum allowed: 200', - }); -}); diff --git a/src/legacy/server/http/register_hapi_plugins.js b/src/legacy/server/http/register_hapi_plugins.js deleted file mode 100644 index 688df0328e81b..0000000000000 --- a/src/legacy/server/http/register_hapi_plugins.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import HapiTemplates from '@hapi/vision'; -import HapiStaticFiles from '@hapi/inert'; -import HapiProxy from '@hapi/h2o2'; - -const plugins = [HapiTemplates, HapiStaticFiles, HapiProxy]; - -async function registerPlugins(server) { - return await server.register(plugins); -} - -export function registerHapiPlugins(server) { - registerPlugins(server); -} diff --git a/src/legacy/server/http/setup_base_path_provider.js b/src/legacy/server/http/setup_base_path_provider.js deleted file mode 100644 index 8c28131fc5ba8..0000000000000 --- a/src/legacy/server/http/setup_base_path_provider.js +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export function setupBasePathProvider(kbnServer) { - kbnServer.server.decorate('request', 'getBasePath', function () { - const request = this; - return kbnServer.newPlatform.setup.core.http.basePath.get(request); - }); -} diff --git a/yarn.lock b/yarn.lock index bcd3787ece63b..a2b4cfd857214 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2016,16 +2016,6 @@ dependencies: "@hapi/hoek" "9.x.x" -"@hapi/vision@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/@hapi/vision/-/vision-6.0.1.tgz#976c3575be56d3cb5b472ddcfe0b7403778706fd" - integrity sha512-xv4PwmhbXCLzDfojZ7l4+P/YynBhMInV8GtLPH4gB74prhwOl8lGcJxxK8V9rf1aMH/vonM5yVGd9FuoA9sT0A== - dependencies: - "@hapi/boom" "9.x.x" - "@hapi/bounce" "2.x.x" - "@hapi/hoek" "9.x.x" - "@hapi/validate" "1.x.x" - "@hapi/wreck@17.x.x", "@hapi/wreck@^17.0.0", "@hapi/wreck@^17.1.0": version "17.1.0" resolved "https://registry.yarnpkg.com/@hapi/wreck/-/wreck-17.1.0.tgz#fbdc380c6f3fa1f8052dc612b2d3b6ce3e88dbec"