Skip to content

Commit

Permalink
8229912: [TESTBUG] java/net/Socks/SocksIPv6Test fails without IPv6
Browse files Browse the repository at this point in the history
Reviewed-by: goetz
Backport-of: 8468648
  • Loading branch information
i556354 authored and GoeLin committed Jun 14, 2023
1 parent 0fdd6dd commit 9fe6ade
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/jdk/java/net/Socks/SocksIPv6Test.java
Expand Up @@ -24,6 +24,7 @@
/* @test
* @bug 7100957
* @modules jdk.httpserver
* @library /test/lib
* @summary Java doesn't correctly handle the SOCKS protocol when used over IPv6.
* @run testng SocksIPv6Test
*/
Expand All @@ -46,22 +47,27 @@
import java.util.List;
import com.sun.net.httpserver.*;
import java.io.BufferedWriter;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import jdk.test.lib.NetworkConfiguration;

import static org.testng.Assert.*;

public class SocksIPv6Test {

private HttpServer server;
private SocksServer socks;
private String response = "Hello.";
private static boolean shouldRun = false;

@BeforeClass
public void setUp() throws Exception {
shouldRun = ensureInet6AddressFamily() && ensureIPv6OnLoopback();
if (!ensureInet6AddressFamily() || !ensureIPv6OnLoopback()) {
NetworkConfiguration.printSystemConfiguration(System.out);
throw new SkipException("Host does not support IPv6");
}

server = HttpServer.create(new InetSocketAddress("::1", 0), 0);
server.createContext("/", ex -> {
Expand Down Expand Up @@ -120,8 +126,6 @@ private boolean ensureInet6AddressFamily() throws IOException {

@Test(groups = "unit")
public void testSocksOverIPv6() throws Exception {
if (!shouldRun) return;

Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("::1",
socks.getPort()));
URL url = new URL("http://[::1]:" + server.getAddress().getPort());
Expand All @@ -136,8 +140,6 @@ public void testSocksOverIPv6() throws Exception {

@Test(groups = "unit")
public void testSocksOverIPv6Hostname() throws Exception {
if (!shouldRun) return;

InetAddress ipv6Loopback = InetAddress.getByName("::1");
String ipv6Hostname = ipv6Loopback.getHostName();
String ipv6HostAddress = ipv6Loopback.getHostAddress();
Expand Down

1 comment on commit 9fe6ade

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.