This is an automated email from the ASF dual-hosted git repository.
schofielaj pushed a commit to branch 3.9
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/3.9 by this push:
new 5a074a60df0 KAFKA-18171: Revert the strict config validation for 3.8
and 3.9 (#18741)
5a074a60df0 is described below
commit 5a074a60df07235cedf2fe132a6e1963aee22ebd
Author: Chung, Ming-Yen <[email protected]>
AuthorDate: Thu Jan 30 06:18:29 2025 +0800
KAFKA-18171: Revert the strict config validation for 3.8 and 3.9 (#18741)
* Revert "KAFKA-16946: Utils.getHost/getPort cannot parse
SASL_PLAINTEXT://host:port (#16319)"
This reverts commit 09bc5be63e16aaf19e2325099c9c6b5c07f4606f.
* Revert "KAFKA-16824: Utils.getHost and Utils.getPort do not catch a lot
of invalid host and ports. (#16048)"
This reverts commit 0971924ebc7e65eb7055010d2400626d31967d8c.
Reviewers: Andrew Schofield <[email protected]>
---
.../java/org/apache/kafka/common/utils/Utils.java | 4 +-
.../org/apache/kafka/common/utils/UtilsTest.java | 44 ++++------------------
2 files changed, 10 insertions(+), 38 deletions(-)
diff --git a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java
b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java
index b23a9d72a4f..3dc781ec047 100644
--- a/clients/src/main/java/org/apache/kafka/common/utils/Utils.java
+++ b/clients/src/main/java/org/apache/kafka/common/utils/Utils.java
@@ -94,9 +94,9 @@ public final class Utils {
private Utils() {}
- // This matches URIs of formats: host:port and protocol://host:port
+ // This matches URIs of formats: host:port and protocol:\\host:port
// IPv6 is supported with [ip] pattern
- private static final Pattern HOST_PORT_PATTERN =
Pattern.compile("^(?:[0-9a-zA-Z\\-%._]*://)?\\[?([0-9a-zA-Z\\-%._:]*)]?:([0-9]+)");
+ private static final Pattern HOST_PORT_PATTERN =
Pattern.compile(".*?\\[?([0-9a-zA-Z\\-%._:]*)\\]?:([0-9]+)");
private static final Pattern VALID_HOST_CHARACTERS =
Pattern.compile("([0-9a-zA-Z\\-%._:]*)");
diff --git a/clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
b/clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
index 1905b459037..f2cd912f8b4 100755
--- a/clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/utils/UtilsTest.java
@@ -22,8 +22,6 @@ import org.apache.kafka.test.TestUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.function.Executable;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.stubbing.OngoingStubbing;
import java.io.Closeable;
@@ -118,35 +116,16 @@ public class UtilsTest {
}
}
- @ParameterizedTest
- @CsvSource(value = {"PLAINTEXT", "SASL_PLAINTEXT", "SSL", "SASL_SSL"})
- public void testGetHostValid(String protocol) {
- assertEquals("mydomain.com", getHost(protocol +
"://mydomain.com:8080"));
- assertEquals("MyDomain.com", getHost(protocol +
"://MyDomain.com:8080"));
- assertEquals("My_Domain.com", getHost(protocol +
"://My_Domain.com:8080"));
- assertEquals("::1", getHost(protocol + "://[::1]:1234"));
- assertEquals("2001:db8:85a3:8d3:1319:8a2e:370:7348", getHost(protocol
+ "://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:5678"));
- assertEquals("2001:DB8:85A3:8D3:1319:8A2E:370:7348", getHost(protocol
+ "://[2001:DB8:85A3:8D3:1319:8A2E:370:7348]:5678"));
- assertEquals("fe80::b1da:69ca:57f7:63d8%3", getHost(protocol +
"://[fe80::b1da:69ca:57f7:63d8%3]:5678"));
+ @Test
+ public void testGetHost() {
assertEquals("127.0.0.1", getHost("127.0.0.1:8000"));
+ assertEquals("mydomain.com", getHost("PLAINTEXT://mydomain.com:8080"));
+ assertEquals("MyDomain.com", getHost("PLAINTEXT://MyDomain.com:8080"));
+ assertEquals("My_Domain.com",
getHost("PLAINTEXT://My_Domain.com:8080"));
assertEquals("::1", getHost("[::1]:1234"));
- }
-
- @ParameterizedTest
- @CsvSource(value = {"PLAINTEXT", "SASL_PLAINTEXT", "SSL", "SASL_SSL"})
- public void testGetHostInvalid(String protocol) {
- assertNull(getHost(protocol + "://mydo)main.com:8080"));
- assertNull(getHost(protocol + "://mydo(main.com:8080"));
- assertNull(getHost(protocol + "://mydo()main.com:8080"));
- assertNull(getHost(protocol + "://mydo(main).com:8080"));
- assertNull(getHost(protocol +
"://[2001:db)8:85a3:8d3:1319:8a2e:370:7348]:5678"));
- assertNull(getHost(protocol +
"://[2001:db(8:85a3:8d3:1319:8a2e:370:7348]:5678"));
- assertNull(getHost(protocol +
"://[2001:db()8:85a3:8d3:1319:8a2e:370:7348]:5678"));
- assertNull(getHost(protocol +
"://[2001:db(8:85a3:)8d3:1319:8a2e:370:7348]:5678"));
- assertNull(getHost("ho)st:9092"));
- assertNull(getHost("ho(st:9092"));
- assertNull(getHost("ho()st:9092"));
- assertNull(getHost("ho(st):9092"));
+ assertEquals("2001:db8:85a3:8d3:1319:8a2e:370:7348",
getHost("PLAINTEXT://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:5678"));
+ assertEquals("2001:DB8:85A3:8D3:1319:8A2E:370:7348",
getHost("PLAINTEXT://[2001:DB8:85A3:8D3:1319:8A2E:370:7348]:5678"));
+ assertEquals("fe80::b1da:69ca:57f7:63d8%3",
getHost("PLAINTEXT://[fe80::b1da:69ca:57f7:63d8%3]:5678"));
}
@Test
@@ -161,7 +140,6 @@ public class UtilsTest {
@Test
public void testGetPort() {
- // valid
assertEquals(8000, getPort("127.0.0.1:8000").intValue());
assertEquals(8080, getPort("mydomain.com:8080").intValue());
assertEquals(8080, getPort("MyDomain.com:8080").intValue());
@@ -169,12 +147,6 @@ public class UtilsTest {
assertEquals(5678,
getPort("[2001:db8:85a3:8d3:1319:8a2e:370:7348]:5678").intValue());
assertEquals(5678,
getPort("[2001:DB8:85A3:8D3:1319:8A2E:370:7348]:5678").intValue());
assertEquals(5678,
getPort("[fe80::b1da:69ca:57f7:63d8%3]:5678").intValue());
-
- // invalid
- assertNull(getPort("host:-92"));
- assertNull(getPort("host:-9-2"));
- assertNull(getPort("host:92-"));
- assertNull(getPort("host:9-2"));
}
@Test