aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/DummyCollector.java24
-rw-r--r--services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/HvVesProducerIT.java30
-rw-r--r--services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/SystemUnderTestWrapper.java44
-rw-r--r--services/hv-ves-client/producer/ct/src/test/resources/client.p12bin5183 -> 5175 bytes
-rw-r--r--services/hv-ves-client/producer/ct/src/test/resources/server.p12bin0 -> 5175 bytes
-rw-r--r--services/hv-ves-client/producer/ct/src/test/resources/server.pass1
-rw-r--r--services/hv-ves-client/producer/ct/src/test/resources/trust.p12bin1514 -> 2303 bytes
7 files changed, 74 insertions, 25 deletions
diff --git a/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/DummyCollector.java b/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/DummyCollector.java
index 46aeacc6..70e9cdff 100644
--- a/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/DummyCollector.java
+++ b/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/DummyCollector.java
@@ -20,12 +20,16 @@
package org.onap.dcaegen2.services.sdk.services.hvves.client.producer.ct;
import io.netty.buffer.ByteBuf;
+
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.stream.IntStream;
+
+import io.netty.handler.ssl.SslContext;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.ReplayProcessor;
@@ -39,6 +43,7 @@ import reactor.util.function.Tuple2;
* @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
*/
public class DummyCollector {
+ private Optional<SslContext> sslContext;
private final List<ByteBuf> receivedData = Collections.synchronizedList(new ArrayList<>());
private DisposableServer server;
@@ -48,13 +53,20 @@ public class DummyCollector {
.map(Tuple2::getT1)
.share();
+ DummyCollector(Optional<SslContext> sslContext) {
+ this.sslContext = sslContext;
+ }
+
public InetSocketAddress start() {
- server = TcpServer.create()
- .host("localhost")
- .port(6666)
- .wiretap(true)
- .handle(this::handleConnection)
- .bindNow();
+ TcpServer tcpServer =
+ sslContext.map(context -> TcpServer.create()
+ .secure(ssl -> ssl.sslContext(context)))
+ .orElseGet(TcpServer::create)
+ .host("localhost")
+ .port(6666)
+ .wiretap(true)
+ .handle(this::handleConnection);
+ server = tcpServer.bindNow();
return server.address();
}
diff --git a/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/HvVesProducerIT.java b/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/HvVesProducerIT.java
index 247cfad5..34175577 100644
--- a/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/HvVesProducerIT.java
+++ b/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/HvVesProducerIT.java
@@ -23,7 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import io.netty.buffer.ByteBuf;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.options.PayloadType;
import org.onap.ves.MeasDataCollectionOuterClass;
@@ -31,6 +30,8 @@ import org.onap.ves.VesEventOuterClass.CommonEventHeader;
import org.onap.ves.VesEventOuterClass.VesEvent;
import reactor.core.publisher.Flux;
+import java.time.Duration;
+
/**
* @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
*/
@@ -42,12 +43,7 @@ class HvVesProducerIT {
private static final int PERIOD = 1000;
private static final String OBJECT_INSTANCE_ID = "DH-1";
- private final SystemUnderTestWrapper sut = new SystemUnderTestWrapper();
-
- @BeforeEach
- void setUp() {
- sut.start();
- }
+ private final SystemUnderTestWrapper sut = new SystemUnderTestWrapper(Duration.ofSeconds(10));
@AfterEach
void tearDown() {
@@ -55,19 +51,37 @@ class HvVesProducerIT {
}
@Test
- void singleMessageTest() throws Exception {
+ void singleMessageTest_withUnsecureConnection() throws Exception {
// given
+ final VesEvent sampleEvent = createSimpleVesEvent();
+ final Flux<VesEvent> input = Flux.just(sampleEvent);
+
+ // when
+ sut.start();
+ final ByteBuf receivedData = sut.blockingSend(input);
+ // then
+ WireProtocolDecoder decoded = WireProtocolDecoder.decode(receivedData);
+ assertThat(decoded.type).isEqualTo(PayloadType.PROTOBUF.getPayloadTypeBytes().getShort());
+ assertThat(decoded.event).isEqualTo(sampleEvent);
+
+ }
+
+ @Test
+ void singleMessageTest_withSecureConnection() throws Exception {
+ // given
final VesEvent sampleEvent = createSimpleVesEvent();
final Flux<VesEvent> input = Flux.just(sampleEvent);
// when
+ sut.startSecure();
final ByteBuf receivedData = sut.blockingSend(input);
// then
WireProtocolDecoder decoded = WireProtocolDecoder.decode(receivedData);
assertThat(decoded.type).isEqualTo(PayloadType.PROTOBUF.getPayloadTypeBytes().getShort());
assertThat(decoded.event).isEqualTo(sampleEvent);
+
}
private VesEvent createSimpleVesEvent() {
diff --git a/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/SystemUnderTestWrapper.java b/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/SystemUnderTestWrapper.java
index ec16e9e4..45511d7f 100644
--- a/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/SystemUnderTestWrapper.java
+++ b/services/hv-ves-client/producer/ct/src/test/java/org/onap/dcaegen2/services/sdk/services/hvves/client/producer/ct/SystemUnderTestWrapper.java
@@ -20,6 +20,7 @@
package org.onap.dcaegen2.services.sdk.services.hvves.client.producer.ct;
import io.netty.buffer.ByteBuf;
+import io.netty.handler.ssl.SslContext;
import io.vavr.collection.HashSet;
import io.vavr.control.Try;
@@ -27,10 +28,9 @@ import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
+import java.util.Optional;
-import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys;
-import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore;
-import org.onap.dcaegen2.services.sdk.security.ssl.Passwords;
+import org.onap.dcaegen2.services.sdk.security.ssl.*;
import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.HvVesProducer;
import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.HvVesProducerFactory;
import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.options.ImmutableProducerOptions;
@@ -46,9 +46,17 @@ import reactor.core.publisher.Flux;
public class SystemUnderTestWrapper {
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(5);
- private final DummyCollector collector = new DummyCollector();
+ private static final String TRUST_CERT_PATH = "/trust.p12";
+ private static final String TRUST_PASSWORD_PATH = "/trust.pass";
+ private static final String CLIENT_CERT_PATH = "/client.p12";
+ private static final String CLIENT_PASSWORD_PATH = "/client.pass";
+ private static final String SERVER_CERT_PATH = "/server.p12";
+ private static final String SERVER_PASSWORD_PATH = "/server.pass";
+
+ private DummyCollector collector;
private HvVesProducer cut;
private final Duration timeout;
+ private final SslFactory sslFactory = new SslFactory();
public SystemUnderTestWrapper(Duration timeout) {
this.timeout = timeout;
@@ -59,16 +67,19 @@ public class SystemUnderTestWrapper {
}
public void startSecure() {
- start(ImmutableProducerOptions.builder()
- .securityKeys(ImmutableSecurityKeys.builder()
- .keyStore(ImmutableSecurityKeysStore.of(resource("/client.p12").get()))
- .keyStorePassword(Passwords.fromResource("/client.pass"))
- .trustStore(ImmutableSecurityKeysStore.of(resource("/trust.p12").get()))
- .trustStorePassword(Passwords.fromResource("/trust.pass"))
- .build()));
+ collector = createCollectorWithEnabledSSL();
+
+ final SecurityKeys producerSecurityKeys = ImmutableSecurityKeys.builder()
+ .keyStore(ImmutableSecurityKeysStore.of(resource(CLIENT_CERT_PATH).get()))
+ .keyStorePassword(Passwords.fromResource(CLIENT_PASSWORD_PATH))
+ .trustStore(ImmutableSecurityKeysStore.of(resource(TRUST_CERT_PATH).get()))
+ .trustStorePassword(Passwords.fromResource(TRUST_PASSWORD_PATH))
+ .build();
+ start(ImmutableProducerOptions.builder().securityKeys(producerSecurityKeys));
}
public void start() {
+ collector = new DummyCollector(Optional.empty());
start(createDefaultOptions());
}
@@ -90,6 +101,17 @@ public class SystemUnderTestWrapper {
return collector.dataFromFirstClient();
}
+ private DummyCollector createCollectorWithEnabledSSL() {
+ final SecurityKeys collectorSecurityKeys = ImmutableSecurityKeys.builder()
+ .keyStore(ImmutableSecurityKeysStore.of(resource(SERVER_CERT_PATH).get()))
+ .keyStorePassword(Passwords.fromResource(SERVER_PASSWORD_PATH))
+ .trustStore(ImmutableSecurityKeysStore.of(resource(TRUST_CERT_PATH).get()))
+ .trustStorePassword(Passwords.fromResource(TRUST_PASSWORD_PATH))
+ .build();
+ final SslContext collectorSslContext = sslFactory.createSecureServerContext(collectorSecurityKeys);
+ return new DummyCollector(Optional.of(collectorSslContext));
+ }
+
private Builder createDefaultOptions() {
return ImmutableProducerOptions.builder();
}
diff --git a/services/hv-ves-client/producer/ct/src/test/resources/client.p12 b/services/hv-ves-client/producer/ct/src/test/resources/client.p12
index 68a0fb25..26b79d77 100644
--- a/services/hv-ves-client/producer/ct/src/test/resources/client.p12
+++ b/services/hv-ves-client/producer/ct/src/test/resources/client.p12
Binary files differ
diff --git a/services/hv-ves-client/producer/ct/src/test/resources/server.p12 b/services/hv-ves-client/producer/ct/src/test/resources/server.p12
new file mode 100644
index 00000000..169ecf34
--- /dev/null
+++ b/services/hv-ves-client/producer/ct/src/test/resources/server.p12
Binary files differ
diff --git a/services/hv-ves-client/producer/ct/src/test/resources/server.pass b/services/hv-ves-client/producer/ct/src/test/resources/server.pass
new file mode 100644
index 00000000..e69c2de9
--- /dev/null
+++ b/services/hv-ves-client/producer/ct/src/test/resources/server.pass
@@ -0,0 +1 @@
+onaponap \ No newline at end of file
diff --git a/services/hv-ves-client/producer/ct/src/test/resources/trust.p12 b/services/hv-ves-client/producer/ct/src/test/resources/trust.p12
index ed7f62d4..1ca2f651 100644
--- a/services/hv-ves-client/producer/ct/src/test/resources/trust.p12
+++ b/services/hv-ves-client/producer/ct/src/test/resources/trust.p12
Binary files differ