From 636682d4b476aceee7cb60cda621f0e22d0ffa6a Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Fri, 19 Oct 2018 10:48:41 -0400 Subject: [PATCH] fixing mangling of floating point numbers by console (#23685) * fixing mangling of floating point numbers by console * fixing tests * fixing issue with large requests * restoring old code for server side as it handles large responses better --- src/core_plugins/console/public/src/input.js | 2 +- .../console/server/__tests__/proxy_route/params.js | 2 +- .../server/__tests__/proxy_route/query_string.js | 6 +++--- src/core_plugins/console/server/proxy_route.js | 11 ++++++++++- test/functional/apps/console/_console.js | 4 ++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/core_plugins/console/public/src/input.js b/src/core_plugins/console/public/src/input.js index 3adddcd7b41f3..68b54ab9ecda1 100644 --- a/src/core_plugins/console/public/src/input.js +++ b/src/core_plugins/console/public/src/input.js @@ -173,7 +173,7 @@ export function initializeInput($el, $actionsEl, $copyAsCurlEl, output, openDocu if (mode === null || mode === 'application/json') { // assume json - auto pretty try { - value = utils.expandLiteralStrings(JSON.stringify(JSON.parse(value), null, 2)); + value = utils.expandLiteralStrings(value); } catch (e) { // nothing to do here diff --git a/src/core_plugins/console/server/__tests__/proxy_route/params.js b/src/core_plugins/console/server/__tests__/proxy_route/params.js index 2fb1370555946..7635a52b9d133 100644 --- a/src/core_plugins/console/server/__tests__/proxy_route/params.js +++ b/src/core_plugins/console/server/__tests__/proxy_route/params.js @@ -126,7 +126,7 @@ describe('Console Proxy Route', () => { expect(args[0]).to.have.property('path', '/api/console/proxy'); expect(args[0]).to.have.property('method', 'post'); expect(args[0]).to.have.property('query').eql({ method: 'HEAD', path: '/index/type/id' }); - expect(args[1]).to.be('/index/type/id'); + expect(args[1]).to.be('/index/type/id?pretty'); }); it('sends the returned timeout, rejectUnauthorized, agent, and base headers to Wreck', async () => { diff --git a/src/core_plugins/console/server/__tests__/proxy_route/query_string.js b/src/core_plugins/console/server/__tests__/proxy_route/query_string.js index 9276ec3b5ef35..59e164dfb2521 100644 --- a/src/core_plugins/console/server/__tests__/proxy_route/query_string.js +++ b/src/core_plugins/console/server/__tests__/proxy_route/query_string.js @@ -66,7 +66,7 @@ describe('Console Proxy Route', () => { await request('GET', 'http://evil.com/test'); sinon.assert.calledOnce(Wreck.request); const args = Wreck.request.getCall(0).args; - expect(args[1]).to.be('http://localhost:9200/http://evil.com/test'); + expect(args[1]).to.be('http://localhost:9200/http://evil.com/test?pretty'); }); }); describe('is missing', () => { @@ -87,14 +87,14 @@ describe('Console Proxy Route', () => { it('combines well with the base url', async () => { await request('GET', '/index/type/id'); sinon.assert.calledOnce(Wreck.request); - expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id'); + expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id?pretty'); }); }); describe(`doesn't start with a slash`, () => { it('combines well with the base url', async () => { await request('GET', 'index/type/id'); sinon.assert.calledOnce(Wreck.request); - expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id'); + expect(Wreck.request.getCall(0).args[1]).to.be('http://localhost:9200/index/type/id?pretty'); }); }); }); diff --git a/src/core_plugins/console/server/proxy_route.js b/src/core_plugins/console/server/proxy_route.js index cdae847f0e702..a66ed870739f2 100644 --- a/src/core_plugins/console/server/proxy_route.js +++ b/src/core_plugins/console/server/proxy_route.js @@ -23,7 +23,16 @@ import Wreck from 'wreck'; import { trimLeft, trimRight } from 'lodash'; function resolveUri(base, path) { - return `${trimRight(base, '/')}/${trimLeft(path, '/')}`; + let pathToUse = `${trimRight(base, '/')}/${trimLeft(path, '/')}`; + const questionMarkIndex = pathToUse.indexOf('?'); + // no query string in pathToUse, append '?pretty' + if (questionMarkIndex === -1) { + pathToUse = `${pathToUse}?pretty`; + } else { + // pathToUse has query string, append '&pretty' + pathToUse = `${pathToUse}&pretty`; + } + return pathToUse; } function extendCommaList(obj, property, value) { diff --git a/test/functional/apps/console/_console.js b/test/functional/apps/console/_console.js index c0ce8772bb7af..8ed8edede0344 100644 --- a/test/functional/apps/console/_console.js +++ b/test/functional/apps/console/_console.js @@ -51,8 +51,8 @@ export default function ({ getService, getPageObjects }) { }); }); - it('default request response should include `"timed_out": false`', async function () { - const expectedResponseContains = '"timed_out": false,'; + it('default request response should include `"timed_out" : false`', async function () { + const expectedResponseContains = '"timed_out" : false,'; await PageObjects.console.clickPlay(); await retry.try(async function () { const actualResponse = await PageObjects.console.getResponse();