author | xuelei |
Wed, 05 Mar 2014 07:24:34 +0000 | |
changeset 23052 | 241885315119 |
parent 13788 | jdk/test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java@3f38e525f30a |
child 30820 | 0d4717a011d3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
2 |
* Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6216082 |
|
23052
241885315119
8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents:
13788
diff
changeset
|
27 |
* @library .. |
13788 | 28 |
* @build HttpCallback TestHttpsServer ClosedChannelList HttpTransaction TunnelProxy |
10328 | 29 |
* @summary Redirect problem with HttpsURLConnection using a proxy |
30 |
* SunJSSE does not support dynamic system properties, no way to re-use |
|
31 |
* system properties in samevm/agentvm mode. |
|
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
32 |
* @run main/othervm B6216082 |
10328 | 33 |
*/ |
2 | 34 |
|
35 |
import java.io.*; |
|
36 |
import java.net.*; |
|
37 |
import javax.net.ssl.*; |
|
38 |
import java.util.*; |
|
39 |
||
40 |
public class B6216082 { |
|
41 |
static SimpleHttpTransaction httpTrans; |
|
13788 | 42 |
static TestHttpsServer server; |
2 | 43 |
static TunnelProxy proxy; |
44 |
||
45 |
// it seems there's no proxy ever if a url points to 'localhost', |
|
46 |
// even if proxy related properties are set. so we need to bind |
|
47 |
// our simple http proxy and http server to a non-loopback address |
|
48 |
static InetAddress firstNonLoAddress = null; |
|
49 |
||
50 |
public static void main(String[] args) throws Exception { |
|
10328 | 51 |
HostnameVerifier reservedHV = |
52 |
HttpsURLConnection.getDefaultHostnameVerifier(); |
|
53 |
try { |
|
54 |
// XXX workaround for CNFE |
|
55 |
Class.forName("java.nio.channels.ClosedByInterruptException"); |
|
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
56 |
if (!setupEnv()) { |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
57 |
return; |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
58 |
} |
2 | 59 |
|
10328 | 60 |
startHttpServer(); |
2 | 61 |
|
10328 | 62 |
// https.proxyPort can only be set after the TunnelProxy has been |
63 |
// created as it will use an ephemeral port. |
|
64 |
System.setProperty("https.proxyPort", |
|
65 |
(new Integer(proxy.getLocalPort())).toString() ); |
|
2 | 66 |
|
10328 | 67 |
makeHttpCall(); |
2 | 68 |
|
10328 | 69 |
if (httpTrans.hasBadRequest) { |
70 |
throw new RuntimeException("Test failed : bad http request"); |
|
71 |
} |
|
72 |
} finally { |
|
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
73 |
if (proxy != null) { |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
74 |
proxy.terminate(); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
75 |
} |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
76 |
if (server != null) { |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
77 |
server.terminate(); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
78 |
} |
10328 | 79 |
HttpsURLConnection.setDefaultHostnameVerifier(reservedHV); |
2 | 80 |
} |
81 |
} |
|
82 |
||
83 |
/* |
|
84 |
* Where do we find the keystores for ssl? |
|
85 |
*/ |
|
23052
241885315119
8032473: Restructure JSSE regression test hierarchy in jdk test
xuelei
parents:
13788
diff
changeset
|
86 |
static String pathToStores = "../../../../../../javax/net/ssl/etc"; |
2 | 87 |
static String keyStoreFile = "keystore"; |
88 |
static String trustStoreFile = "truststore"; |
|
89 |
static String passwd = "passphrase"; |
|
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
90 |
public static boolean setupEnv() throws Exception { |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
91 |
firstNonLoAddress = getNonLoAddress(); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
92 |
if (firstNonLoAddress == null) { |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
93 |
System.err.println("The test needs at least one non-loopback address to run. Quit now."); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
94 |
return false; |
2 | 95 |
} |
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
96 |
System.out.println(firstNonLoAddress.getHostAddress()); |
2 | 97 |
// will use proxy |
98 |
System.setProperty( "https.proxyHost", firstNonLoAddress.getHostAddress()); |
|
99 |
||
100 |
// setup properties to do ssl |
|
101 |
String keyFilename = System.getProperty("test.src", "./") + "/" + |
|
102 |
pathToStores + "/" + keyStoreFile; |
|
103 |
String trustFilename = System.getProperty("test.src", "./") + "/" + |
|
104 |
pathToStores + "/" + trustStoreFile; |
|
105 |
||
106 |
System.setProperty("javax.net.ssl.keyStore", keyFilename); |
|
107 |
System.setProperty("javax.net.ssl.keyStorePassword", passwd); |
|
108 |
System.setProperty("javax.net.ssl.trustStore", trustFilename); |
|
109 |
System.setProperty("javax.net.ssl.trustStorePassword", passwd); |
|
110 |
HttpsURLConnection.setDefaultHostnameVerifier(new NameVerifier()); |
|
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
111 |
return true; |
2 | 112 |
} |
113 |
||
114 |
public static InetAddress getNonLoAddress() throws Exception { |
|
115 |
NetworkInterface loNIC = NetworkInterface.getByInetAddress(InetAddress.getByName("localhost")); |
|
116 |
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); |
|
117 |
while (nics.hasMoreElements()) { |
|
118 |
NetworkInterface nic = nics.nextElement(); |
|
119 |
if (!nic.getName().equalsIgnoreCase(loNIC.getName())) { |
|
120 |
Enumeration<InetAddress> addrs = nic.getInetAddresses(); |
|
121 |
while (addrs.hasMoreElements()) { |
|
122 |
InetAddress addr = addrs.nextElement(); |
|
123 |
if (!addr.isLoopbackAddress()) |
|
124 |
return addr; |
|
125 |
} |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
return null; |
|
130 |
} |
|
131 |
||
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
132 |
public static void startHttpServer() throws IOException { |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
133 |
// Both the https server and the proxy let the |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
134 |
// system pick up an ephemeral port. |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
135 |
httpTrans = new SimpleHttpTransaction(); |
13788 | 136 |
server = new TestHttpsServer(httpTrans, 1, 10, 0); |
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
137 |
proxy = new TunnelProxy(1, 10, 0); |
2 | 138 |
} |
139 |
||
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
140 |
public static void makeHttpCall() throws Exception { |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
141 |
System.out.println("https server listen on: " + server.getLocalPort()); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
142 |
System.out.println("https proxy listen on: " + proxy.getLocalPort()); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
143 |
URL url = new URL("https" , firstNonLoAddress.getHostAddress(), |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
144 |
server.getLocalPort(), "/"); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
145 |
HttpURLConnection uc = (HttpURLConnection)url.openConnection(); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
146 |
System.out.println(uc.getResponseCode()); |
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
147 |
uc.disconnect(); |
2 | 148 |
} |
149 |
||
150 |
static class NameVerifier implements HostnameVerifier { |
|
151 |
public boolean verify(String hostname, SSLSession session) { |
|
152 |
return true; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
class SimpleHttpTransaction implements HttpCallback { |
|
158 |
public boolean hasBadRequest = false; |
|
159 |
||
160 |
/* |
|
161 |
* Our http server which simply redirect first call |
|
162 |
*/ |
|
163 |
public void request(HttpTransaction trans) { |
|
164 |
try { |
|
165 |
String path = trans.getRequestURI().getPath(); |
|
166 |
if (path.equals("/")) { |
|
167 |
// the first call, redirect it |
|
168 |
String location = "/redirect"; |
|
169 |
trans.addResponseHeader("Location", location); |
|
170 |
trans.sendResponse(302, "Moved Temporarily"); |
|
171 |
} else { |
|
172 |
// if the bug exsits, it'll send 2 GET commands |
|
173 |
// check 2nd GET here |
|
174 |
String duplicatedGet = trans.getRequestHeader(null); |
|
175 |
if (duplicatedGet != null && |
|
176 |
duplicatedGet.toUpperCase().indexOf("GET") >= 0) { |
|
177 |
trans.sendResponse(400, "Bad Request"); |
|
178 |
hasBadRequest = true; |
|
179 |
} else { |
|
180 |
trans.sendResponse(200, "OK"); |
|
181 |
} |
|
182 |
} |
|
183 |
} catch (Exception e) { |
|
13669
0f1340f8a157
7195733: TEST_BUG: sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/B6216082.java failing
xuelei
parents:
10328
diff
changeset
|
184 |
throw new RuntimeException(e); |
2 | 185 |
} |
186 |
} |
|
187 |
} |