author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 20783 | c0806cb8d4ae |
child 31529 | 31d7d82b39ff |
permissions | -rw-r--r-- |
7982 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20783
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
7982 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
16737
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
26 |
* @bug 6964547 5001942 |
7982 | 27 |
* @run main/othervm SocksProxyVersion |
28 |
* @summary test socksProxyVersion system property |
|
29 |
*/ |
|
30 |
||
31 |
import java.net.InetSocketAddress; |
|
32 |
import java.net.ServerSocket; |
|
33 |
import java.net.Socket; |
|
34 |
import java.net.SocketException; |
|
35 |
import java.io.DataInputStream; |
|
36 |
import java.io.IOException; |
|
16737
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
37 |
import java.net.InetAddress; |
7982 | 38 |
|
39 |
public class SocksProxyVersion implements Runnable { |
|
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
40 |
final ServerSocket ss; |
7982 | 41 |
volatile boolean failed; |
42 |
||
43 |
public static void main(String[] args) throws Exception { |
|
20783
c0806cb8d4ae
8023555: test/java/net/Socks/SocksProxyVersion.java fails when machine name is localhost
tyan
parents:
16737
diff
changeset
|
44 |
if (InetAddress.getLocalHost().isLoopbackAddress()) { |
c0806cb8d4ae
8023555: test/java/net/Socks/SocksProxyVersion.java fails when machine name is localhost
tyan
parents:
16737
diff
changeset
|
45 |
System.out.println("Test cannot run. getLocalHost returns a loopback address"); |
c0806cb8d4ae
8023555: test/java/net/Socks/SocksProxyVersion.java fails when machine name is localhost
tyan
parents:
16737
diff
changeset
|
46 |
return; |
c0806cb8d4ae
8023555: test/java/net/Socks/SocksProxyVersion.java fails when machine name is localhost
tyan
parents:
16737
diff
changeset
|
47 |
} |
7982 | 48 |
new SocksProxyVersion(); |
49 |
} |
|
50 |
||
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
51 |
@SuppressWarnings("try") |
7982 | 52 |
public SocksProxyVersion() throws Exception { |
53 |
ss = new ServerSocket(0); |
|
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
54 |
try (ServerSocket socket = ss) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
55 |
runTest(); |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
56 |
} |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
57 |
} |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
58 |
|
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
59 |
void runTest() throws Exception { |
7982 | 60 |
int port = ss.getLocalPort(); |
61 |
Thread serverThread = new Thread(this); |
|
62 |
serverThread.start(); |
|
63 |
||
16737
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
64 |
/* |
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
65 |
* Retreving the IP Address of the machine |
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
66 |
* since "localhost" is bypassed as a non-proxy host |
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
67 |
*/ |
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
68 |
String addr = InetAddress.getLocalHost().getHostAddress(); |
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
69 |
|
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
70 |
System.setProperty("socksProxyHost", addr); |
7982 | 71 |
System.setProperty("socksProxyPort", Integer.toString(port)); |
72 |
||
73 |
// SOCKS V4 |
|
74 |
System.setProperty("socksProxyVersion", Integer.toString(4)); |
|
75 |
try (Socket s = new Socket()) { |
|
16737
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
76 |
s.connect(new InetSocketAddress(addr, port)); |
7982 | 77 |
} catch (SocketException e) { |
78 |
// java.net.SocketException: Malformed reply from SOCKS server |
|
79 |
// This exception is OK, since the "server" does not implement |
|
80 |
// the socks protocol. It just verifies the version and closes. |
|
81 |
} |
|
82 |
||
83 |
// SOCKS V5 |
|
84 |
System.setProperty("socksProxyVersion", Integer.toString(5)); |
|
85 |
try (Socket s = new Socket()) { |
|
16737
8f36190e097a
5001942: Missings SOCKS support for direct connections
khazra
parents:
8160
diff
changeset
|
86 |
s.connect(new InetSocketAddress(addr, port)); |
7982 | 87 |
} catch (SocketException e) { /* OK */ } |
88 |
||
89 |
serverThread.join(); |
|
90 |
if (failed) { |
|
91 |
throw new RuntimeException("socksProxyVersion not being set correctly"); |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
public void run() { |
|
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
96 |
try { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
97 |
try (Socket s = ss.accept()) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
98 |
int version = (s.getInputStream()).read(); |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
99 |
if (version != 4) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
100 |
System.out.println("Got " + version + ", expected 4"); |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
101 |
failed = true; |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
102 |
} |
7982 | 103 |
} |
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
104 |
try (Socket s = ss.accept()) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
105 |
int version = (s.getInputStream()).read(); |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
106 |
if (version != 5) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
107 |
System.out.println("Got " + version + ", expected 5"); |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
108 |
failed = true; |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
109 |
} |
7982 | 110 |
} |
111 |
} catch (IOException e) { |
|
112 |
e.printStackTrace(); |
|
113 |
} |
|
114 |
} |
|
115 |
} |