From 75f529a79f49ed80ece365afb62e1d44f01f0cfa Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Tue, 22 Aug 2023 07:26:12 -0500 Subject: [PATCH] Enable jarhell check (#3227) JarHell was disabled due to an issue with Kafka where there were multiple copies of the same class packaged inside of a release and test distribution jar. This was resolved with https://github.com/apache/kafka/pull/12407 The Kafka change has been merged, released, and pulled into this repository so we are removing the workaround to supress jar hell issue detection. Signed-off-by: Peter Nied --- build.gradle | 3 +- .../org/opensearch/bootstrap/JarHell.java | 39 ------------------- .../transport/SecurityInterceptorTests.java | 16 ++++++-- 3 files changed, 14 insertions(+), 44 deletions(-) delete mode 100644 src/test/java/org/opensearch/bootstrap/JarHell.java diff --git a/build.gradle b/build.gradle index 0f7d746b0b..8b36328438 100644 --- a/build.gradle +++ b/build.gradle @@ -106,8 +106,7 @@ forbiddenApisTest.enabled = false filepermissions.enabled = false forbiddenPatterns.enabled = false testingConventions.enabled = false -// Conflicts between runtime kafka-clients:x.y.z & testRuntime kafka-clients:x.y.z:test -jarHell.enabled = false +jarHell.enabled = true tasks.whenTaskAdded {task -> if(task.name.contains("forbiddenApisIntegrationTest")) { task.enabled = false diff --git a/src/test/java/org/opensearch/bootstrap/JarHell.java b/src/test/java/org/opensearch/bootstrap/JarHell.java deleted file mode 100644 index 3024a169bc..0000000000 --- a/src/test/java/org/opensearch/bootstrap/JarHell.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - * - * Modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -package org.opensearch.bootstrap; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.HashSet; -import java.util.Set; -import java.util.function.Consumer; - -/** - * Disable JarHell to unblock test development - * https://github.com/opensearch-project/security/issues/1938 - */ -public class JarHell { - private JarHell() {} - - public static void checkJarHell(Consumer output) throws IOException, Exception {} - - public static void checkJarHell(Set urls, Consumer output) throws URISyntaxException, IOException {} - - public static void checkVersionFormat(String targetVersion) {} - - public static void checkJavaVersion(String resource, String targetVersion) {} - - public static Set parseClassPath() { - return new HashSet(); - } -} diff --git a/src/test/java/org/opensearch/security/transport/SecurityInterceptorTests.java b/src/test/java/org/opensearch/security/transport/SecurityInterceptorTests.java index 291f4b7935..73c5edd8b0 100644 --- a/src/test/java/org/opensearch/security/transport/SecurityInterceptorTests.java +++ b/src/test/java/org/opensearch/security/transport/SecurityInterceptorTests.java @@ -9,6 +9,7 @@ package org.opensearch.security.transport; // CS-SUPPRESS-SINGLE: RegexpSingleline Extensions manager used for creating a mock +import java.net.UnknownHostException; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -32,13 +33,13 @@ import org.opensearch.security.support.Base64Helper; import org.opensearch.security.support.ConfigConstants; import org.opensearch.security.user.User; -import org.opensearch.test.OpenSearchTestCase; import org.opensearch.test.transport.MockTransport; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.Transport.Connection; import org.opensearch.transport.TransportInterceptor.AsyncSender; import org.opensearch.transport.TransportRequest; import org.opensearch.transport.TransportRequestOptions; +import org.opensearch.core.common.transport.TransportAddress; import org.opensearch.core.transport.TransportResponse; import org.opensearch.transport.TransportResponseHandler; import org.opensearch.transport.TransportService; @@ -52,6 +53,8 @@ import static org.mockito.Mockito.when; // CS-ENFORCE-SINGLE +import java.net.InetAddress; + public class SecurityInterceptorTests { private SecurityInterceptor securityInterceptor; @@ -141,10 +144,17 @@ public void testSendRequestDecorate() { TransportRequestOptions options = mock(TransportRequestOptions.class); TransportResponseHandler handler = mock(TransportResponseHandler.class); - DiscoveryNode localNode = new DiscoveryNode("local-node", OpenSearchTestCase.buildNewFakeTransportAddress(), Version.CURRENT); + InetAddress localAddress = null; + try { + localAddress = InetAddress.getByName("0.0.0.0"); + } catch (final UnknownHostException uhe) { + throw new RuntimeException(uhe); + } + + DiscoveryNode localNode = new DiscoveryNode("local-node", new TransportAddress(localAddress, 1234), Version.CURRENT); Connection connection1 = transportService.getConnection(localNode); - DiscoveryNode otherNode = new DiscoveryNode("local-node", OpenSearchTestCase.buildNewFakeTransportAddress(), Version.CURRENT); + DiscoveryNode otherNode = new DiscoveryNode("local-node", new TransportAddress(localAddress, 4321), Version.CURRENT); Connection connection2 = transportService.getConnection(otherNode); // isSameNodeRequest = true