author | jjg |
Wed, 04 Jan 2017 18:33:20 -0800 | |
changeset 43029 | 1cd1c816581e |
parent 42460 | 7133f144981a |
child 44854 | 5a486e0acd29 |
permissions | -rw-r--r-- |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
1 |
/* |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
4 |
* |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
8 |
* |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
14 |
* |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
18 |
* |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
21 |
* questions. |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
22 |
*/ |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
23 |
|
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
24 |
/* |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
25 |
* @test |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
26 |
* @bug 8157105 |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
27 |
* @library /lib/testlibrary server |
38745
be430178b177
8157816: Mark 4 httpclient tests as intermittently failing
xiaofeya
parents:
38464
diff
changeset
|
28 |
* @key intermittent |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
29 |
* @build jdk.testlibrary.SimpleSSLContext |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
30 |
* @modules jdk.incubator.httpclient/jdk.incubator.http.internal.common |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
31 |
* jdk.incubator.httpclient/jdk.incubator.http.internal.frame |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
32 |
* jdk.incubator.httpclient/jdk.incubator.http.internal.hpack |
41355
f80c213ae8ff
8166791: Fix module dependencies for networking component tests
skovalev
parents:
38745
diff
changeset
|
33 |
* java.security.jgss |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
34 |
* @run testng/othervm -Djdk.httpclient.HttpClient.log=ssl,errors ErrorTest |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
35 |
* @summary check exception thrown when bad TLS parameters selected |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
36 |
*/ |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
37 |
|
41355
f80c213ae8ff
8166791: Fix module dependencies for networking component tests
skovalev
parents:
38745
diff
changeset
|
38 |
import java.io.IOException; |
f80c213ae8ff
8166791: Fix module dependencies for networking component tests
skovalev
parents:
38745
diff
changeset
|
39 |
import java.net.URI; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
40 |
import jdk.incubator.http.HttpClient; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
41 |
import jdk.incubator.http.HttpRequest; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
42 |
import jdk.incubator.http.HttpResponse; |
41355
f80c213ae8ff
8166791: Fix module dependencies for networking component tests
skovalev
parents:
38745
diff
changeset
|
43 |
import javax.net.ssl.SSLContext; |
f80c213ae8ff
8166791: Fix module dependencies for networking component tests
skovalev
parents:
38745
diff
changeset
|
44 |
import javax.net.ssl.SSLParameters; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
45 |
import java.util.concurrent.Executors; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
46 |
import java.util.concurrent.ExecutorService; |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
47 |
import jdk.testlibrary.SimpleSSLContext; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
48 |
import static jdk.incubator.http.HttpClient.Version.HTTP_2; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
49 |
import static jdk.incubator.http.HttpRequest.BodyProcessor.fromString; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
50 |
import static jdk.incubator.http.HttpResponse.BodyHandler.discard; |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
51 |
|
41355
f80c213ae8ff
8166791: Fix module dependencies for networking component tests
skovalev
parents:
38745
diff
changeset
|
52 |
import org.testng.annotations.Test; |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
53 |
|
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
54 |
/** |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
55 |
* When selecting an unacceptable cipher suite the TLS handshake will fail. |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
56 |
* But, the exception that was thrown was not being returned up to application |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
57 |
* causing hang problems |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
58 |
*/ |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
59 |
public class ErrorTest { |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
60 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
61 |
static final String[] CIPHER_SUITES = new String[]{ "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" }; |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
62 |
|
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
63 |
static final String SIMPLE_STRING = "Hello world Goodbye world"; |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
64 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
65 |
//@Test(timeOut=5000) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
66 |
@Test |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
67 |
public void test() throws Exception { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
68 |
SSLContext sslContext = (new SimpleSSLContext()).get(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
69 |
ExecutorService exec = Executors.newCachedThreadPool(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
70 |
HttpClient client = HttpClient.newBuilder() |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
71 |
.executor(exec) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
72 |
.sslContext(sslContext) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
73 |
.sslParameters(new SSLParameters(CIPHER_SUITES)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
74 |
.version(HTTP_2) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
75 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
76 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
77 |
Http2TestServer httpsServer = null; |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
78 |
try { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
79 |
httpsServer = new Http2TestServer(true, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
80 |
0, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
81 |
exec, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
82 |
sslContext); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
83 |
httpsServer.addHandler(new EchoHandler(), "/"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
84 |
int httpsPort = httpsServer.getAddress().getPort(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
85 |
String httpsURIString = "https://127.0.0.1:" + httpsPort + "/bar/"; |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
86 |
|
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
87 |
httpsServer.start(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
88 |
URI uri = URI.create(httpsURIString); |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
89 |
System.err.println("Request to " + uri); |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
90 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
91 |
HttpRequest req = HttpRequest.newBuilder(uri) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
92 |
.POST(fromString(SIMPLE_STRING)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
93 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
94 |
HttpResponse response; |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
95 |
try { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
96 |
response = client.send(req, discard(null)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
97 |
throw new RuntimeException("Unexpected response: " + response); |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
98 |
} catch (IOException e) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
99 |
System.err.println("Caught Expected IOException: " + e); |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
100 |
} |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
101 |
System.err.println("DONE"); |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
102 |
} finally { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
41355
diff
changeset
|
103 |
if (httpsServer != null ) { httpsServer.stop(); } |
38464
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
104 |
exec.shutdownNow(); |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
105 |
} |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
106 |
} |
08512546de5f
8157105: HTTP/2 client hangs in blocking mode if an invalid frame has been received
michaelm
parents:
diff
changeset
|
107 |
} |