|
7 | 7 | import java.security.GeneralSecurityException; |
8 | 8 | import java.security.cert.X509Certificate; |
9 | 9 |
|
10 | | -import javax.net.ssl.SSLPeerUnverifiedException; |
| 10 | +import javax.net.ssl.SSLException; |
11 | 11 |
|
12 | 12 | import org.apache.http.HttpResponse; |
13 | 13 | import org.apache.http.client.ClientProtocolException; |
@@ -39,7 +39,7 @@ public class HttpsClientSslLiveTest { |
39 | 39 |
|
40 | 40 | // tests |
41 | 41 |
|
42 | | - @Test(expected = SSLPeerUnverifiedException.class) |
| 42 | + @Test(expected = SSLException.class) |
43 | 43 | public final void whenHttpsUrlIsConsumed_thenException() throws ClientProtocolException, IOException { |
44 | 44 | final CloseableHttpClient httpClient = HttpClientBuilder.create().build(); |
45 | 45 |
|
@@ -71,6 +71,28 @@ public final boolean isTrusted(final X509Certificate[] certificate, final String |
71 | 71 | httpClient.close(); |
72 | 72 | } |
73 | 73 |
|
| 74 | + @Test |
| 75 | + public final void givenHttpClientAfter4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException { |
| 76 | + final TrustStrategy acceptingTrustStrategy = new TrustStrategy() { |
| 77 | + @Override |
| 78 | + public final boolean isTrusted(final X509Certificate[] certificate, final String authType) { |
| 79 | + return true; |
| 80 | + } |
| 81 | + }; |
| 82 | + final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); |
| 83 | + final SchemeRegistry registry = new SchemeRegistry(); |
| 84 | + registry.register(new Scheme("https", 443, sf)); |
| 85 | + final ClientConnectionManager ccm = new PoolingClientConnectionManager(registry); |
| 86 | + |
| 87 | + final CloseableHttpClient httpClient = new DefaultHttpClient(ccm); |
| 88 | + |
| 89 | + final HttpGet getMethod = new HttpGet(HOST_WITH_SSL); |
| 90 | + final HttpResponse response = httpClient.execute(getMethod); |
| 91 | + assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); |
| 92 | + |
| 93 | + httpClient.close(); |
| 94 | + } |
| 95 | + |
74 | 96 | @Test |
75 | 97 | public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException { |
76 | 98 | final SSLContextBuilder builder = new SSLContextBuilder(); |
|
0 commit comments