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