Skip to content

Commit

Permalink
fixing mangling of floating point numbers by console (elastic#23685)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bmcconaghy committed Oct 19, 2018
1 parent a7ce5de commit 636682d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core_plugins/console/public/src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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');
});
});
});
Expand Down
11 changes: 10 additions & 1 deletion src/core_plugins/console/server/proxy_route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/apps/console/_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 636682d

Please sign in to comment.