From 5eb136f0c3fa6486641c8bea3aebd8abee9a5441 Mon Sep 17 00:00:00 2001 From: javanna Date: Tue, 13 Jun 2017 14:15:37 +0200 Subject: [PATCH] [TEST] test that low level REST client leaves path untouched Relates to #24987 --- .../org/elasticsearch/client/RestClient.java | 2 +- .../elasticsearch/client/RestClientTests.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java index ba3a07454ee48..cc0f1b3089638 100644 --- a/client/rest/src/main/java/org/elasticsearch/client/RestClient.java +++ b/client/rest/src/main/java/org/elasticsearch/client/RestClient.java @@ -553,7 +553,7 @@ private static HttpRequestBase addRequestBody(HttpRequestBase httpRequest, HttpE return httpRequest; } - private static URI buildUri(String pathPrefix, String path, Map params) { + static URI buildUri(String pathPrefix, String path, Map params) { Objects.requireNonNull(path, "path must not be null"); try { String fullPath; diff --git a/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java b/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java index d8c297ed099c3..6978aab58fe71 100644 --- a/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java +++ b/client/rest/src/test/java/org/elasticsearch/client/RestClientTests.java @@ -23,6 +23,9 @@ import org.apache.http.HttpHost; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import java.net.URI; +import java.util.Collections; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; @@ -77,6 +80,22 @@ public void testPerformAsyncWithWrongEndpoint() throws Exception { } } + public void testBuildUriLeavesPathUntouched() { + { + URI uri = RestClient.buildUri("/foo$bar", "/index/type/id", Collections.emptyMap()); + assertEquals("/foo$bar/index/type/id", uri.getPath()); + } + { + URI uri = RestClient.buildUri(null, "/foo$bar/ty/pe/i/d", Collections.emptyMap()); + assertEquals("/foo$bar/ty/pe/i/d", uri.getPath()); + } + { + URI uri = RestClient.buildUri(null, "/index/type/id", Collections.singletonMap("foo$bar", "x/y/z")); + assertEquals("/index/type/id", uri.getPath()); + assertEquals("foo$bar=x/y/z", uri.getQuery()); + } + } + private static RestClient createRestClient() { HttpHost[] hosts = new HttpHost[]{new HttpHost("localhost", 9200)}; return new RestClient(mock(CloseableHttpAsyncClient.class), randomLongBetween(1_000, 30_000), new Header[]{}, hosts, null, null);