cleanup of httpclient tests
This commit is contained in:
parent
d8e4f04225
commit
72279b8d80
@ -173,7 +173,7 @@
|
|||||||
<mockito.version>1.10.8</mockito.version>
|
<mockito.version>1.10.8</mockito.version>
|
||||||
|
|
||||||
<httpcore.version>4.3.3</httpcore.version>
|
<httpcore.version>4.3.3</httpcore.version>
|
||||||
<httpclient.version>4.3.4</httpclient.version>
|
<httpclient.version>4.3.6</httpclient.version>
|
||||||
|
|
||||||
<rest-assured.version>2.4.0</rest-assured.version>
|
<rest-assured.version>2.4.0</rest-assured.version>
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import java.io.IOException;
|
|||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLException;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
@ -39,7 +39,7 @@ public class HttpsClientSslLiveTest {
|
|||||||
|
|
||||||
// tests
|
// tests
|
||||||
|
|
||||||
@Test(expected = SSLPeerUnverifiedException.class)
|
@Test(expected = SSLException.class)
|
||||||
public final void whenHttpsUrlIsConsumed_thenException() throws ClientProtocolException, IOException {
|
public final void whenHttpsUrlIsConsumed_thenException() throws ClientProtocolException, IOException {
|
||||||
final CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
final CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
||||||
|
|
||||||
@ -71,6 +71,28 @@ public class HttpsClientSslLiveTest {
|
|||||||
httpClient.close();
|
httpClient.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenHttpClientAfter4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException {
|
||||||
|
final TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
|
||||||
|
@Override
|
||||||
|
public final boolean isTrusted(final X509Certificate[] certificate, final String authType) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
final SSLSocketFactory sf = new SSLSocketFactory(acceptingTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
final SchemeRegistry registry = new SchemeRegistry();
|
||||||
|
registry.register(new Scheme("https", 443, sf));
|
||||||
|
final ClientConnectionManager ccm = new PoolingClientConnectionManager(registry);
|
||||||
|
|
||||||
|
final CloseableHttpClient httpClient = new DefaultHttpClient(ccm);
|
||||||
|
|
||||||
|
final HttpGet getMethod = new HttpGet(HOST_WITH_SSL);
|
||||||
|
final HttpResponse response = httpClient.execute(getMethod);
|
||||||
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
|
|
||||||
|
httpClient.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException {
|
public final void givenHttpClientPost4_3_whenAcceptingAllCertificates_thenCanConsumeHttpsUriWithSelfSignedCertificate() throws IOException, GeneralSecurityException {
|
||||||
final SSLContextBuilder builder = new SSLContextBuilder();
|
final SSLContextBuilder builder = new SSLContextBuilder();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user