This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit 4b92b066b0fe185a592317c333020b29e0d97090
Author: Robert Lazarski <[email protected]>
AuthorDate: Mon Apr 20 11:26:08 2026 -1000

    AXIS2-5858 Add unit tests for IPv6 bracket formatting in EPR URLs
    
    Test IPv4 not bracketed, IPv6 compressed/full/loopback all bracketed,
    and null IP handled without NPE. Runs in GHA CI on all JDK versions.
---
 .../transport/http/HTTPTransportUtilsIPv6Test.java | 88 ++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git 
a/modules/transport/http/src/test/java/org/apache/axis2/transport/http/HTTPTransportUtilsIPv6Test.java
 
b/modules/transport/http/src/test/java/org/apache/axis2/transport/http/HTTPTransportUtilsIPv6Test.java
new file mode 100644
index 0000000000..0e2a6126d0
--- /dev/null
+++ 
b/modules/transport/http/src/test/java/org/apache/axis2/transport/http/HTTPTransportUtilsIPv6Test.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axis2.transport.http;
+
+import junit.framework.TestCase;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+
+/**
+ * AXIS2-5858: Verify IPv6 addresses are bracketed in EPR URLs.
+ */
+public class HTTPTransportUtilsIPv6Test extends TestCase {
+
+    private ConfigurationContext configContext;
+    private TransportInDescription httpTransport;
+
+    @Override
+    protected void setUp() throws Exception {
+        AxisConfiguration axisConfig = new AxisConfiguration();
+        configContext = new ConfigurationContext(axisConfig);
+        configContext.setServicePath("services");
+        configContext.setContextRoot("/");
+        httpTransport = new TransportInDescription("http");
+    }
+
+    public void testIPv4AddressNotBracketed() throws Exception {
+        EndpointReference[] eprs = HTTPTransportUtils.getEPRsForService(
+                configContext, httpTransport, "MyService", "192.168.1.100", 
8080);
+        String epr = eprs[0].getAddress();
+        assertTrue("IPv4 should not have brackets: " + epr,
+                epr.contains("://192.168.1.100:8080/"));
+        assertFalse("IPv4 should not have brackets: " + epr,
+                epr.contains("["));
+    }
+
+    public void testIPv6AddressBracketed() throws Exception {
+        EndpointReference[] eprs = HTTPTransportUtils.getEPRsForService(
+                configContext, httpTransport, "MyService", "fe80::1", 8080);
+        String epr = eprs[0].getAddress();
+        assertTrue("IPv6 should be bracketed: " + epr,
+                epr.contains("://[fe80::1]:8080/"));
+    }
+
+    public void testIPv6FullAddressBracketed() throws Exception {
+        EndpointReference[] eprs = HTTPTransportUtils.getEPRsForService(
+                configContext, httpTransport, "MyService",
+                "2001:0db8:85a3:0000:0000:8a2e:0370:7334", 443);
+        String epr = eprs[0].getAddress();
+        assertTrue("Full IPv6 should be bracketed: " + epr,
+                epr.contains("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"));
+    }
+
+    public void testIPv6LoopbackBracketed() throws Exception {
+        EndpointReference[] eprs = HTTPTransportUtils.getEPRsForService(
+                configContext, httpTransport, "MyService", "::1", 8080);
+        String epr = eprs[0].getAddress();
+        assertTrue("IPv6 loopback should be bracketed: " + epr,
+                epr.contains("://[::1]:8080/"));
+    }
+
+    public void testNullIpHandled() throws Exception {
+        // null IP falls through to Utils.getIpAddress() which returns an IPv4
+        // address — just verify no NPE
+        EndpointReference[] eprs = HTTPTransportUtils.getEPRsForService(
+                configContext, httpTransport, "MyService", null, 8080);
+        assertNotNull(eprs);
+        assertNotNull(eprs[0].getAddress());
+    }
+}

Reply via email to