author | rriggs |
Thu, 24 Jan 2019 14:39:16 -0500 | |
changeset 53478 | 0716631b907f |
parent 47216 | 71c04702a3d5 |
child 54634 | 59c01214e478 |
permissions | -rw-r--r-- |
22276
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
1 |
/* |
38883 | 2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
22276
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
4 |
* |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
8 |
* |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
14 |
* |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
18 |
* |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
21 |
* questions. |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
22 |
*/ |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
23 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
24 |
/* @test |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
25 |
* @bug 7100957 |
38883 | 26 |
* @modules jdk.httpserver |
22276
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
27 |
* @summary Java doesn't correctly handle the SOCKS protocol when used over IPv6. |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
28 |
* @run testng SocksIPv6Test |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
29 |
*/ |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
30 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
31 |
import java.io.BufferedReader; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
32 |
import java.io.IOException; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
33 |
import java.io.InputStream; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
34 |
import java.io.InputStreamReader; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
35 |
import java.io.OutputStreamWriter; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
36 |
import java.net.Authenticator; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
37 |
import java.net.InetSocketAddress; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
38 |
import java.net.URL; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
39 |
import java.net.Proxy; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
40 |
import java.lang.Override; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
41 |
import java.net.InetAddress; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
42 |
import java.net.Inet6Address; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
43 |
import java.net.ServerSocket; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
44 |
import java.net.SocketException; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
45 |
import java.net.NetworkInterface; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
46 |
import java.net.UnknownHostException; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
47 |
import java.util.Collections; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
48 |
import java.util.List; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
49 |
import com.sun.net.httpserver.*; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
50 |
import java.io.BufferedWriter; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
51 |
import org.testng.annotations.AfterClass; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
52 |
import org.testng.annotations.BeforeClass; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
53 |
import org.testng.annotations.Test; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
54 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
55 |
import static org.testng.Assert.*; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
56 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
57 |
public class SocksIPv6Test { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
58 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
59 |
private HttpServer server; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
60 |
private SocksServer socks; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
61 |
private String response = "Hello."; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
62 |
private static boolean shouldRun = false; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
63 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
64 |
@BeforeClass |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
65 |
public void setUp() throws Exception { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
66 |
shouldRun = ensureInet6AddressFamily() && ensureIPv6OnLoopback(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
67 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
68 |
server = HttpServer.create(new InetSocketAddress(0), 0); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
69 |
server.createContext("/", ex -> { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
70 |
ex.sendResponseHeaders(200, response.length()); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
71 |
try (BufferedWriter writer = new BufferedWriter( |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
72 |
new OutputStreamWriter(ex.getResponseBody(), "UTF-8"))) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
73 |
writer.write(response); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
74 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
75 |
ex.close(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
76 |
}); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
77 |
server.start(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
78 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
79 |
socks = new SocksServer(0, false); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
80 |
socks.addUser("user", "pass"); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
81 |
socks.start(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
82 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
83 |
Authenticator.setDefault(new Authenticator() { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
84 |
@Override |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
85 |
protected java.net.PasswordAuthentication getPasswordAuthentication() { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
86 |
return new java.net.PasswordAuthentication( |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
87 |
"user", "pass".toCharArray()); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
88 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
89 |
}); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
90 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
91 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
92 |
private boolean ensureIPv6OnLoopback() throws Exception { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
93 |
boolean ipv6 = false; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
94 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
95 |
List<NetworkInterface> nics = Collections.list(NetworkInterface.getNetworkInterfaces()); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
96 |
for (NetworkInterface nic : nics) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
97 |
if (!nic.isLoopback()) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
98 |
continue; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
99 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
100 |
List<InetAddress> addrs = Collections.list(nic.getInetAddresses()); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
101 |
for (InetAddress addr : addrs) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
102 |
if (addr instanceof Inet6Address) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
103 |
ipv6 = true; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
104 |
break; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
105 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
106 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
107 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
108 |
if (!ipv6) |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
109 |
System.out.println("IPv6 is not enabled on loopback. Skipping test suite."); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
110 |
return ipv6; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
111 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
112 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
113 |
private boolean ensureInet6AddressFamily() throws IOException { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
114 |
try (ServerSocket s = new ServerSocket()) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
115 |
s.bind(new InetSocketAddress("::1", 0)); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
116 |
return true; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
117 |
} catch (SocketException e) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
118 |
System.out.println("Inet 6 address family is not available. Skipping test suite."); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
119 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
120 |
return false; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
121 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
122 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
123 |
@Test(groups = "unit") |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
124 |
public void testSocksOverIPv6() throws Exception { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
125 |
if (!shouldRun) return; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
126 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
127 |
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("::1", |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
128 |
socks.getPort())); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
129 |
URL url = new URL("http://[::1]:" + server.getAddress().getPort()); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
130 |
java.net.URLConnection conn = url.openConnection(proxy); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
131 |
String actual = ""; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
132 |
try (BufferedReader reader = new BufferedReader( |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
133 |
new InputStreamReader(conn.getInputStream()))) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
134 |
actual = reader.readLine(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
135 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
136 |
assertEquals(actual, response); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
137 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
138 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
139 |
@Test(groups = "unit") |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
140 |
public void testSocksOverIPv6Hostname() throws Exception { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
141 |
if (!shouldRun) return; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
142 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
143 |
String ipv6Hostname = InetAddress.getByName("::1").getHostName(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
144 |
String ipv4Hostname = InetAddress.getByName("127.0.0.1").getHostName(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
145 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
146 |
if (ipv6Hostname.equals(InetAddress.getByName("::1").getHostAddress())) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
147 |
System.out.println("Unable to get the hostname of the IPv6 loopback " |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
148 |
+ "address. Skipping test case."); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
149 |
return; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
150 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
151 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
152 |
if (ipv6Hostname.equals(ipv4Hostname)) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
153 |
System.out.println("IPv6 and IPv4 loopback addresses map to the" |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
154 |
+ " same hostname. Skipping test case."); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
155 |
return; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
156 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
157 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
158 |
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(ipv6Hostname, |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
159 |
socks.getPort())); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
160 |
URL url = new URL("http://" + ipv6Hostname + ":" + server.getAddress().getPort()); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
161 |
java.net.URLConnection conn = url.openConnection(proxy); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
162 |
String actual = ""; |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
163 |
try (BufferedReader reader = new BufferedReader( |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
164 |
new InputStreamReader(conn.getInputStream()))) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
165 |
actual = reader.readLine(); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
166 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
167 |
assertEquals(actual, response); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
168 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
169 |
|
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
170 |
@AfterClass |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
171 |
public void tearDown() { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
172 |
if (server != null) { |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
173 |
server.stop(1); |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
174 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
175 |
if (socks != null) { |
53478 | 176 |
socks.close(); |
22276
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
177 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
178 |
} |
7fc4c8b08e49
7100957: SOCKS proxying does not work with IPv6 connections
chegar
parents:
diff
changeset
|
179 |
} |