From be68ea73313277ae749cdc47f15e9993d1c5a6ce Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Wed, 10 Apr 2019 15:02:01 +0200 Subject: Move cmd ssl logic to xnf-simulator Change-Id: I562acbb0b7522e6cefea2a2dc1a9e292c1227b41 Signed-off-by: Jakub Dudycz Issue-ID: DCAEGEN2-565 --- sources/hv-collector-ssl/pom.xml | 12 -- .../dcae/collectors/veshv/ssl/boundary/utils.kt | 73 ----------- .../collectors/veshv/ssl/boundary/UtilsKtTest.kt | 76 ----------- .../hv-collector-ssl/src/test/resources/ssl/ca.crt | 21 --- .../src/test/resources/ssl/password | 1 - .../src/test/resources/ssl/server.crt | 19 --- .../src/test/resources/ssl/server.key | 28 ---- .../src/test/resources/ssl/server.ks.pkcs12 | Bin 2389 -> 0 bytes .../src/test/resources/ssl/trust.pkcs12 | Bin 1096 -> 0 bytes .../impl/config/ArgXnfSimulatorConfiguration.kt | 1 - .../veshv/simulators/xnf/impl/config/SslUtils.kt | 72 +++++++++++ .../dcae/collectors/veshv/simulators/xnf/main.kt | 1 - .../dcae/collectors/veshv/main/HvVesClientTest.kt | 58 --------- .../veshv/main/OngoingSimulationsTest.kt | 142 --------------------- .../dcae/collectors/veshv/main/XnfSimulatorTest.kt | 135 -------------------- .../simulators/xnf/impl/OngoingSimulationsTest.kt | 137 ++++++++++++++++++++ .../veshv/simulators/xnf/impl/XnfSimulatorTest.kt | 134 +++++++++++++++++++ .../xnf/impl/adapters/HvVesClientTest.kt | 58 +++++++++ .../simulators/xnf/impl/config/SslUtilsTest.kt | 76 +++++++++++ .../src/test/resources/ssl/ca.crt | 21 +++ .../src/test/resources/ssl/password | 1 + .../src/test/resources/ssl/server.crt | 19 +++ .../src/test/resources/ssl/server.key | 28 ++++ .../src/test/resources/ssl/server.ks.pkcs12 | Bin 0 -> 2389 bytes .../src/test/resources/ssl/trust.pkcs12 | Bin 0 -> 1096 bytes 25 files changed, 546 insertions(+), 567 deletions(-) delete mode 100644 sources/hv-collector-ssl/src/main/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/utils.kt delete mode 100644 sources/hv-collector-ssl/src/test/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/UtilsKtTest.kt delete mode 100644 sources/hv-collector-ssl/src/test/resources/ssl/ca.crt delete mode 100644 sources/hv-collector-ssl/src/test/resources/ssl/password delete mode 100644 sources/hv-collector-ssl/src/test/resources/ssl/server.crt delete mode 100644 sources/hv-collector-ssl/src/test/resources/ssl/server.key delete mode 100644 sources/hv-collector-ssl/src/test/resources/ssl/server.ks.pkcs12 delete mode 100644 sources/hv-collector-ssl/src/test/resources/ssl/trust.pkcs12 create mode 100644 sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtils.kt delete mode 100644 sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt delete mode 100644 sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/OngoingSimulationsTest.kt delete mode 100644 sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt create mode 100644 sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/OngoingSimulationsTest.kt create mode 100644 sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulatorTest.kt create mode 100644 sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/HvVesClientTest.kt create mode 100644 sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtilsTest.kt create mode 100644 sources/hv-collector-xnf-simulator/src/test/resources/ssl/ca.crt create mode 100644 sources/hv-collector-xnf-simulator/src/test/resources/ssl/password create mode 100644 sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.crt create mode 100644 sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.key create mode 100644 sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.ks.pkcs12 create mode 100644 sources/hv-collector-xnf-simulator/src/test/resources/ssl/trust.pkcs12 diff --git a/sources/hv-collector-ssl/pom.xml b/sources/hv-collector-ssl/pom.xml index 0ba609e5..2aaf2295 100644 --- a/sources/hv-collector-ssl/pom.xml +++ b/sources/hv-collector-ssl/pom.xml @@ -54,16 +54,6 @@ - - ${project.parent.groupId} - hv-collector-commandline - ${project.parent.version} - - - ${project.parent.groupId} - hv-collector-domain - ${project.parent.version} - ${project.parent.groupId} hv-collector-test-utils @@ -94,6 +84,4 @@ test - - diff --git a/sources/hv-collector-ssl/src/main/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/utils.kt b/sources/hv-collector-ssl/src/main/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/utils.kt deleted file mode 100644 index 5981d9d4..00000000 --- a/sources/hv-collector-ssl/src/main/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/utils.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.ssl.boundary - -import arrow.core.None -import arrow.core.Some -import arrow.core.Try -import org.apache.commons.cli.CommandLine -import org.onap.dcae.collectors.veshv.commandline.CommandLineOption -import org.onap.dcae.collectors.veshv.commandline.hasOption -import org.onap.dcae.collectors.veshv.commandline.stringValue -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 java.nio.file.Paths - -/** - * @author Piotr Jaszczyk - * @since September 2018 - */ - -const val KEY_STORE_FILE = "/etc/ves-hv/server.p12" -const val KEY_STORE_PASSWORD_FILE = "/etc/ves-hv/server.pass" -const val TRUST_STORE_FILE = "/etc/ves-hv/trust.p12" -const val TRUST_STORE_PASSWORD_FILE = "/etc/ves-hv/trust.pass" - -fun createSecurityConfiguration(cmdLine: CommandLine): Try = - createSecurityConfigurationProvider(cmdLine).map { it() } - -fun createSecurityConfigurationProvider(cmdLine: CommandLine): Try<() -> SecurityConfiguration> = - if (shouldDisableSsl(cmdLine)) - Try { { disabledSecurityConfiguration() } } - else - Try { { enabledSecurityConfiguration(cmdLine) } } - -private fun shouldDisableSsl(cmdLine: CommandLine) = cmdLine.hasOption(CommandLineOption.SSL_DISABLE) - -private fun disabledSecurityConfiguration() = SecurityConfiguration(None) - -private fun enabledSecurityConfiguration(cmdLine: CommandLine): SecurityConfiguration { - val ksFile = cmdLine.stringValue(CommandLineOption.KEY_STORE_FILE, KEY_STORE_FILE) - val ksPass = cmdLine.stringValue(CommandLineOption.KEY_STORE_PASSWORD_FILE, KEY_STORE_PASSWORD_FILE) - val tsFile = cmdLine.stringValue(CommandLineOption.TRUST_STORE_FILE, TRUST_STORE_FILE) - val tsPass = cmdLine.stringValue(CommandLineOption.TRUST_STORE_PASSWORD_FILE, TRUST_STORE_PASSWORD_FILE) - - val keys = ImmutableSecurityKeys.builder() - .keyStore(ImmutableSecurityKeysStore.of(pathFromFile(ksFile))) - .keyStorePassword(Passwords.fromPath(pathFromFile(ksPass))) - .trustStore(ImmutableSecurityKeysStore.of(pathFromFile(tsFile))) - .trustStorePassword(Passwords.fromPath(pathFromFile(tsPass))) - .build() - - return SecurityConfiguration(Some(keys)) -} - -private fun pathFromFile(file: String) = Paths.get(file) diff --git a/sources/hv-collector-ssl/src/test/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/UtilsKtTest.kt b/sources/hv-collector-ssl/src/test/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/UtilsKtTest.kt deleted file mode 100644 index c7c414f8..00000000 --- a/sources/hv-collector-ssl/src/test/kotlin/org/onap/dcae/collectors/veshv/ssl/boundary/UtilsKtTest.kt +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2019 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.ssl.boundary - -import com.nhaarman.mockitokotlin2.doReturn -import com.nhaarman.mockitokotlin2.eq -import com.nhaarman.mockitokotlin2.mock -import com.nhaarman.mockitokotlin2.verify -import com.nhaarman.mockitokotlin2.whenever -import org.apache.commons.cli.CommandLine -import org.assertj.core.api.Assertions.assertThat -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it -import org.jetbrains.spek.api.dsl.on -import org.onap.dcae.collectors.veshv.commandline.CommandLineOption -import org.onap.dcae.collectors.veshv.commandline.hasOption -import org.onap.dcae.collectors.veshv.commandline.stringValue -import java.nio.file.Paths - - -internal object UtilsKtTest : Spek({ - - describe("creating securty configuration provider") { - - on("command line without ssl disable") { - val passwordFile = resourcePathAsString("/ssl/password") - val commandLine: CommandLine = mock() - whenever(commandLine.hasOption(CommandLineOption.SSL_DISABLE)).doReturn(false) - whenever(commandLine.stringValue(CommandLineOption.TRUST_STORE_PASSWORD_FILE, TRUST_STORE_PASSWORD_FILE)) - .doReturn(passwordFile) - whenever(commandLine.stringValue(CommandLineOption.KEY_STORE_PASSWORD_FILE, KEY_STORE_PASSWORD_FILE)) - .doReturn(passwordFile) - - it("should create configuration with some keys") { - val configuration = createSecurityConfiguration(commandLine) - - verify(commandLine).hasOption(CommandLineOption.SSL_DISABLE) - assertThat(configuration.isSuccess()).isTrue() - configuration.map { assertThat(it.keys.isDefined()).isTrue() } - } - } - on("command line with ssl disabled") { - val commandLine: CommandLine = mock() - whenever(commandLine.hasOption(CommandLineOption.SSL_DISABLE)).doReturn(true) - - it("should create configuration without keys") { - val configuration = createSecurityConfiguration(commandLine) - - verify(commandLine).hasOption(CommandLineOption.SSL_DISABLE) - assertThat(configuration.isSuccess()).isTrue() - configuration.map { assertThat(it.keys.isEmpty()).isTrue() } - } - } - } -}) - -private fun resourcePathAsString(resource: String) = - Paths.get(UtilsKtTest::class.java.getResource(resource).toURI()).toString() diff --git a/sources/hv-collector-ssl/src/test/resources/ssl/ca.crt b/sources/hv-collector-ssl/src/test/resources/ssl/ca.crt deleted file mode 100644 index f9a05b90..00000000 --- a/sources/hv-collector-ssl/src/test/resources/ssl/ca.crt +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDbDCCAlSgAwIBAgIJAMsh09jY3jSBMA0GCSqGSIb3DQEBCwUAMEsxCzAJBgNV -BAYTAlBMMQswCQYDVQQIDAJETDEQMA4GA1UEBwwHV3JvY2xhdzEOMAwGA1UECgwF -Tm9raWExDTALBgNVBAsMBE1BTk8wHhcNMTgwODEzMTE1OTE5WhcNMTkwODEzMTE1 -OTE5WjBLMQswCQYDVQQGEwJQTDELMAkGA1UECAwCREwxEDAOBgNVBAcMB1dyb2Ns -YXcxDjAMBgNVBAoMBU5va2lhMQ0wCwYDVQQLDARNQU5PMIIBIjANBgkqhkiG9w0B -AQEFAAOCAQ8AMIIBCgKCAQEAyIs4sk5SlBRltDHZDDIGHdazzdduPRKdDBMUTE5i -++iZe1MU9WnbPWgbnfj/1DN+VbbJEa32agDXBhS9mPiSrflDe8oqPPk12miiflsY -TxGxY1bjH58kRNey164fPznzc9LqKqV1brUPktgBkHumM4zPVZYue5cp1T2FiWcE -nFdqOKK2F0mdby+Pim9JHil34YcvavOlMXULkqayR7hxfUIAmMZtl59BKVx9BcKD -9Sv9TQYRIYHhymrKnwIb8RolDaDdVUnr2ryREjZ8WfoBsOpraIYDUjKijF5FlgLs -Fp8wcIflF6JyMbtchTm5acQZkcqK1AGYTD1wxT33E2pdDQIDAQABo1MwUTAdBgNV -HQ4EFgQUOL9AR068MxqYCsKkEfgDzF2HrY8wHwYDVR0jBBgwFoAUOL9AR068MxqY -CsKkEfgDzF2HrY8wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEA -OXNDDqrk8bTJfy78mkMZame/bLEUQ2h4EvWT6trd5XYNfPwQW/u6laLJAtLFbzth -lpNBRK//sK+AYgwDURq0HcW5YczhgzZbfG9ab1J/7GUrFJh+DHL3bNL1YFX84JbI -coUbxaJFkmIvlQDLWDYfpQ/gNwUbuUPZjGZC2bWobZw9sRC+e51TIoAmgZwvTElC -v3vD2BwbIs7C4ylrIQU9Q1rY17MeWH9m8ZhEX1C4W4+N54V6jJ7czE9HQEnapeEu -5rmEoDqP191x+tOxp/Xg8j+wcAK/dVy1Q3xQQZCW84rv0TBHbdaAPamBLUzHeW3W -F7BpnVhn1NfYVOKx5W0NfA== ------END CERTIFICATE----- diff --git a/sources/hv-collector-ssl/src/test/resources/ssl/password b/sources/hv-collector-ssl/src/test/resources/ssl/password deleted file mode 100644 index e69c2de9..00000000 --- a/sources/hv-collector-ssl/src/test/resources/ssl/password +++ /dev/null @@ -1 +0,0 @@ -onaponap \ No newline at end of file diff --git a/sources/hv-collector-ssl/src/test/resources/ssl/server.crt b/sources/hv-collector-ssl/src/test/resources/ssl/server.crt deleted file mode 100644 index 2b06108b..00000000 --- a/sources/hv-collector-ssl/src/test/resources/ssl/server.crt +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDEjCCAfoCCQCId29lGbm5LjANBgkqhkiG9w0BAQsFADBLMQswCQYDVQQGEwJQ -TDELMAkGA1UECAwCREwxEDAOBgNVBAcMB1dyb2NsYXcxDjAMBgNVBAoMBU5va2lh -MQ0wCwYDVQQLDARNQU5PMB4XDTE4MDgxMzEyMDAyNFoXDTE5MDgwODEyMDAyNFow -SzELMAkGA1UEBhMCUEwxCzAJBgNVBAgMAkRMMRAwDgYDVQQHDAdXcm9jbGF3MQ4w -DAYDVQQKDAVOb2tpYTENMAsGA1UECwwETUFOTzCCASIwDQYJKoZIhvcNAQEBBQAD -ggEPADCCAQoCggEBALbblOyqeJayotBiY6aZnGWnMHCHNTileJF8hkFS5P5qM9BU -XH7NW/p5wSNcQWBB81HrRVneHpm6zfZtUPtcqXC4vpTk/sy3WT8rlEU+uv1YYVP8 -r0jxXr1WZ8sGcxOjhiMMRpMqImoALRak3ombtktfMc2Yeab4J25941wpDSQoUjT8 -LlXhfyjbBijum0LY+cqsuV5qk2qrzo0ZLD6m51aaWEyeysQ/3JanYKvPZDKdvAYN -+98ud6d/rjdWIJXwxEGp1fpW0p+fHOUhjMB1a5gkPDIpU68ME6BZJ3xJZb1qqXLS -pkUitMIWZSWx5xNhcifsnxWyhZfnhd8GnxU3Lf8CAwEAATANBgkqhkiG9w0BAQsF -AAOCAQEAJCrPdc8R7kBOmeIPyVX8QBOsrVTBBDzhskpi51nMsAKvcGjtYdXknYPj -bw3YVASE2efrq5QWHC0maIxDAHzI/kmWGH8F0s8S6QRH/7fstvxaNaSArzQB/thW -qIWs7AufUSsLMwtcXQ6KdYNbnaMwTynuuK+ANilcLvV8GxRAzXgFdoWZ2OuJRyzu -BWQZS49WanyqX1kDLMsrLtdJyl/yVEfsmDcUyhapuuGwtconkWK/CVrJlV1vh1Z+ -Svh9IfvAF7WPPpGsM/y9+hGNtK6sPVUKl4acBzIAv6aN1QS5H4zRvtbwv7xpUp4M -P84PY3lv1X3NJCGrfVByh2lFWParKA== ------END CERTIFICATE----- diff --git a/sources/hv-collector-ssl/src/test/resources/ssl/server.key b/sources/hv-collector-ssl/src/test/resources/ssl/server.key deleted file mode 100644 index 40e25932..00000000 --- a/sources/hv-collector-ssl/src/test/resources/ssl/server.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC225TsqniWsqLQ -YmOmmZxlpzBwhzU4pXiRfIZBUuT+ajPQVFx+zVv6ecEjXEFgQfNR60VZ3h6Zus32 -bVD7XKlwuL6U5P7Mt1k/K5RFPrr9WGFT/K9I8V69VmfLBnMTo4YjDEaTKiJqAC0W -pN6Jm7ZLXzHNmHmm+CdufeNcKQ0kKFI0/C5V4X8o2wYo7ptC2PnKrLleapNqq86N -GSw+pudWmlhMnsrEP9yWp2Crz2QynbwGDfvfLnenf643ViCV8MRBqdX6VtKfnxzl -IYzAdWuYJDwyKVOvDBOgWSd8SWW9aqly0qZFIrTCFmUlsecTYXIn7J8VsoWX54Xf -Bp8VNy3/AgMBAAECggEATzN4o7GKnast/hg/lU9/gEAUKQlHMgvp1woalHy1FsUl -QBzqGzoTlr/Zudkhr/Gg1GCVH0Gn+2n//7aFlvohoeNDGPa+rijUDRpxFDUBhO4c -6eXOfkedg2DDgBqBCYaQeOm+P8vGMCd3YBF1GiFJqgfHaIecWYeufJsmOSrGuFvK -1OvHpvg4/FLLQqgVcVO812kD4UwSOKnZVnPuZ3pzQviUZvO8ZxI/LkzQB1EdH6u3 -rBtiGslYkiKl5cGpH39/Dx2nKhHfvSnkfsm7koB00Bl41yy61GPwdl4XUwg8LUhX -TbsuoIPGTJX/2FUMn0UnAdDJm29hE4eyHyYOhew8gQKBgQDlAeUcnFr9uxe0i7cg -6ctJlNIKJjlA1tH4qIMEytdn06STo9g2j8X5HVE0FX/3+gAYDtEVICTF66w8Y474 -aeazvf+TCfkxtEOiH2afvaNkIkfzKR0ceB48DECT0DCF7xha5rJVf/W4GpCz2WkZ -ojDzw5ZVvzbx/FaF9A/IseJ63wKBgQDMaSjiephhdlCERGPdwWMg3AfthEX/VHM0 -YugbVjjYjDbn2pMkntW2hUuVXP8HD+9DnQZo0/c/hxe28Q5b+2fjZephdctnY8tL -XWbaEerM2lxEjmrpA4jYTBZJ9nMsxkEYHGHb5I586aS2YaZ12e7DoKMFdl0EZzvi -zGPIxSzQ4QKBgAxVv8t8uIH2M96rr997+FEsTOvzBx5w87pbCUOW0WdsRO8W4ix+ -LgGvDJKrncrzklG5apWit5hZi1ttWWQUADMqRrvay6tbtFDlNBfilQxttEZqroC8 -D5TYbBoKGrL8H+m1h2GHlOqns6ecTEbvL4fRvyU7OXBrURXCAZ+jxTktAoGACbQI -O9AEAcRjCBRTBUjT0tB/E9hOllNE8LytNfb+1dC6HoFysK9Vh8eGEf4LISOxgO0o -S7ucJgjcqFODEfy6LsI8wQmdcTf8g4RYiIuHMNhAvwRfsNX5HgNmn3Yye3Khzmoy -fwS3etiAeCPkif2hZunuMykuOzJHVnnLVtF9UiECgYEA41d7FgUcnfPIyA5xLg7K -lRgjFMsc68uzoCBQww2kio0HNJpdOPBJlg6oHHfYKriv2r9793jETRVwjSNPlKZb -vqm9yhnbXuahYBZSgdo2W+NbhP6IbJ0vrF4t9g6byjancQptaCjNIr9St9g+Ugly -8m0n3gIT/+Lr+it63cgk8SA= ------END PRIVATE KEY----- diff --git a/sources/hv-collector-ssl/src/test/resources/ssl/server.ks.pkcs12 b/sources/hv-collector-ssl/src/test/resources/ssl/server.ks.pkcs12 deleted file mode 100644 index a97eb65a..00000000 Binary files a/sources/hv-collector-ssl/src/test/resources/ssl/server.ks.pkcs12 and /dev/null differ diff --git a/sources/hv-collector-ssl/src/test/resources/ssl/trust.pkcs12 b/sources/hv-collector-ssl/src/test/resources/ssl/trust.pkcs12 deleted file mode 100644 index 01b61373..00000000 Binary files a/sources/hv-collector-ssl/src/test/resources/ssl/trust.pkcs12 and /dev/null differ diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/ArgXnfSimulatorConfiguration.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/ArgXnfSimulatorConfiguration.kt index 7fa23f7f..d9cbbaa8 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/ArgXnfSimulatorConfiguration.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/ArgXnfSimulatorConfiguration.kt @@ -36,7 +36,6 @@ import org.onap.dcae.collectors.veshv.commandline.CommandLineOption.VES_HV_PORT import org.onap.dcae.collectors.veshv.commandline.intValue import org.onap.dcae.collectors.veshv.commandline.stringValue import org.onap.dcae.collectors.veshv.domain.WireFrameMessage -import org.onap.dcae.collectors.veshv.ssl.boundary.createSecurityConfigurationProvider import org.onap.dcae.collectors.veshv.utils.arrow.OptionUtils.binding import org.onap.dcae.collectors.veshv.utils.arrow.doOnFailure import org.onap.dcae.collectors.veshv.utils.logging.Logger diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtils.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtils.kt new file mode 100644 index 00000000..7678fdbb --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtils.kt @@ -0,0 +1,72 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.simulators.xnf.impl.config + + +import arrow.core.None +import arrow.core.Some +import arrow.core.Try +import org.apache.commons.cli.CommandLine +import org.onap.dcae.collectors.veshv.commandline.CommandLineOption +import org.onap.dcae.collectors.veshv.commandline.hasOption +import org.onap.dcae.collectors.veshv.commandline.stringValue +import org.onap.dcae.collectors.veshv.ssl.boundary.SecurityConfiguration +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 java.nio.file.Paths + +/** + * @author Piotr Jaszczyk + * @since September 2018 + */ + +const val KEY_STORE_FILE = "/etc/ves-hv/server.p12" +const val KEY_STORE_PASSWORD_FILE = "/etc/ves-hv/server.pass" +const val TRUST_STORE_FILE = "/etc/ves-hv/trust.p12" +const val TRUST_STORE_PASSWORD_FILE = "/etc/ves-hv/trust.pass" + +fun createSecurityConfigurationProvider(cmdLine: CommandLine): Try<() -> SecurityConfiguration> = + if (shouldDisableSsl(cmdLine)) + Try { { disabledSecurityConfiguration() } } + else + Try { { enabledSecurityConfiguration(cmdLine) } } + +private fun shouldDisableSsl(cmdLine: CommandLine) = cmdLine.hasOption(CommandLineOption.SSL_DISABLE) + +private fun disabledSecurityConfiguration() = SecurityConfiguration(None) + +private fun enabledSecurityConfiguration(cmdLine: CommandLine): SecurityConfiguration { + val ksFile = cmdLine.stringValue(CommandLineOption.KEY_STORE_FILE, KEY_STORE_FILE) + val ksPass = cmdLine.stringValue(CommandLineOption.KEY_STORE_PASSWORD_FILE, KEY_STORE_PASSWORD_FILE) + val tsFile = cmdLine.stringValue(CommandLineOption.TRUST_STORE_FILE, TRUST_STORE_FILE) + val tsPass = cmdLine.stringValue(CommandLineOption.TRUST_STORE_PASSWORD_FILE, TRUST_STORE_PASSWORD_FILE) + + val keys = ImmutableSecurityKeys.builder() + .keyStore(ImmutableSecurityKeysStore.of(pathFromFile(ksFile))) + .keyStorePassword(Passwords.fromPath(pathFromFile(ksPass))) + .trustStore(ImmutableSecurityKeysStore.of(pathFromFile(tsFile))) + .trustStorePassword(Passwords.fromPath(pathFromFile(tsPass))) + .build() + + return SecurityConfiguration(Some(keys)) +} + +private fun pathFromFile(file: String) = Paths.get(file) diff --git a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt index 4fcb1809..04a0c14a 100644 --- a/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt +++ b/sources/hv-collector-xnf-simulator/src/main/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/main.kt @@ -20,7 +20,6 @@ package org.onap.dcae.collectors.veshv.simulators.xnf import io.vavr.collection.HashSet -import org.onap.dcae.collectors.veshv.commandline.handleWrongArgumentError import org.onap.dcae.collectors.veshv.commandline.handleWrongArgumentErrorCurried import org.onap.dcae.collectors.veshv.healthcheck.api.HealthDescription import org.onap.dcae.collectors.veshv.healthcheck.api.HealthState diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt deleted file mode 100644 index 14061532..00000000 --- a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/HvVesClientTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2019 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.main - -import com.nhaarman.mockitokotlin2.any -import com.nhaarman.mockitokotlin2.eq -import com.nhaarman.mockitokotlin2.mock -import com.nhaarman.mockitokotlin2.verify -import com.nhaarman.mockitokotlin2.whenever -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.HvVesClient -import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.HvVesProducer -import org.onap.ves.VesEventOuterClass -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import java.nio.ByteBuffer - - -/** - * @author Jakub Dudycz - * @since February 2019 - */ -internal class HvVesClientTest : Spek({ - describe("HvVesClient") { - val hvVesProducer: HvVesProducer = mock() - val cut = HvVesClient(hvVesProducer) - - describe("handling raw message stream") { - - val rawMessages = Flux.empty() - whenever(hvVesProducer.sendRaw(any(), any())).thenReturn(Mono.empty()) - cut.sendRawPayload(rawMessages) - - it("should perform sending operation") { - verify(hvVesProducer).sendRaw(eq(rawMessages), any()) - } - } - } -}) \ No newline at end of file diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/OngoingSimulationsTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/OngoingSimulationsTest.kt deleted file mode 100644 index 325d3bb5..00000000 --- a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/OngoingSimulationsTest.kt +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.main - -import org.assertj.core.api.Assertions.assertThat -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.given -import org.jetbrains.spek.api.dsl.it -import org.jetbrains.spek.api.dsl.on -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.OngoingSimulations -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusFailure -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusNotFound -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusOngoing -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.StatusSuccess -import org.onap.dcae.collectors.veshv.tests.utils.waitUntilSucceeds -import reactor.core.publisher.Mono -import reactor.core.scheduler.Schedulers -import java.util.* - -/** - * @author Piotr Jaszczyk - * @since September 2018 - */ -internal class OngoingSimulationsTest : Spek({ - val scheduler = Schedulers.single() - val cut = OngoingSimulations(scheduler) - - describe("simulations repository") { - given("not existing task task id") { - val id = UUID.randomUUID() - - on("asking for status") { - val result = cut.status(id) - - it("should have 'not found' status") { - assertThat(result).isEqualTo(StatusNotFound) - } - } - } - - given("no tasks") { - on("quering about any pending task") { - it("should return false") { - assertThat(cut.isAnySimulationPending()).isFalse() - } - } - } - - given("never ending task") { - val task = neverendingTask() - - on("startAsynchronousSimulation") { - val result = cut.startAsynchronousSimulation(task) - - it("should have ongoing status") { - assertThat(cut.status(result)).isEqualTo(StatusOngoing) - } - - it("should return true when asked about any pending tasks") { - assertThat(cut.isAnySimulationPending()).isTrue() - } - } - } - - given("failing task") { - val (cause, task) = failingTask() - - on("startAsynchronousSimulation") { - val taskID = cut.startAsynchronousSimulation(task) - - it("should have failing status") { - waitUntilSucceeds { - assertThat(cut.status(taskID)).isEqualTo(StatusFailure(cause)) - } - } - - it("should return false when asked about any pending tasks") { - waitUntilSucceeds { - assertThat(cut.isAnySimulationPending()).isFalse() - } - } - } - } - - given("successful task") { - val task = succesfulTask() - - on("startAsynchronousSimulation") { - val taskID = cut.startAsynchronousSimulation(task) - - it("should have successful status") { - waitUntilSucceeds { - assertThat(cut.status(taskID)).isEqualTo(StatusSuccess) - } - } - - it("should return false when asked about any pending tasks") { - waitUntilSucceeds { - assertThat(cut.isAnySimulationPending()).isFalse() - } - } - } - } - - afterGroup { - scheduler.dispose() - } - } - - afterEachTest { cut.clear() } -}) - -private fun neverendingTask() = Mono.never() - -private fun succesfulTask(): Mono = Mono.empty() - .doOnSuccess { - println("great success") - } - -private fun failingTask(): Pair> { - val cause = RuntimeException("facepalm") - val task = Mono.error(cause) - return Pair(cause, task) -} diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt deleted file mode 100644 index ea0628c1..00000000 --- a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/main/XnfSimulatorTest.kt +++ /dev/null @@ -1,135 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018-2019 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.main - -import arrow.core.Left -import arrow.core.None -import arrow.core.Right -import com.nhaarman.mockitokotlin2.any -import com.nhaarman.mockitokotlin2.eq -import com.nhaarman.mockitokotlin2.mock -import com.nhaarman.mockitokotlin2.verify -import com.nhaarman.mockitokotlin2.whenever -import org.jetbrains.spek.api.Spek -import org.jetbrains.spek.api.dsl.describe -import org.jetbrains.spek.api.dsl.it -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.XnfSimulator -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.HvVesClient -import org.onap.dcae.collectors.veshv.simulators.xnf.impl.factory.ClientFactory -import org.onap.dcae.collectors.veshv.tests.utils.Assertions.assertThat -import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser -import org.onap.dcae.collectors.veshv.ves.message.generator.api.ParsingError -import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventParameters -import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType -import org.onap.dcae.collectors.veshv.ves.message.generator.factory.MessageGeneratorFactory -import org.onap.dcae.collectors.veshv.ves.message.generator.generators.VesEventGenerator -import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.options.PayloadType -import org.onap.ves.VesEventOuterClass -import org.onap.ves.VesEventOuterClass.CommonEventHeader -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import java.io.ByteArrayInputStream - -/** - * @author Piotr Jaszczyk - * @since September 2018 - */ -internal class XnfSimulatorTest : Spek({ - lateinit var cut: XnfSimulator - lateinit var clientFactory: ClientFactory - lateinit var messageParametersParser: MessageParametersParser - lateinit var generatorFactory: MessageGeneratorFactory - - beforeEachTest { - clientFactory = mock() - messageParametersParser = mock() - generatorFactory = mock() - cut = XnfSimulator(clientFactory, generatorFactory, messageParametersParser) - } - - describe("startSimulation") { - it("should fail when empty input stream") { - // given - val emptyInputStream = ByteArrayInputStream(byteArrayOf()) - - // when - val result = cut.startSimulation(emptyInputStream) - - // then - assertThat(result).isLeft() - } - - it("should fail when invalid JSON") { - // given - val invalidJson = "invalid json".byteInputStream() - - // when - val result = cut.startSimulation(invalidJson) - - // then - assertThat(result).isLeft() - } - - it("should fail when JSON syntax is valid but content is invalid") { - // given - val json = "[1,2,3]".byteInputStream() - val cause = ParsingError("epic fail", None) - whenever(messageParametersParser.parse(any())).thenReturn( - Left(cause)) - - // when - val result = cut.startSimulation(json) - - // then - assertThat(result).left().isEqualTo(cause) - } - - it("should return generated ves messages") { - // given - val vesEventGenerator: VesEventGenerator = mock() - val vesClient: HvVesClient = mock() - - val json = "[true]".byteInputStream() - - val vesEventParams = VesEventParameters( - CommonEventHeader.getDefaultInstance(), - VesEventType.VALID, - 1 - ) - val messageParams = listOf(vesEventParams) - - val generatedMessages = Flux.empty() - - - whenever(messageParametersParser.parse(any())).thenReturn(Right(messageParams)) - whenever(generatorFactory.createVesEventGenerator()).thenReturn(vesEventGenerator) - whenever(vesEventGenerator.createMessageFlux(vesEventParams)).thenReturn(generatedMessages) - whenever(clientFactory.create()).thenReturn(vesClient) - - whenever(vesClient.sendRawPayload(any(), eq(PayloadType.PROTOBUF))).thenReturn(Mono.just(Unit)) - - // when - cut.startSimulation(json).map { it.block() } - - // then - verify(vesClient).sendRawPayload(any(), eq(PayloadType.PROTOBUF)) - } - } -}) \ No newline at end of file diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/OngoingSimulationsTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/OngoingSimulationsTest.kt new file mode 100644 index 00000000..cb604626 --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/OngoingSimulationsTest.kt @@ -0,0 +1,137 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.simulators.xnf.impl + +import org.assertj.core.api.Assertions.assertThat +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.given +import org.jetbrains.spek.api.dsl.it +import org.jetbrains.spek.api.dsl.on +import org.onap.dcae.collectors.veshv.tests.utils.waitUntilSucceeds +import reactor.core.publisher.Mono +import reactor.core.scheduler.Schedulers +import java.util.* + +/** + * @author Piotr Jaszczyk + * @since September 2018 + */ +internal class OngoingSimulationsTest : Spek({ + val scheduler = Schedulers.single() + val cut = OngoingSimulations(scheduler) + + describe("simulations repository") { + given("not existing task task id") { + val id = UUID.randomUUID() + + on("asking for status") { + val result = cut.status(id) + + it("should have 'not found' status") { + assertThat(result).isEqualTo(StatusNotFound) + } + } + } + + given("no tasks") { + on("quering about any pending task") { + it("should return false") { + assertThat(cut.isAnySimulationPending()).isFalse() + } + } + } + + given("never ending task") { + val task = neverendingTask() + + on("startAsynchronousSimulation") { + val result = cut.startAsynchronousSimulation(task) + + it("should have ongoing status") { + assertThat(cut.status(result)).isEqualTo(StatusOngoing) + } + + it("should return true when asked about any pending tasks") { + assertThat(cut.isAnySimulationPending()).isTrue() + } + } + } + + given("failing task") { + val (cause, task) = failingTask() + + on("startAsynchronousSimulation") { + val taskID = cut.startAsynchronousSimulation(task) + + it("should have failing status") { + waitUntilSucceeds { + assertThat(cut.status(taskID)).isEqualTo(StatusFailure(cause)) + } + } + + it("should return false when asked about any pending tasks") { + waitUntilSucceeds { + assertThat(cut.isAnySimulationPending()).isFalse() + } + } + } + } + + given("successful task") { + val task = succesfulTask() + + on("startAsynchronousSimulation") { + val taskID = cut.startAsynchronousSimulation(task) + + it("should have successful status") { + waitUntilSucceeds { + assertThat(cut.status(taskID)).isEqualTo(StatusSuccess) + } + } + + it("should return false when asked about any pending tasks") { + waitUntilSucceeds { + assertThat(cut.isAnySimulationPending()).isFalse() + } + } + } + } + + afterGroup { + scheduler.dispose() + } + } + + afterEachTest { cut.clear() } +}) + +private fun neverendingTask() = Mono.never() + +private fun succesfulTask(): Mono = Mono.empty() + .doOnSuccess { + println("great success") + } + +private fun failingTask(): Pair> { + val cause = RuntimeException("facepalm") + val task = Mono.error(cause) + return Pair(cause, task) +} diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulatorTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulatorTest.kt new file mode 100644 index 00000000..11ce0b3f --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/XnfSimulatorTest.kt @@ -0,0 +1,134 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018-2019 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.simulators.xnf.impl + +import arrow.core.Left +import arrow.core.None +import arrow.core.Right +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.eq +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.HvVesClient +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.factory.ClientFactory +import org.onap.dcae.collectors.veshv.tests.utils.Assertions.assertThat +import org.onap.dcae.collectors.veshv.ves.message.generator.api.MessageParametersParser +import org.onap.dcae.collectors.veshv.ves.message.generator.api.ParsingError +import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventParameters +import org.onap.dcae.collectors.veshv.ves.message.generator.api.VesEventType +import org.onap.dcae.collectors.veshv.ves.message.generator.factory.MessageGeneratorFactory +import org.onap.dcae.collectors.veshv.ves.message.generator.generators.VesEventGenerator +import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.options.PayloadType +import org.onap.ves.VesEventOuterClass +import org.onap.ves.VesEventOuterClass.CommonEventHeader +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import java.io.ByteArrayInputStream + +/** + * @author Piotr Jaszczyk + * @since September 2018 + */ +internal class XnfSimulatorTest : Spek({ + lateinit var cut: XnfSimulator + lateinit var clientFactory: ClientFactory + lateinit var messageParametersParser: MessageParametersParser + lateinit var generatorFactory: MessageGeneratorFactory + + beforeEachTest { + clientFactory = mock() + messageParametersParser = mock() + generatorFactory = mock() + cut = XnfSimulator(clientFactory, generatorFactory, messageParametersParser) + } + + describe("startSimulation") { + it("should fail when empty input stream") { + // given + val emptyInputStream = ByteArrayInputStream(byteArrayOf()) + + // when + val result = cut.startSimulation(emptyInputStream) + + // then + assertThat(result).isLeft() + } + + it("should fail when invalid JSON") { + // given + val invalidJson = "invalid json".byteInputStream() + + // when + val result = cut.startSimulation(invalidJson) + + // then + assertThat(result).isLeft() + } + + it("should fail when JSON syntax is valid but content is invalid") { + // given + val json = "[1,2,3]".byteInputStream() + val cause = ParsingError("epic fail", None) + whenever(messageParametersParser.parse(any())).thenReturn( + Left(cause)) + + // when + val result = cut.startSimulation(json) + + // then + assertThat(result).left().isEqualTo(cause) + } + + it("should return generated ves messages") { + // given + val vesEventGenerator: VesEventGenerator = mock() + val vesClient: HvVesClient = mock() + + val json = "[true]".byteInputStream() + + val vesEventParams = VesEventParameters( + CommonEventHeader.getDefaultInstance(), + VesEventType.VALID, + 1 + ) + val messageParams = listOf(vesEventParams) + + val generatedMessages = Flux.empty() + + + whenever(messageParametersParser.parse(any())).thenReturn(Right(messageParams)) + whenever(generatorFactory.createVesEventGenerator()).thenReturn(vesEventGenerator) + whenever(vesEventGenerator.createMessageFlux(vesEventParams)).thenReturn(generatedMessages) + whenever(clientFactory.create()).thenReturn(vesClient) + + whenever(vesClient.sendRawPayload(any(), eq(PayloadType.PROTOBUF))).thenReturn(Mono.just(Unit)) + + // when + cut.startSimulation(json).map { it.block() } + + // then + verify(vesClient).sendRawPayload(any(), eq(PayloadType.PROTOBUF)) + } + } +}) \ No newline at end of file diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/HvVesClientTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/HvVesClientTest.kt new file mode 100644 index 00000000..5e6cb981 --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/adapters/HvVesClientTest.kt @@ -0,0 +1,58 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2019 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters + +import com.nhaarman.mockitokotlin2.any +import com.nhaarman.mockitokotlin2.eq +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it +import org.onap.dcae.collectors.veshv.simulators.xnf.impl.adapters.HvVesClient +import org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api.HvVesProducer +import org.onap.ves.VesEventOuterClass +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import java.nio.ByteBuffer + + +/** + * @author Jakub Dudycz + * @since February 2019 + */ +internal class HvVesClientTest : Spek({ + describe("HvVesClient") { + val hvVesProducer: HvVesProducer = mock() + val cut = HvVesClient(hvVesProducer) + + describe("handling raw message stream") { + + val rawMessages = Flux.empty() + whenever(hvVesProducer.sendRaw(any(), any())).thenReturn(Mono.empty()) + cut.sendRawPayload(rawMessages) + + it("should perform sending operation") { + verify(hvVesProducer).sendRaw(eq(rawMessages), any()) + } + } + } +}) \ No newline at end of file diff --git a/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtilsTest.kt b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtilsTest.kt new file mode 100644 index 00000000..631ec7bf --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/kotlin/org/onap/dcae/collectors/veshv/simulators/xnf/impl/config/SslUtilsTest.kt @@ -0,0 +1,76 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2019 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.dcae.collectors.veshv.simulators.xnf.impl.config + +import com.nhaarman.mockitokotlin2.doReturn +import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever +import org.apache.commons.cli.CommandLine +import org.assertj.core.api.Assertions.assertThat +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it +import org.jetbrains.spek.api.dsl.on +import org.onap.dcae.collectors.veshv.commandline.CommandLineOption +import org.onap.dcae.collectors.veshv.commandline.hasOption +import org.onap.dcae.collectors.veshv.commandline.stringValue +import java.nio.file.Paths + + +internal object SslUtilsTest : Spek({ + + describe("creating securty configuration provider") { + + on("command line without ssl disable") { + val passwordFile = resourcePathAsString("/ssl/password") + val commandLine: CommandLine = mock() + whenever(commandLine.hasOption(CommandLineOption.SSL_DISABLE)).doReturn(false) + whenever(commandLine.stringValue(CommandLineOption.TRUST_STORE_PASSWORD_FILE, TRUST_STORE_PASSWORD_FILE)) + .doReturn(passwordFile) + whenever(commandLine.stringValue(CommandLineOption.KEY_STORE_PASSWORD_FILE, KEY_STORE_PASSWORD_FILE)) + .doReturn(passwordFile) + + it("should create configuration with some keys") { + val configuration = createSecurityConfigurationProvider(commandLine) + + verify(commandLine).hasOption(CommandLineOption.SSL_DISABLE) + assertThat(configuration.isSuccess()).isTrue() + configuration.map { assertThat(it().keys.isDefined()).isTrue() } + } + } + + on("command line with ssl disabled") { + val commandLine: CommandLine = mock() + whenever(commandLine.hasOption(CommandLineOption.SSL_DISABLE)).doReturn(true) + + it("should create configuration without keys") { + val configuration = createSecurityConfigurationProvider(commandLine) + + verify(commandLine).hasOption(CommandLineOption.SSL_DISABLE) + assertThat(configuration.isSuccess()).isTrue() + configuration.map { assertThat(it().keys.isEmpty()).isTrue() } + } + } + } +}) + +private fun resourcePathAsString(resource: String) = + Paths.get(SslUtilsTest::class.java.getResource(resource).toURI()).toString() diff --git a/sources/hv-collector-xnf-simulator/src/test/resources/ssl/ca.crt b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/ca.crt new file mode 100644 index 00000000..f9a05b90 --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/ca.crt @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDbDCCAlSgAwIBAgIJAMsh09jY3jSBMA0GCSqGSIb3DQEBCwUAMEsxCzAJBgNV +BAYTAlBMMQswCQYDVQQIDAJETDEQMA4GA1UEBwwHV3JvY2xhdzEOMAwGA1UECgwF +Tm9raWExDTALBgNVBAsMBE1BTk8wHhcNMTgwODEzMTE1OTE5WhcNMTkwODEzMTE1 +OTE5WjBLMQswCQYDVQQGEwJQTDELMAkGA1UECAwCREwxEDAOBgNVBAcMB1dyb2Ns +YXcxDjAMBgNVBAoMBU5va2lhMQ0wCwYDVQQLDARNQU5PMIIBIjANBgkqhkiG9w0B +AQEFAAOCAQ8AMIIBCgKCAQEAyIs4sk5SlBRltDHZDDIGHdazzdduPRKdDBMUTE5i +++iZe1MU9WnbPWgbnfj/1DN+VbbJEa32agDXBhS9mPiSrflDe8oqPPk12miiflsY +TxGxY1bjH58kRNey164fPznzc9LqKqV1brUPktgBkHumM4zPVZYue5cp1T2FiWcE +nFdqOKK2F0mdby+Pim9JHil34YcvavOlMXULkqayR7hxfUIAmMZtl59BKVx9BcKD +9Sv9TQYRIYHhymrKnwIb8RolDaDdVUnr2ryREjZ8WfoBsOpraIYDUjKijF5FlgLs +Fp8wcIflF6JyMbtchTm5acQZkcqK1AGYTD1wxT33E2pdDQIDAQABo1MwUTAdBgNV +HQ4EFgQUOL9AR068MxqYCsKkEfgDzF2HrY8wHwYDVR0jBBgwFoAUOL9AR068MxqY +CsKkEfgDzF2HrY8wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEA +OXNDDqrk8bTJfy78mkMZame/bLEUQ2h4EvWT6trd5XYNfPwQW/u6laLJAtLFbzth +lpNBRK//sK+AYgwDURq0HcW5YczhgzZbfG9ab1J/7GUrFJh+DHL3bNL1YFX84JbI +coUbxaJFkmIvlQDLWDYfpQ/gNwUbuUPZjGZC2bWobZw9sRC+e51TIoAmgZwvTElC +v3vD2BwbIs7C4ylrIQU9Q1rY17MeWH9m8ZhEX1C4W4+N54V6jJ7czE9HQEnapeEu +5rmEoDqP191x+tOxp/Xg8j+wcAK/dVy1Q3xQQZCW84rv0TBHbdaAPamBLUzHeW3W +F7BpnVhn1NfYVOKx5W0NfA== +-----END CERTIFICATE----- diff --git a/sources/hv-collector-xnf-simulator/src/test/resources/ssl/password b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/password new file mode 100644 index 00000000..e69c2de9 --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/password @@ -0,0 +1 @@ +onaponap \ No newline at end of file diff --git a/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.crt b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.crt new file mode 100644 index 00000000..2b06108b --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.crt @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIDEjCCAfoCCQCId29lGbm5LjANBgkqhkiG9w0BAQsFADBLMQswCQYDVQQGEwJQ +TDELMAkGA1UECAwCREwxEDAOBgNVBAcMB1dyb2NsYXcxDjAMBgNVBAoMBU5va2lh +MQ0wCwYDVQQLDARNQU5PMB4XDTE4MDgxMzEyMDAyNFoXDTE5MDgwODEyMDAyNFow +SzELMAkGA1UEBhMCUEwxCzAJBgNVBAgMAkRMMRAwDgYDVQQHDAdXcm9jbGF3MQ4w +DAYDVQQKDAVOb2tpYTENMAsGA1UECwwETUFOTzCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBALbblOyqeJayotBiY6aZnGWnMHCHNTileJF8hkFS5P5qM9BU +XH7NW/p5wSNcQWBB81HrRVneHpm6zfZtUPtcqXC4vpTk/sy3WT8rlEU+uv1YYVP8 +r0jxXr1WZ8sGcxOjhiMMRpMqImoALRak3ombtktfMc2Yeab4J25941wpDSQoUjT8 +LlXhfyjbBijum0LY+cqsuV5qk2qrzo0ZLD6m51aaWEyeysQ/3JanYKvPZDKdvAYN ++98ud6d/rjdWIJXwxEGp1fpW0p+fHOUhjMB1a5gkPDIpU68ME6BZJ3xJZb1qqXLS +pkUitMIWZSWx5xNhcifsnxWyhZfnhd8GnxU3Lf8CAwEAATANBgkqhkiG9w0BAQsF +AAOCAQEAJCrPdc8R7kBOmeIPyVX8QBOsrVTBBDzhskpi51nMsAKvcGjtYdXknYPj +bw3YVASE2efrq5QWHC0maIxDAHzI/kmWGH8F0s8S6QRH/7fstvxaNaSArzQB/thW +qIWs7AufUSsLMwtcXQ6KdYNbnaMwTynuuK+ANilcLvV8GxRAzXgFdoWZ2OuJRyzu +BWQZS49WanyqX1kDLMsrLtdJyl/yVEfsmDcUyhapuuGwtconkWK/CVrJlV1vh1Z+ +Svh9IfvAF7WPPpGsM/y9+hGNtK6sPVUKl4acBzIAv6aN1QS5H4zRvtbwv7xpUp4M +P84PY3lv1X3NJCGrfVByh2lFWParKA== +-----END CERTIFICATE----- diff --git a/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.key b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.key new file mode 100644 index 00000000..40e25932 --- /dev/null +++ b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC225TsqniWsqLQ +YmOmmZxlpzBwhzU4pXiRfIZBUuT+ajPQVFx+zVv6ecEjXEFgQfNR60VZ3h6Zus32 +bVD7XKlwuL6U5P7Mt1k/K5RFPrr9WGFT/K9I8V69VmfLBnMTo4YjDEaTKiJqAC0W +pN6Jm7ZLXzHNmHmm+CdufeNcKQ0kKFI0/C5V4X8o2wYo7ptC2PnKrLleapNqq86N +GSw+pudWmlhMnsrEP9yWp2Crz2QynbwGDfvfLnenf643ViCV8MRBqdX6VtKfnxzl +IYzAdWuYJDwyKVOvDBOgWSd8SWW9aqly0qZFIrTCFmUlsecTYXIn7J8VsoWX54Xf +Bp8VNy3/AgMBAAECggEATzN4o7GKnast/hg/lU9/gEAUKQlHMgvp1woalHy1FsUl +QBzqGzoTlr/Zudkhr/Gg1GCVH0Gn+2n//7aFlvohoeNDGPa+rijUDRpxFDUBhO4c +6eXOfkedg2DDgBqBCYaQeOm+P8vGMCd3YBF1GiFJqgfHaIecWYeufJsmOSrGuFvK +1OvHpvg4/FLLQqgVcVO812kD4UwSOKnZVnPuZ3pzQviUZvO8ZxI/LkzQB1EdH6u3 +rBtiGslYkiKl5cGpH39/Dx2nKhHfvSnkfsm7koB00Bl41yy61GPwdl4XUwg8LUhX +TbsuoIPGTJX/2FUMn0UnAdDJm29hE4eyHyYOhew8gQKBgQDlAeUcnFr9uxe0i7cg +6ctJlNIKJjlA1tH4qIMEytdn06STo9g2j8X5HVE0FX/3+gAYDtEVICTF66w8Y474 +aeazvf+TCfkxtEOiH2afvaNkIkfzKR0ceB48DECT0DCF7xha5rJVf/W4GpCz2WkZ +ojDzw5ZVvzbx/FaF9A/IseJ63wKBgQDMaSjiephhdlCERGPdwWMg3AfthEX/VHM0 +YugbVjjYjDbn2pMkntW2hUuVXP8HD+9DnQZo0/c/hxe28Q5b+2fjZephdctnY8tL +XWbaEerM2lxEjmrpA4jYTBZJ9nMsxkEYHGHb5I586aS2YaZ12e7DoKMFdl0EZzvi +zGPIxSzQ4QKBgAxVv8t8uIH2M96rr997+FEsTOvzBx5w87pbCUOW0WdsRO8W4ix+ +LgGvDJKrncrzklG5apWit5hZi1ttWWQUADMqRrvay6tbtFDlNBfilQxttEZqroC8 +D5TYbBoKGrL8H+m1h2GHlOqns6ecTEbvL4fRvyU7OXBrURXCAZ+jxTktAoGACbQI +O9AEAcRjCBRTBUjT0tB/E9hOllNE8LytNfb+1dC6HoFysK9Vh8eGEf4LISOxgO0o +S7ucJgjcqFODEfy6LsI8wQmdcTf8g4RYiIuHMNhAvwRfsNX5HgNmn3Yye3Khzmoy +fwS3etiAeCPkif2hZunuMykuOzJHVnnLVtF9UiECgYEA41d7FgUcnfPIyA5xLg7K +lRgjFMsc68uzoCBQww2kio0HNJpdOPBJlg6oHHfYKriv2r9793jETRVwjSNPlKZb +vqm9yhnbXuahYBZSgdo2W+NbhP6IbJ0vrF4t9g6byjancQptaCjNIr9St9g+Ugly +8m0n3gIT/+Lr+it63cgk8SA= +-----END PRIVATE KEY----- diff --git a/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.ks.pkcs12 b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.ks.pkcs12 new file mode 100644 index 00000000..a97eb65a Binary files /dev/null and b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/server.ks.pkcs12 differ diff --git a/sources/hv-collector-xnf-simulator/src/test/resources/ssl/trust.pkcs12 b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/trust.pkcs12 new file mode 100644 index 00000000..01b61373 Binary files /dev/null and b/sources/hv-collector-xnf-simulator/src/test/resources/ssl/trust.pkcs12 differ -- cgit 1.2.3-korg