1 /*============LICENSE_START=======================================================
2 * oom-truststore-merger
3 * ================================================================================
4 * Copyright (C) 2020 Nokia. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.onap.oom.certservice.postprocessor.configuration.path;
22 import static org.assertj.core.api.Assertions.assertThat;
23 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
24 import static org.onap.oom.certservice.postprocessor.configuration.model.EnvVariable.TRUSTSTORES_PASSWORDS_PATHS;
25 import static org.onap.oom.certservice.postprocessor.configuration.model.EnvVariable.TRUSTSTORES_PATHS;
27 import java.util.Optional;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.mockito.junit.jupiter.MockitoExtension;
32 import org.onap.oom.certservice.postprocessor.configuration.exception.CertificatesPathsValidationException;
34 @ExtendWith(MockitoExtension.class)
35 class DelimitedPathsSplitterTest {
37 private static final String VALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.pem";
38 private static final String VALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:";
39 private static final String VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE = "/opt/app/certificates/truststore.pass::/etc/truststore.pass";
40 private static final String INVALID_TRUSTSTORES = "/opt/app/certificates/truststore.jks:/opt/app/certificates/truststore.invalid";
41 private static final String INVALID_TRUSTSTORES_PASSWORDS = "/opt/app/certificates/truststore.pass:/.pass";
43 private DelimitedPathsSplitter delimitedPathsSplitter;
47 delimitedPathsSplitter = new DelimitedPathsSplitter();
51 void shouldReturnCorrectListWhenTruststoresValid() {
53 assertThat(delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PATHS, Optional.of(VALID_TRUSTSTORES)))
54 .containsSequence("/opt/app/certificates/truststore.jks",
55 "/opt/app/certificates/truststore.pem");
59 void shouldThrowExceptionWhenTruststoresPathsEnvIsEmpty() {
61 assertThatExceptionOfType(CertificatesPathsValidationException.class)
62 .isThrownBy(() -> delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PATHS, Optional.of("")));
66 void shouldThrowExceptionWhenOneOfTruststoresPathsInvalid() {
68 assertThatExceptionOfType(CertificatesPathsValidationException.class)
69 .isThrownBy(() -> delimitedPathsSplitter
70 .getValidatedPaths(TRUSTSTORES_PATHS, Optional.of(INVALID_TRUSTSTORES)));
74 void shouldReturnCorrectListWhenTruststoresPasswordsValid() {
76 assertThat(delimitedPathsSplitter
77 .getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS, Optional.of(VALID_TRUSTSTORES_PASSWORDS)))
78 .containsSequence("/opt/app/certificates/truststore.pass", "");
82 void shouldReturnCorrectListWhenTruststoresPasswordsContainsEmptyPathsInTheMiddle() {
84 assertThat(delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS,
85 Optional.of(VALID_TRUSTSTORES_PASSWORDS_WITH_EMPTY_IN_THE_MIDDLE))).containsSequence(
86 "/opt/app/certificates/truststore.pass",
88 "/etc/truststore.pass"
93 void shouldThrowExceptionWhenTruststoresPasswordsPathEnvIsEmpty() {
95 assertThatExceptionOfType(CertificatesPathsValidationException.class)
97 () -> delimitedPathsSplitter.getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS, Optional.of("")));
101 void shouldThrowExceptionWhenOneOfTruststorePasswordPathsInvalid() {
103 assertThatExceptionOfType(CertificatesPathsValidationException.class)
104 .isThrownBy(() -> delimitedPathsSplitter
105 .getValidatedPaths(TRUSTSTORES_PASSWORDS_PATHS, Optional.of(INVALID_TRUSTSTORES_PASSWORDS)));