aboutsummaryrefslogtreecommitdiffstats
path: root/sources/hv-collector-configuration/src/test
diff options
context:
space:
mode:
authorFilip Krzywka <filip.krzywka@nokia.com>2019-04-05 11:10:46 +0200
committerFilip Krzywka <filip.krzywka@nokia.com>2019-04-08 11:17:25 +0200
commite55809c0219be0898138c436d82ceba212b92df9 (patch)
tree0651e8a0a6a249d26bcde659d7844e1ad1de8dbe /sources/hv-collector-configuration/src/test
parent8e2a52b2aebf8f968da02265affb6d01b0a1c166 (diff)
Flatten configuration structure
Change-Id: I9a5a53f3c4cf0973d071f2bc6962016b5613972d Issue-ID: DCAEGEN2-710 Signed-off-by: Filip Krzywka <filip.krzywka@nokia.com>
Diffstat (limited to 'sources/hv-collector-configuration/src/test')
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt2
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt28
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt187
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt48
-rw-r--r--sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/gsonadapters/SecurityAdapterTest.kt135
-rw-r--r--sources/hv-collector-configuration/src/test/resources/sampleConfig.json31
6 files changed, 149 insertions, 282 deletions
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt
index 0cbc0e4a..d5fe588e 100644
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/CbsConfigurationProviderTest.kt
@@ -78,7 +78,7 @@ internal object CbsConfigurationProviderTest : Spek({
StepVerifier.create(configProvider().take(1))
.consumeNextWith {
- val routes = it.collector.orNull()!!.routing.orNull()!!
+ val routes = it.routing.orNull()!!
val route1 = routes.elementAt(0)
val route2 = routes.elementAt(1)
val receivedSink1 = route1.sink
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt
index d5b18e68..bc61b57d 100644
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationMergerTest.kt
@@ -44,14 +44,14 @@ internal object ConfigurationMergerTest : Spek({
assertThat(result.logLevel).isEqualTo(Some(LogLevel.INFO))
}
+ val someListenPort = Some(45)
it("merges single embedded parameter into empty config") {
val actual = PartialConfiguration()
- val serverConfig = PartialServerConfig(listenPort = Some(45))
- val diff = PartialConfiguration(server = Some(serverConfig))
+ val diff = PartialConfiguration(listenPort = someListenPort)
val result = ConfigurationMerger().merge(actual, diff)
- assertThat(result.server).isEqualTo(Some(serverConfig))
+ assertThat(result.listenPort).isEqualTo(someListenPort)
}
it("merges single parameter into full config") {
@@ -69,16 +69,15 @@ internal object ConfigurationMergerTest : Spek({
val actual = FileConfigurationReader().loadConfig(
InputStreamReader(
FileConfigurationReaderTest.javaClass.getResourceAsStream("/sampleConfig.json")) as Reader)
- val serverConfig = PartialServerConfig(listenPort = Some(45))
- val diff = PartialConfiguration(server = Some(serverConfig))
+ val diff = PartialConfiguration(listenPort = someListenPort)
val result = ConfigurationMerger().merge(actual, diff)
- assertThat(result.server.orNull()?.listenPort).isEqualTo(serverConfig.listenPort)
- assertThat(result.server.orNull()?.idleTimeoutSec?.isEmpty()).isFalse()
- assertThat(result.server.orNull()?.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
- assertThat(result.server.orNull()?.maxPayloadSizeBytes?.isEmpty()).isFalse()
- assertThat(result.server.orNull()?.maxPayloadSizeBytes).isEqualTo(Some(512000))
+ assertThat(result.listenPort).isEqualTo(someListenPort)
+ assertThat(result.idleTimeoutSec.isEmpty()).isFalse()
+ assertThat(result.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
+ assertThat(result.maxPayloadSizeBytes.isEmpty()).isFalse()
+ assertThat(result.maxPayloadSizeBytes).isEqualTo(Some(1048576))
}
it("merges full config into single parameter") {
@@ -90,12 +89,11 @@ internal object ConfigurationMergerTest : Spek({
val result = ConfigurationMerger().merge(actual, diff)
assertThat(result.logLevel).isEqualTo(Some(LogLevel.ERROR))
- assertThat(result.server.isEmpty()).isFalse()
- assertThat(result.server.orNull()?.maxPayloadSizeBytes).isEqualTo(Some(512000))
- assertThat(result.server.orNull()?.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
+ assertThat(result.maxPayloadSizeBytes).isEqualTo(Some(1048576))
+ assertThat(result.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
- assertThat(result.security.isEmpty()).isFalse()
- assertThat(result.cbs.isEmpty()).isFalse()
+ assertThat(result.keyStoreFile.isEmpty()).isFalse()
+ assertThat(result.firstRequestDelaySec.isEmpty()).isFalse()
}
}
})
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt
index 682bec5a..e43acfa3 100644
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/ConfigurationValidatorTest.kt
@@ -23,29 +23,26 @@ import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.getOrElse
-import com.nhaarman.mockitokotlin2.mock
-import com.nhaarman.mockitokotlin2.verify
-import com.nhaarman.mockitokotlin2.whenever
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
-import org.assertj.core.api.ObjectAssert
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.config.api.model.Routing
import org.onap.dcae.collectors.veshv.config.impl.ConfigurationValidator.Companion.DEFAULT_LOG_LEVEL
-import org.onap.dcae.collectors.veshv.ssl.boundary.SecurityKeysPaths
import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys
+import java.io.File
import java.time.Duration
+
internal object ConfigurationValidatorTest : Spek({
describe("ConfigurationValidator") {
val cut = ConfigurationValidator()
describe("validating partial configuration with missing fields") {
val config = PartialConfiguration(
- Some(PartialServerConfig(listenPort = Some(1)))
+ listenPort = Some(1)
)
it("should return ValidationError") {
@@ -55,23 +52,8 @@ internal object ConfigurationValidatorTest : Spek({
}
describe("validating configuration with empty log level") {
- val config = PartialConfiguration(
- Some(PartialServerConfig(
- Some(1),
- Some(Duration.ofSeconds(2)),
- Some(3)
- )),
- Some(PartialCbsConfig(
- Some(Duration.ofSeconds(5)),
- Some(Duration.ofSeconds(3))
- )),
- Some(PartialSecurityConfig(
- Some(mock())
- )),
- Some(PartialCollectorConfig(
- someFromEmptyRouting
- )),
- None
+ val config = partialConfiguration(
+ logLevel = None
)
it("should use default log level") {
@@ -88,29 +70,19 @@ internal object ConfigurationValidatorTest : Spek({
}
describe("validating complete configuration") {
- val idleTimeoutSec = Duration.ofSeconds(10L)
- val firstReqDelaySec = Duration.ofSeconds(10L)
- val securityKeys = mock<SecurityKeysPaths>()
- val immutableSecurityKeys = mock<SecurityKeys>()
- whenever(securityKeys.asImmutableSecurityKeys()).thenReturn(immutableSecurityKeys)
-
val config = PartialConfiguration(
- Some(PartialServerConfig(
- Some(1),
- Some(idleTimeoutSec),
- Some(2)
- )),
- Some(PartialCbsConfig(
- Some(firstReqDelaySec),
- Some(Duration.ofSeconds(3))
- )),
- Some(PartialSecurityConfig(
- Some(securityKeys)
- )),
- Some(PartialCollectorConfig(
- someFromEmptyRouting
- )),
- Some(LogLevel.INFO)
+ listenPort = Some(defaultListenPort),
+ idleTimeoutSec = Some(defaultIdleTimeoutSec),
+ maxPayloadSizeBytes = Some(defaultMaxPayloadSizeBytes),
+ firstRequestDelaySec = Some(defaultFirstReqDelaySec),
+ requestIntervalSec = Some(defaultRequestIntervalSec),
+ sslDisable = Some(false),
+ keyStoreFile = Some(KEYSTORE),
+ keyStorePassword = Some(KEYSTORE_PASSWORD),
+ trustStoreFile = Some(TRUSTSTORE),
+ trustStorePassword = Some(TRUSTSTORE_PASSWORD),
+ routing = Some(emptyRouting),
+ logLevel = Some(LogLevel.TRACE)
)
it("should create valid configuration") {
@@ -120,46 +92,34 @@ internal object ConfigurationValidatorTest : Spek({
fail("Configuration should have been created successfully")
},
{
- assertThat(it.server.idleTimeout)
- .isEqualTo(idleTimeoutSec)
-
- verify(securityKeys).asImmutableSecurityKeys()
- assertThat(it.security.keys
- .getOrElse { fail("Should be immutableSecurityKeys") })
- .isEqualTo(immutableSecurityKeys)
-
- assertThat(it.cbs.firstRequestDelay)
- .isEqualTo(firstReqDelaySec)
-
- assertThat(it.collector.routing)
- .isEqualTo(emptyRouting)
+ assertThat(it.server.listenPort).isEqualTo(defaultListenPort)
+ assertThat(it.server.idleTimeout).isEqualTo(defaultIdleTimeoutSec)
+ assertThat(it.server.maxPayloadSizeBytes).isEqualTo(defaultMaxPayloadSizeBytes)
+
+ val securityKeys = it.security.keys
+ .getOrElse { fail("Should be immutableSecurityKeys") } as SecurityKeys
+ assertThat(securityKeys.keyStore().path()).isEqualTo(File(KEYSTORE).toPath())
+ assertThat(securityKeys.trustStore().path()).isEqualTo(File(TRUSTSTORE).toPath())
+ securityKeys.keyStorePassword().use { assertThat(it).isEqualTo(KEYSTORE_PASSWORD.toCharArray()) }
+ securityKeys.trustStorePassword().use { assertThat(it).isEqualTo(TRUSTSTORE_PASSWORD.toCharArray()) }
+
+ assertThat(it.cbs.firstRequestDelay).isEqualTo(defaultFirstReqDelaySec)
+ assertThat(it.cbs.requestInterval).isEqualTo(defaultRequestIntervalSec)
+
+ assertThat(it.collector.routing).isEqualTo(emptyRouting)
+ assertThat(it.logLevel).isEqualTo(LogLevel.TRACE)
}
)
}
}
describe("validating configuration with security disabled") {
- val idleTimeoutSec = Duration.ofSeconds(10)
- val firstReqDelaySec = Duration.ofSeconds(10)
- val missingSecurityKeys: Option<SecurityKeysPaths> = None
-
- val config = PartialConfiguration(
- Some(PartialServerConfig(
- Some(1),
- Some(idleTimeoutSec),
- Some(2)
- )),
- Some(PartialCbsConfig(
- Some(firstReqDelaySec),
- Some(Duration.ofSeconds(3))
- )),
- Some(PartialSecurityConfig(
- missingSecurityKeys
- )),
- Some(PartialCollectorConfig(
- someFromEmptyRouting
- )),
- Some(LogLevel.INFO)
+ val config = partialConfiguration(
+ sslDisable = Some(true),
+ keyStoreFile = Some(""),
+ keyStorePassword = Some(""),
+ trustStoreFile = Some(""),
+ trustStorePassword = Some("")
)
it("should create valid configuration") {
@@ -170,13 +130,13 @@ internal object ConfigurationValidatorTest : Spek({
},
{
assertThat(it.server.idleTimeout)
- .isEqualTo(idleTimeoutSec)
+ .isEqualTo(defaultIdleTimeoutSec)
assertThat(it.security.keys)
- .isEqualTo(missingSecurityKeys)
+ .isEqualTo(None)
assertThat(it.cbs.firstRequestDelay)
- .isEqualTo(firstReqDelaySec)
+ .isEqualTo(defaultFirstReqDelaySec)
assertThat(it.collector.routing)
.isEqualTo(emptyRouting)
@@ -185,8 +145,69 @@ internal object ConfigurationValidatorTest : Spek({
}
}
+ describe("validating configuration with ssl disable missing") {
+ val config = partialConfiguration(
+ sslDisable = None
+ )
+
+ it("should create valid configuration with ssl enabled") {
+ val result = cut.validate(config)
+ result.fold(
+ {
+ fail("Configuration should have been created successfully but was $it")
+ },
+ {
+ val securityKeys = it.security.keys
+ .getOrElse { fail("Should be immutableSecurityKeys") } as SecurityKeys
+ assertThat(securityKeys.keyStore().path()).isEqualTo(File(KEYSTORE).toPath())
+ assertThat(securityKeys.trustStore().path()).isEqualTo(File(TRUSTSTORE).toPath())
+ securityKeys.keyStorePassword().use { assertThat(it).isEqualTo(KEYSTORE_PASSWORD.toCharArray()) }
+ securityKeys.trustStorePassword().use { assertThat(it).isEqualTo(TRUSTSTORE_PASSWORD.toCharArray()) }
+ }
+ )
+ }
+ }
+
}
})
+private fun partialConfiguration(listenPort: Option<Int> = Some(defaultListenPort),
+ idleTimeoutSec: Option<Duration> = Some(defaultIdleTimeoutSec),
+ maxPayloadSizeBytes: Option<Int> = Some(defaultMaxPayloadSizeBytes),
+ firstReqDelaySec: Option<Duration> = Some(defaultFirstReqDelaySec),
+ requestIntervalSec: Option<Duration> = Some(defaultRequestIntervalSec),
+ sslDisable: Option<Boolean> = Some(false),
+ keyStoreFile: Option<String> = Some(KEYSTORE),
+ keyStorePassword: Option<String> = Some(KEYSTORE_PASSWORD),
+ trustStoreFile: Option<String> = Some(TRUSTSTORE),
+ trustStorePassword: Option<String> = Some(TRUSTSTORE_PASSWORD),
+ routing: Option<Routing> = Some(emptyRouting),
+ logLevel: Option<LogLevel> = Some(LogLevel.INFO)
+) =
+ PartialConfiguration(
+ listenPort = listenPort,
+ idleTimeoutSec = idleTimeoutSec,
+ maxPayloadSizeBytes = maxPayloadSizeBytes,
+ firstRequestDelaySec = firstReqDelaySec,
+ requestIntervalSec = requestIntervalSec,
+ sslDisable = sslDisable,
+ keyStoreFile = keyStoreFile,
+ keyStorePassword = keyStorePassword,
+ trustStoreFile = trustStoreFile,
+ trustStorePassword = trustStorePassword,
+ routing = routing,
+ logLevel = logLevel
+ )
+
+val defaultListenPort = 1234
+val defaultRequestIntervalSec = Duration.ofSeconds(3)
+val defaultMaxPayloadSizeBytes = 2
+val defaultIdleTimeoutSec = Duration.ofSeconds(10L)
+val defaultFirstReqDelaySec = Duration.ofSeconds(10L)
+
+val KEYSTORE = "test.ks.pkcs12"
+val KEYSTORE_PASSWORD = "changeMe"
+val TRUSTSTORE = "trust.ks.pkcs12"
+val TRUSTSTORE_PASSWORD = "changeMeToo"
+
val emptyRouting: Routing = emptyList()
-val someFromEmptyRouting = Some(emptyRouting)
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt
index 4e35bfb3..b4683458 100644
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt
+++ b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/FileConfigurationReaderTest.kt
@@ -20,6 +20,7 @@
package org.onap.dcae.collectors.veshv.config.impl
import arrow.core.Some
+import arrow.core.getOrElse
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
@@ -27,8 +28,8 @@ import org.jetbrains.spek.api.dsl.it
import org.onap.dcae.collectors.veshv.tests.utils.resourceAsStream
import org.onap.dcae.collectors.veshv.utils.logging.LogLevel
import java.io.StringReader
-import java.net.InetSocketAddress
import java.time.Duration
+import kotlin.test.fail
/**
* @author Pawel Biniek <pawel.biniek@nokia.com>
@@ -46,29 +47,24 @@ internal object FileConfigurationReaderTest : Spek({
assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
}
- it("parses simple structure") {
+ it("parses simple structure and creates correct objects") {
val input = """{
- "server" : {
- "healthCheckApiPort" : 12002,
- "listenPort" : 12003
+ "server.listenPort" : 12003,
+ "cbs.firstRequestDelaySec": 10
}
- }
- """.trimIndent()
+ """.trimIndent()
val config = cut.loadConfig(StringReader(input))
- assertThat(config.server.nonEmpty()).isTrue()
- assertThat(config.server.orNull()?.listenPort).isEqualTo(Some(12003))
+ assertThat(config.listenPort).isEqualTo(Some(12003))
+ assertThat(config.firstRequestDelaySec).isEqualTo(Some(Duration.ofSeconds(10)))
}
it("parses disabled security configuration") {
val input = """{
- "security": {
- }
+ "security.sslDisable": true
}""".trimIndent()
val config = cut.loadConfig(StringReader(input))
- assertThat(config.security.nonEmpty()).isTrue()
- val security = config.security.orNull() as PartialSecurityConfig
- assertThat(security.keys.nonEmpty()).isFalse()
+ assertThat(config.sslDisable.getOrElse { fail("Should be Some") }).isTrue()
}
it("parses invalid log level string to empty option") {
@@ -89,22 +85,18 @@ internal object FileConfigurationReaderTest : Spek({
assertThat(config).isNotNull
assertThat(config.logLevel).isEqualTo(Some(LogLevel.ERROR))
- assertThat(config.security.nonEmpty()).isTrue()
- val security = config.security.orNull() as PartialSecurityConfig
- assertThat(security.keys.nonEmpty()).isTrue()
+ assertThat(config.listenPort).isEqualTo(Some(6000))
+ assertThat(config.idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
+ assertThat(config.maxPayloadSizeBytes).isEqualTo(Some(1048576))
- assertThat(config.cbs.nonEmpty()).isTrue()
- val cbs = config.cbs.orNull() as PartialCbsConfig
- assertThat(cbs.firstRequestDelaySec).isEqualTo(Some(Duration.ofSeconds(7)))
- assertThat(cbs.requestIntervalSec).isEqualTo(Some(Duration.ofSeconds(900)))
+ assertThat(config.firstRequestDelaySec).isEqualTo(Some(Duration.ofSeconds(7)))
+ assertThat(config.requestIntervalSec).isEqualTo(Some(Duration.ofSeconds(900)))
- assertThat(config.server.nonEmpty()).isTrue()
- val server = config.server.orNull() as PartialServerConfig
- server.run {
- assertThat(idleTimeoutSec).isEqualTo(Some(Duration.ofSeconds(1200)))
- assertThat(listenPort).isEqualTo(Some(6000))
- assertThat(maxPayloadSizeBytes).isEqualTo(Some(512000))
- }
+ assertThat(config.sslDisable).isEqualTo(Some(false))
+ assertThat(config.keyStoreFile).isEqualTo(Some("test.ks.pkcs12"))
+ assertThat(config.keyStorePassword).isEqualTo(Some("changeMe"))
+ assertThat(config.trustStoreFile).isEqualTo(Some("trust.ks.pkcs12"))
+ assertThat(config.trustStorePassword).isEqualTo(Some("changeMeToo"))
}
}
}
diff --git a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/gsonadapters/SecurityAdapterTest.kt b/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/gsonadapters/SecurityAdapterTest.kt
deleted file mode 100644
index a466896b..00000000
--- a/sources/hv-collector-configuration/src/test/kotlin/org/onap/dcae/collectors/veshv/config/impl/gsonadapters/SecurityAdapterTest.kt
+++ /dev/null
@@ -1,135 +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.config.impl.gsonadapters
-
-import com.google.gson.JsonDeserializationContext
-import com.google.gson.JsonParser
-import com.google.gson.reflect.TypeToken
-import com.nhaarman.mockitokotlin2.mock
-import org.assertj.core.api.Assertions
-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
-
-internal object SecurityAdapterTest : Spek({
-
- describe("deserialization") {
- val gson = JsonParser()
- val context = mock<JsonDeserializationContext>()
- val someType = TypeToken.get(SecurityAdapter::class.java).type
-
- val cut = SecurityAdapter()
-
- given("empty security object") {
- val json = gson.parse("{}")
-
- it("should parse json to security configuration without keys") {
- val deserialized = cut.deserialize(json, someType, context)
-
- Assertions.assertThat(deserialized.keys.isEmpty()).isTrue()
- }
- }
-
- given("valid security object with ssl disabled") {
-
- given("security keys missing") {
- val json = gson.parse(SECURITY_WITH_SSL_DISABLED_AND_KEYS_MISSING)
-
- it("should parse json to security configuration without keys") {
- val deserialized = cut.deserialize(json, someType, context)
-
- Assertions.assertThat(deserialized.keys.isEmpty()).isTrue()
- }
- }
-
- given("security keys provided") {
- val json = gson.parse(SECURITY_WITH_SSL_DISABLED_AND_KEYS_PROVIDED)
-
- it("should parse json to security configuration without keys") {
- val deserialized = cut.deserialize(json, someType, context)
-
- Assertions.assertThat(deserialized.keys.isEmpty()).isTrue()
- }
- }
- }
-
- given("valid security object with missing sslDisable key") {
- val json = gson.parse(MISSING_SSL_DISABLE_ENTRY)
-
- it("should return parse json to security configuration") {
- val deserialized = cut.deserialize(json, someType, context)
-
- Assertions.assertThat(deserialized.keys.isDefined()).isTrue()
- }
- }
-
- given("valid security object with ssl enabled") {
- val json = gson.parse(VALID_SECURITY_WITH_SSL_ENABLED)
-
- it("should return parse json to security configuration") {
- val deserialized = cut.deserialize(json, someType, context)
-
- Assertions.assertThat(deserialized.keys.isDefined()).isTrue()
- }
- }
- }
-})
-
-val SECURITY_WITH_SSL_DISABLED_AND_KEYS_MISSING = """
-{
- "sslDisable": true
-}
-"""
-
-val SECURITY_WITH_SSL_DISABLED_AND_KEYS_PROVIDED = """
-{
- "sslDisable": true,
- "keys": {
- "keyStoreFile": "test.ks.pkcs12",
- "keyStorePassword": "changeMe",
- "trustStoreFile": "trust.ks.pkcs12",
- "trustStorePassword": "changeMeToo"
- }
-}
-"""
-
-val MISSING_SSL_DISABLE_ENTRY = """
-{
- "keys": {
- "keyStoreFile": "test.ks.pkcs12",
- "keyStorePassword": "changeMe",
- "trustStoreFile": "trust.ks.pkcs12",
- "trustStorePassword": "changeMeToo"
- }
-}
-"""
-
-val VALID_SECURITY_WITH_SSL_ENABLED = """
-{
- "sslDisable": false,
- "keys": {
- "keyStoreFile": "test.ks.pkcs12",
- "keyStorePassword": "changeMe",
- "trustStoreFile": "trust.ks.pkcs12",
- "trustStorePassword": "changeMeToo"
- }
-}
-"""
diff --git a/sources/hv-collector-configuration/src/test/resources/sampleConfig.json b/sources/hv-collector-configuration/src/test/resources/sampleConfig.json
index 07f0702f..2c3805ef 100644
--- a/sources/hv-collector-configuration/src/test/resources/sampleConfig.json
+++ b/sources/hv-collector-configuration/src/test/resources/sampleConfig.json
@@ -1,22 +1,13 @@
{
"logLevel": "ERROR",
- "server": {
- "healthCheckApiPort": 5000,
- "listenPort": 6000,
- "idleTimeoutSec": 1200,
- "maxPayloadSizeBytes": 512000
- },
- "cbs": {
- "firstRequestDelaySec": 7,
- "requestIntervalSec": 900
- },
- "security": {
- "sslDisable": false,
- "keys": {
- "keyStoreFile": "test.ks.pkcs12",
- "keyStorePassword": "changeMe",
- "trustStoreFile": "trust.ks.pkcs12",
- "trustStorePassword": "changeMeToo"
- }
- }
-}
+ "server.listenPort": 6000,
+ "server.idleTimeoutSec": 1200,
+ "server.maxPayloadSizeBytes": 1048576,
+ "cbs.firstRequestDelaySec": 7,
+ "cbs.requestIntervalSec": 900,
+ "security.sslDisable": false,
+ "security.keys.keyStoreFile": "test.ks.pkcs12",
+ "security.keys.keyStorePassword": "changeMe",
+ "security.keys.trustStoreFile": "trust.ks.pkcs12",
+ "security.keys.trustStorePassword": "changeMeToo"
+} \ No newline at end of file