Skip to content

Commit

Permalink
8224081: SOCKS v4 tests require IPv4
Browse files Browse the repository at this point in the history
Backport-of: acad8d1
  • Loading branch information
Amos Shi committed Aug 26, 2024
1 parent d3ce405 commit 9ba9dd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 10 additions & 6 deletions test/jdk/java/net/Socks/SocksProxyVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/*
* @test
* @bug 6964547 5001942 8129444
* @library /test/lib
* @run main/othervm SocksProxyVersion
* @summary test socksProxyVersion system property
*/
Expand All @@ -35,6 +36,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.Proxy;
import jdk.test.lib.net.IPSupport;

public class SocksProxyVersion implements Runnable {
final ServerSocket ss;
Expand Down Expand Up @@ -80,14 +82,16 @@ final void runTest(int port) throws Exception {
Proxy proxy = new Proxy(Proxy.Type.SOCKS,
new InetSocketAddress(addr, port));

// SOCKS V4
System.setProperty("socksProxyVersion", Integer.toString(4));
this.expected = 4;
check(new Socket(), addr, port);
check(new Socket(proxy), addr, port);
if (IPSupport.hasIPv4()) {
// SOCKS V4 (requires IPv4)
System.setProperty("socksProxyVersion", "4");
this.expected = 4;
check(new Socket(), addr, port);
check(new Socket(proxy), addr, port);
}

// SOCKS V5
System.setProperty("socksProxyVersion", Integer.toString(5));
System.setProperty("socksProxyVersion", "5");
this.expected = 5;
check(new Socket(), addr, port);
check(new Socket(proxy), addr, port);
Expand Down
8 changes: 5 additions & 3 deletions test/jdk/sun/security/x509/URICertStore/SocksProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Objects;
Expand All @@ -30,7 +31,7 @@
import javax.net.ServerSocketFactory;

/*
* A simple socks4 proxy for traveling socket.
* A simple socks proxy for traveling socket.
*/
class SocksProxy implements Runnable, AutoCloseable {

Expand All @@ -49,10 +50,11 @@ static SocksProxy startProxy(Consumer<Socket> socketConsumer)
ServerSocket server
= ServerSocketFactory.getDefault().createServerSocket(0);

System.setProperty("socksProxyHost", "127.0.0.1");
System.setProperty("socksProxyHost",
InetAddress.getLoopbackAddress().getHostAddress());
System.setProperty("socksProxyPort",
String.valueOf(server.getLocalPort()));
System.setProperty("socksProxyVersion", "4");
System.setProperty("socksProxyVersion", "5");

SocksProxy proxy = new SocksProxy(server, socketConsumer);
Thread proxyThread = new Thread(proxy, "Proxy");
Expand Down

1 comment on commit 9ba9dd2

@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.