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.truststoremerger.configuration.path.validation;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.onap.oom.truststoremerger.configuration.path.validation.ValidationFunctions.doesItContainValidCertificatesPaths;
25 import static org.onap.oom.truststoremerger.configuration.path.validation.ValidationFunctions.doesItContainValidPasswordPaths;
27 import java.util.Arrays;
28 import java.util.List;
29 import org.junit.jupiter.api.Test;
31 class ValidationFunctionsTest {
34 void shouldValidateWithSuccessCorrectCertificatesPaths() {
36 List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12");
38 boolean result = doesItContainValidCertificatesPaths().test(certPaths);
40 assertThat(result).isTrue();
44 void shouldValidateWithFailureCertificatesPathsWithOneEmptyPath() {
46 List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12", "");
48 boolean result = doesItContainValidCertificatesPaths().test(certPaths);
50 assertThat(result).isFalse();
54 void shouldValidateWithFailureCertificatesPathsWithOnePathWhichHasIncorrectExtension() {
56 List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.txt", "/opt/cert.p12");
58 boolean result = doesItContainValidCertificatesPaths().test(certPaths);
60 assertThat(result).isFalse();
64 void shouldValidateWithSuccessCertificatesPasswordPaths() {
66 List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "");
68 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
70 assertThat(result).isTrue();
74 void shouldValidateWithSuccessCertificatePasswordsPathsWhichContainsEmptyPathsInTheMiddle() {
76 List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "", "/etc/truststore.pass");
78 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
80 assertThat(result).isTrue();
84 void shouldValidateWithFailureCertificatesPasswordsPathsWithIncorrectExtension() {
86 List<String> passwordPaths = Arrays.asList("/pass.txt");
88 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
90 assertThat(result).isFalse();
94 void shouldValidateWithFailureCertificatesPasswordPathsWithMissingPrecedingSlash() {
96 List<String> passwordPaths = Arrays.asList("jks.pass");
98 boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
100 assertThat(result).isFalse();
104 void shouldValidateWithSuccessSourcePathsToCopyFiles() {
106 List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/external/keystore.p12",
107 "/opt/dcae/cacert/external/keystore.pass");
109 boolean result = ValidationFunctions.doesItContainValidPathsToCopy().test(sourcePaths);
111 assertThat(result).isTrue();
115 void shouldValidateWithSuccessDestinationPathsToCopyFiles() {
117 List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.p12","/opt/dcae/cacert/p12.pass");
119 boolean result = ValidationFunctions.doesItContainValidPathsToCopy().test(sourcePaths);
121 assertThat(result).isTrue();
125 void shouldValidateWithFailureDestinationPathsWithIncorrectExtension() {
127 List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.txt","/opt/dcae/cacert/p12.other");
129 boolean result = ValidationFunctions.doesItContainValidPathsToCopy().test(sourcePaths);
131 assertThat(result).isFalse();