summaryrefslogtreecommitdiffstats
path: root/vid-automation
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2020-03-26 16:47:08 +0200
committerIttay Stern <ittay.stern@att.com>2020-03-26 16:47:08 +0200
commit2c9d0b2dbd2f4a75fcd13fac3d1fc71429326425 (patch)
tree25fb7a589dce6aa69d592eb52402dedb0bb3d550 /vid-automation
parent6ffdec2e4c70db07fa598eb9612d2c8124a29ccc (diff)
Trust any certificate by API tests
Issue-ID: VID-647 Change-Id: I7ecfe746c57d6a178704b4f3616a637005f8f7c4 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-automation')
-rw-r--r--vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java b/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java
index 6106ae4a2..68ebeb122 100644
--- a/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java
+++ b/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java
@@ -1,25 +1,44 @@
package vid.automation.test.utils;
+import javax.net.ssl.SSLContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.TrustAllStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
public class InsecureHttpsClient {
public static RestTemplate newRestTemplate() {
- CloseableHttpClient insecureTLSHttpClient
- = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
+
+ CloseableHttpClient insecureTLSHttpClient = HttpClients.custom()
+ .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
+ .setSSLContext(trustAllCertificates())
+ .build();
+
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(insecureTLSHttpClient);
return new RestTemplate(factory);
}
+ private static SSLContext trustAllCertificates() {
+ try {
+ return new SSLContextBuilder()
+ .loadTrustMaterial(null, TrustAllStrategy.INSTANCE)
+ .build();
+ } catch (Exception e) {
+ return ExceptionUtils.rethrow(e);
+ }
+ }
+
public static Client newJaxrsClient() {
return ClientBuilder.newBuilder()
.hostnameVerifier(NoopHostnameVerifier.INSTANCE)
+ .sslContext(trustAllCertificates())
.build();
}