author | amurillo |
Wed, 15 Aug 2012 16:49:38 -0700 | |
changeset 13465 | d3fc5d192448 |
parent 8160 | 4257e268578e |
child 16737 | 8f36190e097a |
permissions | -rw-r--r-- |
7982 | 1 |
/* |
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
26 |
* @bug 6964547 |
|
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; |
|
37 |
||
38 |
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
|
39 |
final ServerSocket ss; |
7982 | 40 |
volatile boolean failed; |
41 |
||
42 |
public static void main(String[] args) throws Exception { |
|
43 |
new SocksProxyVersion(); |
|
44 |
} |
|
45 |
||
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
46 |
@SuppressWarnings("try") |
7982 | 47 |
public SocksProxyVersion() throws Exception { |
48 |
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
|
49 |
try (ServerSocket socket = ss) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
50 |
runTest(); |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
51 |
} |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
52 |
} |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
53 |
|
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
54 |
void runTest() throws Exception { |
7982 | 55 |
int port = ss.getLocalPort(); |
56 |
Thread serverThread = new Thread(this); |
|
57 |
serverThread.start(); |
|
58 |
||
59 |
System.setProperty("socksProxyHost", "localhost"); |
|
60 |
System.setProperty("socksProxyPort", Integer.toString(port)); |
|
61 |
||
62 |
// SOCKS V4 |
|
63 |
System.setProperty("socksProxyVersion", Integer.toString(4)); |
|
64 |
try (Socket s = new Socket()) { |
|
65 |
s.connect(new InetSocketAddress("localhost", port)); |
|
66 |
} catch (SocketException e) { |
|
67 |
// java.net.SocketException: Malformed reply from SOCKS server |
|
68 |
// This exception is OK, since the "server" does not implement |
|
69 |
// the socks protocol. It just verifies the version and closes. |
|
70 |
} |
|
71 |
||
72 |
// SOCKS V5 |
|
73 |
System.setProperty("socksProxyVersion", Integer.toString(5)); |
|
74 |
try (Socket s = new Socket()) { |
|
75 |
s.connect(new InetSocketAddress("localhost", port)); |
|
76 |
} catch (SocketException e) { /* OK */ } |
|
77 |
||
78 |
serverThread.join(); |
|
79 |
if (failed) { |
|
80 |
throw new RuntimeException("socksProxyVersion not being set correctly"); |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
public void run() { |
|
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
85 |
try { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
if (version != 4) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
89 |
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
|
90 |
failed = true; |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
91 |
} |
7982 | 92 |
} |
8160
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
if (version != 5) { |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
96 |
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
|
97 |
failed = true; |
4257e268578e
7015410: test/java/net/Socks/SocksProxyVersion.java needs to be updated due to 7013420
alanb
parents:
7982
diff
changeset
|
98 |
} |
7982 | 99 |
} |
100 |
} catch (IOException e) { |
|
101 |
e.printStackTrace(); |
|
102 |
} |
|
103 |
} |
|
104 |
} |