From c4e13c81bd92f6e81ec13a7d89bc25a89bd0adb7 Mon Sep 17 00:00:00 2001 From: Ryan Schmitt Date: Fri, 8 Aug 2025 10:03:01 -0700 Subject: [PATCH] Fix hostname verification tests I noticed after a macOS upgrade that these tests were failing, evidently due to some sort of firewall behavior. Looking at the problem, it seems like these tests actually intend to call `getLoopbackAddress`, rather than `getLocalHost`, which returns the IP address and hostname of the local host _on the network_, rather than on the loopback. --- .../hc/core5/testing/classic/ClassicTLSIntegrationTest.java | 4 ++-- .../org/apache/hc/core5/testing/nio/TLSIntegrationTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java index 6daf50295..f47c83d5c 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/classic/ClassicTLSIntegrationTest.java @@ -317,7 +317,7 @@ void testHostNameVerification() throws Exception { .create(); final HttpCoreContext context = HttpCoreContext.create(); - final HttpHost target1 = new HttpHost("https", InetAddress.getLocalHost(), "localhost", server.getLocalPort()); + final HttpHost target1 = new HttpHost("https", InetAddress.getLoopbackAddress(), "localhost", server.getLocalPort()); final ClassicHttpRequest request1 = new BasicClassicHttpRequest(Method.POST, "/stuff"); request1.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response1 = requester.execute(target1, request1, TIMEOUT, context)) { @@ -325,7 +325,7 @@ void testHostNameVerification() throws Exception { } Assertions.assertThrows(SSLHandshakeException.class, () -> { - final HttpHost target2 = new HttpHost("https", InetAddress.getLocalHost(), "some-other-host", server.getLocalPort()); + final HttpHost target2 = new HttpHost("https", InetAddress.getLoopbackAddress(), "some-other-host", server.getLocalPort()); final ClassicHttpRequest request2 = new BasicClassicHttpRequest(Method.POST, "/stuff"); request2.setEntity(new StringEntity("some stuff", ContentType.TEXT_PLAIN)); try (final ClassicHttpResponse response2 = requester.execute(target2, request2, TIMEOUT, context)) { diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java index e84581832..138baf6c6 100644 --- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java +++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TLSIntegrationTest.java @@ -370,7 +370,7 @@ void testHostNameVerification() throws Exception { final ListenerEndpoint listener = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit()); final InetSocketAddress address = (InetSocketAddress) listener.getAddress(); - final HttpHost target1 = new HttpHost(URIScheme.HTTPS.id, InetAddress.getLocalHost(), "localhost", address.getPort()); + final HttpHost target1 = new HttpHost(URIScheme.HTTPS.id, InetAddress.getLoopbackAddress(), "localhost", address.getPort()); final Future> resultFuture1 = client.execute( target1, new BasicRequestProducer(Method.POST, target1, "/stuff", @@ -380,7 +380,7 @@ void testHostNameVerification() throws Exception { Assertions.assertNotNull(message1); Assertions.assertEquals(200, message1.getHead().getCode()); - final HttpHost target2 = new HttpHost(URIScheme.HTTPS.id, InetAddress.getLocalHost(), "some-other-host", address.getPort()); + final HttpHost target2 = new HttpHost(URIScheme.HTTPS.id, InetAddress.getLoopbackAddress(), "some-other-host", address.getPort()); final Future> resultFuture2 = client.execute( target2, new BasicRequestProducer(Method.POST, target2, "/stuff",