66
77import java .io .IOException ;
88import java .security .GeneralSecurityException ;
9- import java .security .cert .X509Certificate ;
109
1110import javax .net .ssl .SSLContext ;
11+ import javax .net .ssl .SSLPeerUnverifiedException ;
1212
1313import org .apache .http .HttpResponse ;
1414import org .apache .http .client .ClientProtocolException ;
@@ -46,7 +46,7 @@ public class RestClientLiveManualTest {
4646 // old httpClient will throw UnsupportedOperationException
4747 @ Ignore
4848 @ Test
49- public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk_1 () throws GeneralSecurityException {
49+ public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk () throws GeneralSecurityException {
5050 final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory ();
5151 final CloseableHttpClient httpClient = (CloseableHttpClient ) requestFactory .getHttpClient ();
5252
@@ -92,7 +92,7 @@ public final void givenAcceptingAllCertificatesUsing4_4_whenHttpsUrlIsConsumed_t
9292 }
9393
9494 @ Test
95- public final void givenAcceptingAllCertificatesUsing4_4_whenHttpsUrlIsConsumedUsingRestTemplate_thenCorrect () throws ClientProtocolException , IOException {
95+ public final void givenAcceptingAllCertificatesUsing4_4_whenUsingRestTemplate_thenCorrect () throws ClientProtocolException , IOException {
9696 final CloseableHttpClient httpClient = HttpClients .custom ().setSSLHostnameVerifier (new NoopHostnameVerifier ()).build ();
9797 final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory ();
9898 requestFactory .setHttpClient (httpClient );
@@ -101,4 +101,12 @@ public final void givenAcceptingAllCertificatesUsing4_4_whenHttpsUrlIsConsumedUs
101101 assertThat (response .getStatusCode ().value (), equalTo (200 ));
102102 }
103103
104+ @ Test (expected = SSLPeerUnverifiedException .class )
105+ public void whenHttpsUrlIsConsumed_thenException () throws ClientProtocolException , IOException {
106+ CloseableHttpClient httpClient = HttpClients .createDefault ();
107+ String urlOverHttps = "https://localhost:8082/httpclient-simple" ;
108+ HttpGet getMethod = new HttpGet (urlOverHttps );
109+ HttpResponse response = httpClient .execute (getMethod );
110+ assertThat (response .getStatusLine ().getStatusCode (), equalTo (200 ));
111+ }
104112}
0 commit comments