Skip to content

Commit 72279b8

Browse files
author
eugenp
committed
cleanup of httpclient tests
1 parent d8e4f04 commit 72279b8

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎httpclient/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
<mockito.version>1.10.8</mockito.version>
174174

175175
<httpcore.version>4.3.3</httpcore.version>
176-
<httpclient.version>4.3.4</httpclient.version>
176+
<httpclient.version>4.3.6</httpclient.version>
177177

178178
<rest-assured.version>2.4.0</rest-assured.version>
179179

‎httpclient/src/test/java/org/baeldung/httpclient/HttpsClientSslLiveTest.java‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.security.GeneralSecurityException;
88
import java.security.cert.X509Certificate;
99

10-
import javax.net.ssl.SSLPeerUnverifiedException;
10+
import javax.net.ssl.SSLException;
1111

1212
import org.apache.http.HttpResponse;
1313
import org.apache.http.client.ClientProtocolException;
@@ -39,7 +39,7 @@ public class HttpsClientSslLiveTest {
3939

4040
// tests
4141

42-
@Test(expected = SSLPeerUnverifiedException.class)
42+
@Test(expected = SSLException.class)
4343
public final void whenHttpsUrlIsConsumed_thenException() throws ClientProtocolException, IOException {
4444
final CloseableHttpClient httpClient = HttpClientBuilder.create().build();
4545

@@ -71,6 +71,28 @@ public final boolean isTrusted(final X509Certificate[] certificate, final String
7171
httpClient.close();
7272
}
7373

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+
7496
@Test
7597
public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException {
7698
final SSLContextBuilder builder = new SSLContextBuilder();

0 commit comments

Comments
 (0)