summaryrefslogtreecommitdiffstats
path: root/rest-services/cbs-client/src/test/java/org/onap
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2019-08-20 14:42:53 +0200
committerkjaniak <kornel.janiak@nokia.com>2019-11-27 14:20:09 +0100
commit01789096439b85ebb9d63633377a3603ef4a9535 (patch)
treeee52a2b22b3bf9c97298d80cc368cc61d9366f40 /rest-services/cbs-client/src/test/java/org/onap
parent2f1cf71e142b1c3494bd4f652f3af2a296430b8f (diff)
Upgrade CBS java SDK to support SSL
- add TrustStoreKeys class for one-way TLS for CBS client - use trust.jks & trust.pass - add unit test - top up version of Vavr lib (due to bug) Issue-ID: DCAEGEN2-1552 Signed-off-by: Piotr Wielebski <piotr.wielebski@nokia.com> Change-Id: I372c559cce5db8eba5448d99e12cdf6609c40d00
Diffstat (limited to 'rest-services/cbs-client/src/test/java/org/onap')
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java122
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java20
-rw-r--r--rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java17
3 files changed, 137 insertions, 22 deletions
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java
index e00fd6bd..d0df0b6c 100644
--- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientConfigurationTest.java
@@ -21,18 +21,132 @@
package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api;
-import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-
+import org.junit.Rule;
+import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.CbsClientConfigurationException;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
+import org.onap.dcaegen2.services.sdk.security.ssl.Passwords;
+
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
* @since February 2019
*/
class CbsClientConfigurationTest {
+
+ @Rule
+ public final EnvironmentVariables envs = new EnvironmentVariables();
+
+ @Test
+ void fromEnvironment_shouldReturnConfigurationForConnectionWithoutTls_when_DCAE_CA_CERTPATH_isEmpty() {
+ // given
+ envs.set("DCAE_CA_CERTPATH", "");
+ envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
+ envs.set("CONFIG_BINDING_SERVICE_SERVICE_PORT", "10000");
+ envs.set("HOSTNAME", "dcae-prh");
+ envs.set("CONSUL_HOST", "consul-server.onap");
+
+ // when
+ CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
+
+ // then
+ assertThat(configuration.trustStoreKeys()).isEqualTo(null);
+ assertThat(configuration.protocol()).isEqualTo("http");
+ }
+
+ @Test
+ void fromEnvironment_shouldReturnConfigurationForConnectionOverTls_when_DCAE_CA_CERTPATH_isSet() throws URISyntaxException {
+ // given
+ envs.set("DCAE_CA_CERTPATH", preparePathToCertFile());
+ envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
+ envs.set("CONFIG_BINDING_SERVICE_PORT_10443_TCP_PORT", "10443");
+ envs.set("HOSTNAME", "dcae-prh");
+ envs.set("CONSUL_HOST", "consul-server.onap");
+
+ // when
+ CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
+
+ // then
+ assertThat(configuration.trustStoreKeys()).isNotNull();
+ assertThat(configuration.protocol()).isEqualTo("https");
+ }
+
+ @Test
+ void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_DCAE_CA_CERTPATH_is_Null() {
+ // given
+ envs.set("DCAE_CA_CERTPATH", null);
+ envs.set("CONFIG_BINDING_SERVICE_SERVICE_PORT", "9090");
+ envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
+ envs.set("CONFIG_BINDING_SERVICE_PORT_10443_TCP_PORT", "10443");
+ envs.set("HOSTNAME", "dcae-prh");
+ envs.set("CONSUL_HOST", "consul-server.onap");
+
+ // when
+ CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
+
+ // then
+ assertThat(configuration.trustStoreKeys()).isNull();
+ assertThat(configuration.protocol()).isEqualTo("http");
+ }
+
+ @Test
+ void fromEnvironment_shouldReturn_CbsClientConfigurationException_WhenAllEnvVariablesAreMissing() {
+ assertThatExceptionOfType(CbsClientConfigurationException.class)
+ .isThrownBy(CbsClientConfiguration::fromEnvironment);
+ }
+
+ @Test
+ void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_DCAE_CA_CERTPATH_isWrong() {
+ // given
+ envs.set("DCAE_CA_CERTPATH", "/home/cacert.pem");
+ envs.set("HOSTNAME", "dcae-prh");
+ envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
+ envs.set("CONFIG_BINDING_SERVICE_PORT_10443_TCP_PORT", "10443");
+ envs.set("CONSUL_HOST", "consul-server.onap");
+
+ // then
+ assertThatExceptionOfType(CbsClientConfigurationException.class)
+ .isThrownBy(CbsClientConfiguration::fromEnvironment)
+ .withMessageContaining("Required files do not exist in /home directory");
+ }
+
@Test
- void fromEnvironmentShouldFailWhenEnvVariablesAreMissing() {
- assertThatExceptionOfType(NullPointerException.class).isThrownBy(CbsClientConfiguration::fromEnvironment);
+ void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_HOSTNAME_isMissing() throws URISyntaxException {
+ // given
+ envs.set("HOSTNAME", "");
+ envs.set("DCAE_CA_CERTPATH", preparePathToCertFile());
+ envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
+ envs.set("CONFIG_BINDING_SERVICE_PORT_10443_TCP_PORT", "10443");
+ envs.set("CONSUL_HOST", "consul-server.onap");
+
+ // then
+ assertThatExceptionOfType(CbsClientConfigurationException.class)
+ .isThrownBy(CbsClientConfiguration::fromEnvironment)
+ .withMessageContaining("Cannot read HOSTNAME from environment.");
+ }
+
+ @Test
+ void fromEnvironment_shouldReturn_CbsClientConfigurationException_When_CONFIG_BINDING_SERVICE_SERVICE_PORT_isEmpty() {
+ // given
+ envs.set("CONFIG_BINDING_SERVICE_SERVICE_PORT", "");
+ envs.set("DCAE_CA_CERTPATH", "");
+ envs.set("HOSTNAME", "dcae-prh");
+ envs.set("CONFIG_BINDING_SERVICE", "config-binding-service");
+ envs.set("CONSUL_HOST", "consul-server.onap");
+
+ // then
+ assertThatExceptionOfType(CbsClientConfigurationException.class)
+ .isThrownBy(CbsClientConfiguration::fromEnvironment)
+ .withMessageContaining("Cannot read CONFIG_BINDING_SERVICE_SERVICE_PORT from environment.");
+ }
+
+ private String preparePathToCertFile() throws URISyntaxException {
+ return Paths.get(Passwords.class.getResource("/test-certs/cacert.pem").toURI()) + "";
}
} \ No newline at end of file
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java
index 43b2a7bb..5804c165 100644
--- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplIT.java
@@ -20,17 +20,8 @@
package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.onap.dcaegen2.services.sdk.model.streams.StreamType.KAFKA;
-import static org.onap.dcaegen2.services.sdk.model.streams.StreamType.MESSAGE_ROUTER;
-import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.test.DummyHttpServer.sendResource;
-import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamPredicates.streamOfType;
-
import com.google.gson.JsonObject;
import io.vavr.collection.Stream;
-
-import java.time.Duration;
-
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -47,14 +38,22 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.St
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.DataStreams;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamFromGsonParser;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamFromGsonParsers;
-import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsRequest;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
+import java.time.Duration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.onap.dcaegen2.services.sdk.model.streams.StreamType.KAFKA;
+import static org.onap.dcaegen2.services.sdk.model.streams.StreamType.MESSAGE_ROUTER;
+import static org.onap.dcaegen2.services.sdk.rest.services.adapters.http.test.DummyHttpServer.sendResource;
+import static org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.streams.StreamPredicates.streamOfType;
+
/**
* @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
* @since February 2019
@@ -77,6 +76,7 @@ class CbsClientImplIT {
.get("/sampleKey/dcae-component", (req, resp) -> sendResource(resp, SAMPLE_KEY))
);
sampleConfiguration = ImmutableCbsClientConfiguration.builder()
+ .protocol("http")
.appName("dcae-component")
.hostname(server.host())
.port(server.port())
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java
index 78b79f9d..40cf7100 100644
--- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java
+++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientImplTest.java
@@ -20,14 +20,7 @@
package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
import com.google.gson.JsonObject;
-import java.net.InetSocketAddress;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
@@ -40,6 +33,14 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import reactor.core.publisher.Mono;
+import java.net.InetSocketAddress;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
/**
* @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
* @since February 2019
@@ -52,7 +53,7 @@ class CbsClientImplTest {
// given
InetSocketAddress cbsAddress = InetSocketAddress.createUnresolved("cbshost", 6969);
String serviceName = "dcaegen2-ves-collector";
- final CbsClient cut = new CbsClientImpl(httpClient, serviceName, cbsAddress);
+ final CbsClient cut = new CbsClientImpl(httpClient, serviceName, cbsAddress, "http");
final HttpResponse httpResponse = ImmutableHttpResponse.builder()
.url("http://xxx")
.statusCode(200)