1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit;
16
17 import static org.eclipse.jetty.http.HttpVersion.HTTP_1_1;
18
19 import java.net.URL;
20
21 import javax.net.ssl.SSLHandshakeException;
22
23 import org.eclipse.jetty.server.SslConnectionFactory;
24 import org.eclipse.jetty.util.ssl.SslContextFactory;
25 import org.eclipse.jetty.util.ssl.SslContextFactory.Server;
26 import org.htmlunit.junit.BrowserRunner;
27 import org.htmlunit.util.WebConnectionWrapper;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30
31
32
33
34
35
36
37 @RunWith(BrowserRunner.class)
38 public class HttpWebConnectionInsecureSSLTest extends WebServerTestCase {
39
40
41
42
43 @Test(expected = SSLHandshakeException.class)
44 public void normal() throws Exception {
45 final URL https = new URL("https://localhost:" + PORT2 + "/");
46 loadPage("<div>test</div>", https);
47 }
48
49
50
51
52 @Test
53 public void insecureSSL() throws Exception {
54 final WebClient webClient = getWebClient();
55 webClient.getOptions().setUseInsecureSSL(true);
56
57 final URL https = new URL("https://localhost:" + PORT2 + "/");
58 loadPage("<div>test</div>", https);
59 }
60
61
62
63
64 @Test
65 public void insecureSSL_withWrapper() throws Exception {
66 final WebClient webClient = getWebClient();
67 webClient.setWebConnection(new WebConnectionWrapper(webClient.getWebConnection()));
68 webClient.getOptions().setUseInsecureSSL(true);
69
70 final URL https = new URL("https://localhost:" + PORT2 + "/");
71 loadPage("<div>test</div>", https);
72 }
73
74 @Override
75 protected boolean isHttps() {
76 return true;
77 }
78
79 @Override
80 public SslConnectionFactory getSslConnectionFactory() {
81 final URL url = HttpWebConnectionInsecureSSLWithClientCertificateTest.class
82 .getClassLoader().getResource("insecureSSL.pfx");
83
84 final SslContextFactory contextFactory = new Server.Server();
85 contextFactory.setKeyStorePath(url.toExternalForm());
86 contextFactory.setKeyStorePassword("nopassword");
87 return new SslConnectionFactory(contextFactory, HTTP_1_1.toString());
88 }
89 }