diff options
Diffstat (limited to 'vid-automation/src/main')
4 files changed, 43 insertions, 12 deletions
diff --git a/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java b/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java index bfd4782f9..4819b813f 100644 --- a/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java +++ b/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java @@ -20,7 +20,6 @@ import java.util.Properties; import java.util.Random; import java.util.TimeZone; import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -38,6 +37,7 @@ import vid.automation.reportportal.ReportPortalListenerDelegator; import vid.automation.test.infra.FeaturesTogglingConfiguration; import vid.automation.test.services.UsersService; import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor; +import vid.automation.test.utils.InsecureHttpsClient; @Listeners(ReportPortalListenerDelegator.class) public class BaseApiTest { @@ -50,16 +50,16 @@ public class BaseApiTest { @SuppressWarnings("WeakerAccess") protected Client client; protected Random random; - protected final RestTemplate restTemplate = new RestTemplate(); + protected final RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate(); protected final UsersService usersService = new UsersService(); - protected final RestTemplate restTemplateErrorAgnostic = new RestTemplate(); + protected final RestTemplate restTemplateErrorAgnostic = InsecureHttpsClient.newRestTemplate(); @BeforeClass public void init() { uri = getUri(); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - client = ClientBuilder.newClient(); + client = InsecureHttpsClient.newJaxrsClient(); client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); random = new Random(System.currentTimeMillis()); FeaturesTogglingConfiguration.initializeFeatureManager(); diff --git a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java index c6bf58f53..41ede9a3f 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java +++ b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java @@ -94,6 +94,7 @@ import vid.automation.test.services.SimulatorApi; import vid.automation.test.services.UsersService; import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor; import vid.automation.test.utils.DB_CONFIG; +import vid.automation.test.utils.InsecureHttpsClient; import vid.automation.test.utils.TestConfigurationHelper; import vid.automation.test.utils.TestHelper; @@ -102,7 +103,7 @@ public class VidBaseTestCase extends SetupCDTest{ protected final UsersService usersService = new UsersService(); protected final CategoryParamsService categoryParamsService = new CategoryParamsService(); - protected final RestTemplate restTemplate = new RestTemplate(); + protected final RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate(); protected final URI uri; protected final URI envUrI; diff --git a/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java b/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java index c98b2428a..0117a8a99 100644 --- a/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java +++ b/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java @@ -1,19 +1,23 @@ package vid.automation.test.utils; +import java.io.IOException; +import java.net.URI; +import java.util.Collections; +import java.util.List; import org.junit.Assert; import org.onap.sdc.ci.tests.datatypes.UserCredentials; -import org.springframework.http.*; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpRequest; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.support.HttpRequestWrapper; import org.springframework.web.client.RestTemplate; -import java.io.IOException; -import java.net.URI; -import java.util.Collections; -import java.util.List; - public class CookieAndJsonHttpHeadersInterceptor implements ClientHttpRequestInterceptor { private final HttpHeaders cookieAndJsonHttpHeaders; @@ -33,7 +37,7 @@ public class CookieAndJsonHttpHeadersInterceptor implements ClientHttpRequestInt protected HttpHeaders getCookieAndJsonHttpHeaders(URI uri, UserCredentials userCredentials) { HttpHeaders loginRequestHeaders = new HttpHeaders(); loginRequestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - RestTemplate restTemplate = new RestTemplate(); + RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate(); ResponseEntity<String> loginRes = restTemplate.postForEntity(uri.toASCIIString() + "/login_external.htm", new HttpEntity<>("loginId=" + userCredentials.getUserId() + "&password=" + userCredentials.getPassword(), loginRequestHeaders), String.class); Assert.assertEquals("Login failed - wrong http status with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), HttpStatus.FOUND, loginRes.getStatusCode()); Assert.assertNull("Failed to login with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), loginRes.getBody()); 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 new file mode 100644 index 000000000..6106ae4a2 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/test/utils/InsecureHttpsClient.java @@ -0,0 +1,26 @@ +package vid.automation.test.utils; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +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(); + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(insecureTLSHttpClient); + return new RestTemplate(factory); + } + + public static Client newJaxrsClient() { + return ClientBuilder.newBuilder() + .hostnameVerifier(NoopHostnameVerifier.INSTANCE) + .build(); + } + +} |