mirror of https://github.com/apache/kafka.git
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 commit09bc5be63e
. * Revert "KAFKA-16824: Utils.getHost and Utils.getPort do not catch a lot of invalid host and ports. (#16048)" This reverts commit0971924ebc
. Reviewers: Andrew Schofield <aschofield@confluent.io>
This commit is contained in:
parent
6b82a4cc6a
commit
5a074a60df
|
@ -94,9 +94,9 @@ public final class Utils {
|
||||||
|
|
||||||
private 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
|
// 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\\-%._:]*)");
|
private static final Pattern VALID_HOST_CHARACTERS = Pattern.compile("([0-9a-zA-Z\\-%._:]*)");
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,6 @@ import org.apache.kafka.test.TestUtils;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.Timeout;
|
import org.junit.jupiter.api.Timeout;
|
||||||
import org.junit.jupiter.api.function.Executable;
|
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 org.mockito.stubbing.OngoingStubbing;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
@ -118,35 +116,16 @@ public class UtilsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@Test
|
||||||
@CsvSource(value = {"PLAINTEXT", "SASL_PLAINTEXT", "SSL", "SASL_SSL"})
|
public void testGetHost() {
|
||||||
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"));
|
|
||||||
assertEquals("127.0.0.1", getHost("127.0.0.1:8000"));
|
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"));
|
assertEquals("::1", getHost("[::1]:1234"));
|
||||||
}
|
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"));
|
||||||
@ParameterizedTest
|
assertEquals("fe80::b1da:69ca:57f7:63d8%3", getHost("PLAINTEXT://[fe80::b1da:69ca:57f7:63d8%3]:5678"));
|
||||||
@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"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -161,7 +140,6 @@ public class UtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPort() {
|
public void testGetPort() {
|
||||||
// valid
|
|
||||||
assertEquals(8000, getPort("127.0.0.1:8000").intValue());
|
assertEquals(8000, getPort("127.0.0.1:8000").intValue());
|
||||||
assertEquals(8080, getPort("mydomain.com:8080").intValue());
|
assertEquals(8080, getPort("mydomain.com:8080").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("[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());
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue