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.util.WebConnectionWrapper;
27 import org.junit.jupiter.api.Assertions;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33
34
35
36 public class HttpWebConnectionInsecureSSLTest extends WebServerTestCase {
37
38
39
40
41 @Test
42 public void normal() throws Exception {
43 final URL https = new URL("https://localhost:" + PORT2 + "/");
44 Assertions.assertThrows(SSLHandshakeException.class,
45 () -> loadPage("<div>test</div>", https));
46 }
47
48
49
50
51 @Test
52 public void insecureSSL() throws Exception {
53 final WebClient webClient = getWebClient();
54 webClient.getOptions().setUseInsecureSSL(true);
55
56 final URL https = new URL("https://localhost:" + PORT2 + "/");
57 loadPage("<div>test</div>", https);
58 }
59
60
61
62
63 @Test
64 public void insecureSSL_withWrapper() throws Exception {
65 final WebClient webClient = getWebClient();
66 webClient.setWebConnection(new WebConnectionWrapper(webClient.getWebConnection()));
67 webClient.getOptions().setUseInsecureSSL(true);
68
69 final URL https = new URL("https://localhost:" + PORT2 + "/");
70 loadPage("<div>test</div>", https);
71 }
72
73 @Override
74 protected boolean isHttps() {
75 return true;
76 }
77
78 @Override
79 public SslConnectionFactory getSslConnectionFactory() {
80 final URL url = HttpWebConnectionInsecureSSLWithClientCertificateTest.class
81 .getClassLoader().getResource("insecureSSL.pfx");
82
83 final SslContextFactory contextFactory = new Server.Server();
84 contextFactory.setKeyStorePath(url.toExternalForm());
85 contextFactory.setKeyStorePassword("nopassword");
86 return new SslConnectionFactory(contextFactory, HTTP_1_1.toString());
87 }
88 }