Merge "[OOM-CPMv2] Fix sonar issue"
[oom/platform/cert-service.git] / trustStoreMerger / src / test / java / org / onap / oom / certservice / postprocessor / configuration / path / validation / ValidationFunctionsTest.java
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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=========================================================
18  */
19
20 package org.onap.oom.certservice.postprocessor.configuration.path.validation;
21
22
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;
27
28 import java.util.Arrays;
29 import java.util.List;
30 import org.junit.jupiter.api.Test;
31
32 class ValidationFunctionsTest {
33
34     @Test
35     void shouldValidateWithSuccessCorrectCertificatesPaths() {
36         // given
37         List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12");
38         // when
39         boolean result = doesItContainValidCertificatesPaths().test(certPaths);
40         // then
41         assertThat(result).isTrue();
42     }
43
44     @Test
45     void shouldValidateWithFailureCertificatesPathsWithOneEmptyPath() {
46         // given
47         List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.p12", "");
48         // when
49         boolean result = doesItContainValidCertificatesPaths().test(certPaths);
50         // then
51         assertThat(result).isFalse();
52     }
53
54     @Test
55     void shouldValidateWithFailureCertificatesPathsWithOnePathWhichHasIncorrectExtension() {
56         // given
57         List<String> certPaths = Arrays.asList("/opt/app/certificates/truststore.txt", "/opt/cert.p12");
58         // when
59         boolean result = doesItContainValidCertificatesPaths().test(certPaths);
60         // then
61         assertThat(result).isFalse();
62     }
63
64     @Test
65     void shouldValidateWithSuccessCertificatesPasswordPaths() {
66         // given
67         List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "");
68         // when
69         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
70         // then
71         assertThat(result).isTrue();
72     }
73
74     @Test
75     void shouldValidateWithSuccessCertificatePasswordsPathsWhichContainsEmptyPathsInTheMiddle() {
76         // given
77         List<String> passwordPaths = Arrays.asList("/opt/app/certificates/truststore.pass", "", "/etc/truststore.pass");
78         // when
79         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
80         // then
81         assertThat(result).isTrue();
82     }
83
84     @Test
85     void shouldValidateWithFailureCertificatesPasswordsPathsWithIncorrectExtension() {
86         // given
87         List<String> passwordPaths = Arrays.asList("/pass.txt");
88         // when
89         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
90         // then
91         assertThat(result).isFalse();
92     }
93
94     @Test
95     void shouldValidateWithFailureCertificatesPasswordPathsWithMissingPrecedingSlash() {
96         // given
97         List<String> passwordPaths = Arrays.asList("jks.pass");
98         // when
99         boolean result = doesItContainValidPasswordPaths().test(passwordPaths);
100         // then
101         assertThat(result).isFalse();
102     }
103
104     @Test
105     void shouldValidateWithSuccessSourcePathsToCopyFiles() {
106         // given
107         List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/external/keystore.p12",
108             "/opt/dcae/cacert/external/keystore.pass");
109         // when
110         boolean result = doesItContainValidPathsToCopy().test(sourcePaths);
111         // then
112         assertThat(result).isTrue();
113     }
114
115     @Test
116     void shouldValidateWithSuccessDestinationPathsToCopyFiles() {
117         // given
118         List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.p12","/opt/dcae/cacert/p12.pass");
119         // when
120         boolean result = doesItContainValidPathsToCopy().test(sourcePaths);
121         // then
122         assertThat(result).isTrue();
123     }
124
125     @Test
126     void shouldValidateWithFailureDestinationPathsWithIncorrectExtension() {
127         // given
128         List<String> sourcePaths = Arrays.asList("/opt/dcae/cacert/cert.txt","/opt/dcae/cacert/p12.other");
129         // when
130         boolean result = doesItContainValidPathsToCopy().test(sourcePaths);
131         // then
132         assertThat(result).isFalse();
133     }
134
135 }