This is an automated email from the ASF dual-hosted git repository.
earthchen pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.3 by this push:
new bc09177b80 [PR] #15935 Enhance NetUtils IPv6 handling and test
coverage (#15974)
bc09177b80 is described below
commit bc09177b8064706b46b8fbb6085e65325d43b0eb
Author: Krrish <[email protected]>
AuthorDate: Wed Jan 7 12:02:20 2026 +0530
[PR] #15935 Enhance NetUtils IPv6 handling and test coverage (#15974)
* test: clarify unsupported IPv6 behavior in NetUtils
* test: added IPV6 edgecase, fixed ambigious CIDR testcase
---
.../apache/dubbo/common/utils/NetUtilsTest.java | 56 ++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
index d5818d90a1..da62139a7d 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
@@ -32,6 +32,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -224,6 +225,61 @@ class NetUtilsTest {
assertThat(normalized.getHostAddress(),
equalTo("fe80:0:0:0:894:aeec:f37d:23e1%5"));
}
+ // ================================
+ // IPv6 normalization and testcases
+ // ================================
+
+ @Test
+ void testNormalizeIpv6WithoutScope() throws UnknownHostException {
+ Inet6Address input = (Inet6Address)
InetAddress.getByName("2001:db8::1");
+
+ InetAddress result = NetUtils.normalizeV6Address(input);
+
+ assertEquals(input.getHostAddress(), result.getHostAddress());
+ }
+ // NOTE:
+ // Scope-name normalization logic is covered by testNormalizeV6Address,
+ // which is currently @Disabled due to Mockito final-class limitations.
+ // These tests focus on CI-safe behavior over hacky way around.
+
+ @Test
+ void testMatchIpExpressionWithIpv6Pattern() throws UnknownHostException {
+ String pattern = "2001:db8::/64";
+ String host = "2001:db8::1";
+ assertTrue(NetUtils.matchIpExpression(pattern, host, 90));
+ }
+
+ @Test
+ void testMatchIPv6WildcardUnsupported() throws UnknownHostException {
+ String pattern = "2001:db8::*";
+ String host = "2001:db8::1";
+ assertThrows(IllegalArgumentException.class, () ->
NetUtils.matchIpExpression(pattern, host, 90));
+ }
+
+ @Test
+ void testMatchIPv4PatternIPv6Host() throws IllegalArgumentException {
+ String pattern = "127.0.0.1";
+ String host = "::1";
+
+ assertThrows(IllegalArgumentException.class, () ->
NetUtils.matchIpExpression(pattern, host, 90));
+ }
+
+ @Test
+ void testValidIpv6EdgeCases() {
+ assertDoesNotThrow(() -> InetAddress.getByName("::"));
+ assertDoesNotThrow(() -> InetAddress.getByName("::1"));
+ assertDoesNotThrow(() -> InetAddress.getByName("2001:db8::"));
+ }
+
+ @Test
+ void testInvalidIpv6EdgeCases() {
+ assertThrows(UnknownHostException.class, () ->
InetAddress.getByName("1:2:3:4:5:6:7:8:9"));
+
+ assertThrows(UnknownHostException.class, () ->
InetAddress.getByName("2001:db8::zzzz"));
+
+ assertThrows(UnknownHostException.class, () ->
InetAddress.getByName("2001:db8::192.168.1"));
+ }
+
@Test
void testMatchIpRangeMatchWhenIpv4() throws UnknownHostException {
assertTrue(NetUtils.matchIpRange("*.*.*.*", "192.168.1.63", 90));