2016-05-23 11:38:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 8157105
|
2016-12-09 11:35:02 +00:00
|
|
|
* @library /lib/testlibrary server
|
2016-05-31 00:49:04 +00:00
|
|
|
* @key intermittent
|
2016-05-23 11:38:48 +00:00
|
|
|
* @build jdk.testlibrary.SimpleSSLContext
|
2016-12-09 11:35:02 +00:00
|
|
|
* @modules jdk.incubator.httpclient/jdk.incubator.http.internal.common
|
|
|
|
* jdk.incubator.httpclient/jdk.incubator.http.internal.frame
|
|
|
|
* jdk.incubator.httpclient/jdk.incubator.http.internal.hpack
|
2016-10-03 15:33:34 +00:00
|
|
|
* java.security.jgss
|
2016-12-09 11:35:02 +00:00
|
|
|
* @run testng/othervm -Djdk.httpclient.HttpClient.log=ssl,errors ErrorTest
|
2016-05-23 11:38:48 +00:00
|
|
|
* @summary check exception thrown when bad TLS parameters selected
|
|
|
|
*/
|
|
|
|
|
2016-10-03 15:33:34 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URI;
|
2016-12-09 11:35:02 +00:00
|
|
|
import jdk.incubator.http.HttpClient;
|
|
|
|
import jdk.incubator.http.HttpRequest;
|
|
|
|
import jdk.incubator.http.HttpResponse;
|
2016-10-03 15:33:34 +00:00
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
|
import javax.net.ssl.SSLParameters;
|
2016-12-09 11:35:02 +00:00
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.ExecutorService;
|
2016-05-23 11:38:48 +00:00
|
|
|
import jdk.testlibrary.SimpleSSLContext;
|
2016-12-09 11:35:02 +00:00
|
|
|
import static jdk.incubator.http.HttpClient.Version.HTTP_2;
|
|
|
|
import static jdk.incubator.http.HttpRequest.BodyProcessor.fromString;
|
|
|
|
import static jdk.incubator.http.HttpResponse.BodyHandler.discard;
|
2016-05-23 11:38:48 +00:00
|
|
|
|
|
|
|
import org.testng.annotations.Test;
|
2016-10-03 15:33:34 +00:00
|
|
|
|
2016-05-23 11:38:48 +00:00
|
|
|
/**
|
|
|
|
* When selecting an unacceptable cipher suite the TLS handshake will fail.
|
|
|
|
* But, the exception that was thrown was not being returned up to application
|
|
|
|
* causing hang problems
|
|
|
|
*/
|
|
|
|
public class ErrorTest {
|
|
|
|
|
2016-12-09 11:35:02 +00:00
|
|
|
static final String[] CIPHER_SUITES = new String[]{ "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" };
|
2016-05-23 11:38:48 +00:00
|
|
|
|
|
|
|
static final String SIMPLE_STRING = "Hello world Goodbye world";
|
|
|
|
|
2016-12-09 11:35:02 +00:00
|
|
|
//@Test(timeOut=5000)
|
|
|
|
@Test
|
|
|
|
public void test() throws Exception {
|
|
|
|
SSLContext sslContext = (new SimpleSSLContext()).get();
|
|
|
|
ExecutorService exec = Executors.newCachedThreadPool();
|
|
|
|
HttpClient client = HttpClient.newBuilder()
|
|
|
|
.executor(exec)
|
|
|
|
.sslContext(sslContext)
|
|
|
|
.sslParameters(new SSLParameters(CIPHER_SUITES))
|
|
|
|
.version(HTTP_2)
|
|
|
|
.build();
|
2016-05-23 11:38:48 +00:00
|
|
|
|
2016-12-09 11:35:02 +00:00
|
|
|
Http2TestServer httpsServer = null;
|
|
|
|
try {
|
|
|
|
httpsServer = new Http2TestServer(true,
|
|
|
|
0,
|
|
|
|
exec,
|
|
|
|
sslContext);
|
|
|
|
httpsServer.addHandler(new EchoHandler(), "/");
|
|
|
|
int httpsPort = httpsServer.getAddress().getPort();
|
|
|
|
String httpsURIString = "https://127.0.0.1:" + httpsPort + "/bar/";
|
2016-05-23 11:38:48 +00:00
|
|
|
|
|
|
|
httpsServer.start();
|
2016-12-09 11:35:02 +00:00
|
|
|
URI uri = URI.create(httpsURIString);
|
2016-05-23 11:38:48 +00:00
|
|
|
System.err.println("Request to " + uri);
|
|
|
|
|
2016-12-09 11:35:02 +00:00
|
|
|
HttpRequest req = HttpRequest.newBuilder(uri)
|
|
|
|
.POST(fromString(SIMPLE_STRING))
|
|
|
|
.build();
|
|
|
|
HttpResponse response;
|
2016-05-23 11:38:48 +00:00
|
|
|
try {
|
2016-12-09 11:35:02 +00:00
|
|
|
response = client.send(req, discard(null));
|
|
|
|
throw new RuntimeException("Unexpected response: " + response);
|
2016-05-23 11:38:48 +00:00
|
|
|
} catch (IOException e) {
|
2016-12-09 11:35:02 +00:00
|
|
|
System.err.println("Caught Expected IOException: " + e);
|
2016-05-23 11:38:48 +00:00
|
|
|
}
|
|
|
|
System.err.println("DONE");
|
|
|
|
} finally {
|
2016-12-09 11:35:02 +00:00
|
|
|
if (httpsServer != null ) { httpsServer.stop(); }
|
2016-05-23 11:38:48 +00:00
|
|
|
exec.shutdownNow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|