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.validation;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.onap.oom.certservice.postprocessor.configuration.path.validation.ValidationFunctions.doesItContainValidCertificatesPaths;
25 import static org.onap.oom.certservice.postprocessor.configuration.path.validation.ValidationFunctions.doesItContainValidPasswordPaths;
26 import static org.onap.oom.certservice.postprocessor.configuration.path.validation.ValidationFunctions.doesItContainValidPathsToCopy;
28 import java.util.Arrays;
29 import java.util.List;
30 import org.junit.jupiter.api.Test;
32 class ValidationFunctionsTest {
35 void shouldValidateWithSuccessCorrectCertificatesPaths() {
37 List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12");
39 boolean result = doesItContainValidCertificatesPaths().test(certPaths);
41 assertThat(result).isTrue();
45 void shouldValidateWithFailureCertificatesPathsWithOneEmptyPath() {
47 List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12", "");
49 boolean result = doesItContainValidCertificatesPaths().test(certPaths);
51 assertThat(result).isFalse();
55 void shouldValidateWithFailureCertificatesPathsWithOnePathWhichHasIncorrectExtension() {
57 List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.txt", "/opt/cert.p12");
59 boolean result = doesItContainValidCertificatesPaths().test(certPaths);
61 assertThat(result).isFalse();
65 void shouldValidateWithSuccessCertificatesPasswordPaths() {
67 List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "");
69 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
71 assertThat(result).isTrue();
75 void shouldValidateWithSuccessCertificatePasswordsPathsWhichContainsEmptyPathsInTheMiddle() {
77 List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "", "/etc/truststore.pass");
79 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
81 assertThat(result).isTrue();
85 void shouldValidateWithFailureCertificatesPasswordsPathsWithIncorrectExtension() {
87 List<String> passwordPaths = Arrays.asList("/pass.txt");
89 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
91 assertThat(result).isFalse();
95 void shouldValidateWithFailureCertificatesPasswordPathsWithMissingPrecedingSlash() {
97 List<String> passwordPaths = Arrays.asList("jks.pass");
99 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
101 assertThat(result).isFalse();
105 void shouldValidateWithSuccessSourcePathsToCopyFiles() {
107 List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/external/keystore.p12",
108 "/opt/dcae/cacert/external/keystore.pass");
110 boolean result = doesItContainValidPathsToCopy().test(sourcePaths);
112 assertThat(result).isTrue();
116 void shouldValidateWithSuccessDestinationPathsToCopyFiles() {
118 List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.p12","/opt/dcae/cacert/p12.pass");
120 boolean result = doesItContainValidPathsToCopy().test(sourcePaths);
122 assertThat(result).isTrue();
126 void shouldValidateWithFailureDestinationPathsWithIncorrectExtension() {
128 List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.txt","/opt/dcae/cacert/p12.other");
130 boolean result = doesItContainValidPathsToCopy().test(sourcePaths);
132 assertThat(result).isFalse();