From afbc7909a2cf516edf10487e399d70e8af7061d7 Mon Sep 17 00:00:00 2001 From: Elastic Jasper Date: Wed, 19 Oct 2016 15:25:13 -0400 Subject: [PATCH] Backport PR #8758 --------- MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Commit 1:** URI-encode forwarded location header in proxy Right now there are situations in which ElasticSearch puts characters in the character code range between 128 and 255 into the `Location` header. This leads to an exception when trying to pass on that header through the hapi proxy in versions before 15.0.0, because it validates that only US-ASCII characters are used in headers. To work around that situation, the `Location` header is encoded using `encodeURI()` for now. Closes #8705 * Original sha: 18c23c17d970ad733f4ac74959047fc172cde2d9 * Authored by Felix Stürmer on 2016-10-18T17:55:31Z **Commit 2:** Add test to verify umlaut in vis name Relates to #8705 * Original sha: e100e1f5c98fc028846387c12d9d403e9f905758 * Authored by Felix Stürmer on 2016-10-19T09:01:46Z **Commit 3:** [elasticsearch/proxy] use different code path with erorr * Original sha: fec5e1a2dc0ad772976630c3d128bdae3a6977f3 * Authored by spalger on 2016-10-19T19:06:39Z --- src/core_plugins/elasticsearch/lib/create_proxy.js | 12 +++++++++++- test/functional/apps/visualize/_area_chart.js | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/core_plugins/elasticsearch/lib/create_proxy.js b/src/core_plugins/elasticsearch/lib/create_proxy.js index 2ef2bd1da56d8..068712ca9c70f 100644 --- a/src/core_plugins/elasticsearch/lib/create_proxy.js +++ b/src/core_plugins/elasticsearch/lib/create_proxy.js @@ -20,7 +20,17 @@ function createProxy(server, method, route, config) { xforward: true, timeout: server.config().get('elasticsearch.requestTimeout'), onResponse: function (err, responseFromUpstream, request, reply) { - reply(err, responseFromUpstream); + if (err) { + reply(err); + return; + } + + if (responseFromUpstream.headers.location) { + // TODO: Workaround for #8705 until hapi has been updated to >= 15.0.0 + responseFromUpstream.headers.location = encodeURI(responseFromUpstream.headers.location); + } + + reply(null, responseFromUpstream); } } }, diff --git a/test/functional/apps/visualize/_area_chart.js b/test/functional/apps/visualize/_area_chart.js index 15bbf4aada834..bd9bfec024801 100644 --- a/test/functional/apps/visualize/_area_chart.js +++ b/test/functional/apps/visualize/_area_chart.js @@ -74,6 +74,16 @@ bdd.describe('visualize app', function describeIndexTests() { }); }); + bdd.it('should save and load with non-ascii characters', async function () { + const vizNamewithSpecialChars = `${vizName1} with Umlaut ä`; + const message = await PageObjects.visualize.saveVisualization(vizNamewithSpecialChars); + + PageObjects.common.debug(`Saved viz message with umlaut = ${message}`); + expect(message).to.be(`Visualization Editor: Saved Visualization "${vizNamewithSpecialChars}"`); + + await PageObjects.visualize.waitForToastMessageGone(); + }); + bdd.it('should save and load', function () { return PageObjects.visualize.saveVisualization(vizName1) .then(function (message) {