2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2019 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.ssl.boundary
22 import arrow.core.None
23 import arrow.core.Some
24 import com.nhaarman.mockitokotlin2.mock
25 import com.nhaarman.mockitokotlin2.verify
26 import org.assertj.core.api.Assertions.assertThat
27 import org.jetbrains.spek.api.Spek
28 import org.jetbrains.spek.api.dsl.given
29 import org.jetbrains.spek.api.dsl.it
30 import org.jetbrains.spek.api.dsl.on
31 import org.onap.dcae.collectors.veshv.domain.SecurityConfiguration
32 import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys
33 import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore
34 import org.onap.dcaegen2.services.sdk.security.ssl.Passwords
35 import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory
36 import java.nio.file.Paths
39 * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
40 * @since February 2019
42 internal object SslContextFactoryTest : Spek({
43 val sslFactory: SslFactory = mock()
44 val cut = SslContextFactory(sslFactory)
46 given("empty security configuration") {
47 val secConfig = SecurityConfiguration(None)
49 on("creating server context") {
50 val result = cut.createServerContext(secConfig)
52 it("should return None") {
53 assertThat(result.isDefined()).isFalse()
57 on("creating client context") {
58 val result = cut.createClientContext(secConfig)
60 it("should return None") {
61 assertThat(result.isDefined()).isFalse()
66 given("security configuration with keys") {
67 val keys = ImmutableSecurityKeys.builder()
68 .trustStore(ImmutableSecurityKeysStore.of(Paths.get("ts.jks")))
69 .trustStorePassword(Passwords.fromString("xxx"))
70 .keyStore(ImmutableSecurityKeysStore.of(Paths.get("ks.pkcs12")))
71 .keyStorePassword(Passwords.fromString("yyy"))
73 val secConfig = SecurityConfiguration(Some(keys))
75 on("creating server context") {
76 val result = cut.createServerContext(secConfig)
78 it("should return Some") {
79 assertThat(result.isDefined()).isTrue()
82 it("should have called SslFactory") {
83 verify(sslFactory).createSecureServerContext(keys)
87 on("creating client context") {
88 val result = cut.createClientContext(secConfig)
90 it("should return Some") {
91 assertThat(result.isDefined()).isTrue()
94 it("should have called SslFactory") {
95 verify(sslFactory).createSecureClientContext(keys)