From 6bdb182233dc3639a7ba9a5fdb5c7d521c6475ce Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Tue, 10 Dec 2024 08:20:09 -0500 Subject: [PATCH] Use the Upgrade flow by default Signed-off-by: Andriy Redko --- .../resources/org/opensearch/bootstrap/test.policy | 11 +++++++++++ client/rest/licenses/httpclient5-5.4.1.jar.sha1 | 2 +- client/rest/licenses/httpcore5-5.3.1.jar.sha1 | 2 +- client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 | 2 +- .../rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 | 2 +- .../java/org/opensearch/client/RestClientBuilder.java | 9 ++------- .../client/RestClientSingleHostIntegTests.java | 10 +++++++++- client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 | 2 +- client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 | 2 +- .../org/opensearch/bootstrap/test-framework.policy | 2 +- .../org/opensearch/bootstrap/BootstrapForTesting.java | 8 ++------ 11 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 client/rest-high-level/src/test/resources/org/opensearch/bootstrap/test.policy diff --git a/client/rest-high-level/src/test/resources/org/opensearch/bootstrap/test.policy b/client/rest-high-level/src/test/resources/org/opensearch/bootstrap/test.policy new file mode 100644 index 0000000000000..2604c2492d8ab --- /dev/null +++ b/client/rest-high-level/src/test/resources/org/opensearch/bootstrap/test.policy @@ -0,0 +1,11 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +grant { + permission java.net.SocketPermission "*", "connect,resolve"; +}; diff --git a/client/rest/licenses/httpclient5-5.4.1.jar.sha1 b/client/rest/licenses/httpclient5-5.4.1.jar.sha1 index 3a4fec6e8afc7..40156e9a42620 100644 --- a/client/rest/licenses/httpclient5-5.4.1.jar.sha1 +++ b/client/rest/licenses/httpclient5-5.4.1.jar.sha1 @@ -1 +1 @@ -ce913081e592ee8eeee35c4e577d7dce13cba7a4 +ce913081e592ee8eeee35c4e577d7dce13cba7a4 \ No newline at end of file diff --git a/client/rest/licenses/httpcore5-5.3.1.jar.sha1 b/client/rest/licenses/httpcore5-5.3.1.jar.sha1 index 90f194e770368..3b7536d6e8998 100644 --- a/client/rest/licenses/httpcore5-5.3.1.jar.sha1 +++ b/client/rest/licenses/httpcore5-5.3.1.jar.sha1 @@ -1 +1 @@ -eaf64237945d7d0f301d48420e8bdb7f565a7b0e +eaf64237945d7d0f301d48420e8bdb7f565a7b0e \ No newline at end of file diff --git a/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 b/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 index bc122991af736..6c3e4ffa5c6da 100644 --- a/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 +++ b/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 @@ -1 +1 @@ -760c34db3ba41b0ffa07e956bc308d3a12356915 +760c34db3ba41b0ffa07e956bc308d3a12356915 \ No newline at end of file diff --git a/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 b/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 index cb71833aad877..ca9828394f40e 100644 --- a/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 +++ b/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 @@ -1 +1 @@ -c4c0c3c7bbcb0db54aa7ddd39e34a835428c99c0 +c4c0c3c7bbcb0db54aa7ddd39e34a835428c99c0 \ No newline at end of file diff --git a/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java b/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java index 78a1d3e3fcf06..3e38f9ae95dec 100644 --- a/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java +++ b/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java @@ -308,15 +308,10 @@ private CloseableHttpAsyncClient createHttpClient() { // default timeouts are all infinite RequestConfig.Builder requestConfigBuilder = RequestConfig.custom() .setConnectTimeout(Timeout.ofMilliseconds(DEFAULT_CONNECT_TIMEOUT_MILLIS)) - .setResponseTimeout(Timeout.ofMilliseconds(DEFAULT_RESPONSE_TIMEOUT_MILLIS)) - .setProtocolUpgradeEnabled(false); + .setResponseTimeout(Timeout.ofMilliseconds(DEFAULT_RESPONSE_TIMEOUT_MILLIS)); if (requestConfigCallback != null) { requestConfigBuilder = requestConfigCallback.customizeRequestConfig(requestConfigBuilder); } - RequestConfig requestConfig = requestConfigBuilder.build(); - if (requestConfig.isProtocolUpgradeEnabled()) { - throw new IllegalArgumentException("protocol upgrade is not supported"); - } try { final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create() @@ -337,7 +332,7 @@ public TlsDetails create(final SSLEngine sslEngine) { .build(); HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create() - .setDefaultRequestConfig(requestConfig) + .setDefaultRequestConfig(requestConfigBuilder.build()) .setConnectionManager(connectionManager) .setTargetAuthenticationStrategy(DefaultAuthenticationStrategy.INSTANCE) .disableAutomaticRetries(); diff --git a/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java b/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java index de04dd843b2db..84f6e7c8beb2e 100644 --- a/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java +++ b/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java @@ -382,6 +382,10 @@ public void testHeaders() throws Exception { if (method.equals("HEAD") == false) { standardHeaders.add("Content-length"); } + if (method.equals("HEAD") == true || method.equals("GET") == true || method.equals("OPTIONS") == true) { + standardHeaders.add("Upgrade"); + } + final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header"); final int statusCode = randomStatusCode(getRandom()); Request request = new Request(method, "/" + statusCode); @@ -400,11 +404,15 @@ public void testHeaders() throws Exception { assertEquals(method, esResponse.getRequestLine().getMethod()); assertEquals(statusCode, esResponse.getStatusLine().getStatusCode()); assertEquals(pathPrefix + "/" + statusCode, esResponse.getRequestLine().getUri()); + assertHeaders(defaultHeaders, requestHeaders, esResponse.getHeaders(), standardHeaders); + final Set removedHeaders = new HashSet<>(); for (final Header responseHeader : esResponse.getHeaders()) { String name = responseHeader.getName(); - if (name.startsWith("Header") == false) { + // Some headers could be returned multiple times in response, like Connection fe. + if (name.startsWith("Header") == false && removedHeaders.contains(name) == false) { assertTrue("unknown header was returned " + name, standardHeaders.remove(name)); + removedHeaders.add(name); } } assertTrue("some expected standard headers weren't returned: " + standardHeaders, standardHeaders.isEmpty()); diff --git a/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 b/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 index 3a4fec6e8afc7..40156e9a42620 100644 --- a/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 +++ b/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 @@ -1 +1 @@ -ce913081e592ee8eeee35c4e577d7dce13cba7a4 +ce913081e592ee8eeee35c4e577d7dce13cba7a4 \ No newline at end of file diff --git a/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 b/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 index 90f194e770368..3b7536d6e8998 100644 --- a/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 +++ b/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 @@ -1 +1 @@ -eaf64237945d7d0f301d48420e8bdb7f565a7b0e +eaf64237945d7d0f301d48420e8bdb7f565a7b0e \ No newline at end of file diff --git a/server/src/main/resources/org/opensearch/bootstrap/test-framework.policy b/server/src/main/resources/org/opensearch/bootstrap/test-framework.policy index c62adda511140..e1a3b4618035e 100644 --- a/server/src/main/resources/org/opensearch/bootstrap/test-framework.policy +++ b/server/src/main/resources/org/opensearch/bootstrap/test-framework.policy @@ -120,7 +120,7 @@ grant codeBase "${codebase.httpcore5}" { grant codeBase "${codebase.httpclient5}" { // httpclient5 makes socket connections for rest tests - permission java.net.SocketPermission "*", "connect"; + permission java.net.SocketPermission "*", "connect,resolve"; }; grant codeBase "${codebase.httpcore-nio}" { diff --git a/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java b/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java index 79cead80fff3e..933385dedcf49 100644 --- a/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java +++ b/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java @@ -301,15 +301,11 @@ static Set parseClassPathWithSymlinks() throws Exception { private static Set getTrustedHosts() { // try { - List hosts = Collections.list(NetworkInterface.getNetworkInterfaces()) + return Collections.list(NetworkInterface.getNetworkInterfaces()) .stream() .flatMap(iface -> Collections.list(iface.getInetAddresses()).stream()) .map(address -> NetworkAddress.format(address)) - .collect(Collectors.toList()); - // 0:0:0:0:0:0:0:1 is simplified to ::1, in it test, the incoming address can be 0:0:0:0:0:0:0:1, - // so we should add it to trusted hosts. - hosts.add("0:0:0:0:0:0:0:1"); - return Collections.unmodifiableSet(new HashSet<>(hosts)); + .collect(Collectors.toSet()); } catch (final SocketException e) { return Collections.emptySet(); }