36b3b1a44709a3af2a00fe473e3c35be06e1f5bc
[oom/platform/cert-service.git] / certServiceClient / src / test / java / org / onap / aaf / certservice / client / configuration / EnvValidationUtilsTest.java
1 /*============LICENSE_START=======================================================
2  * aaf-certservice-client
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.aaf.certservice.client.configuration;
21
22 import org.junit.jupiter.params.ParameterizedTest;
23 import org.junit.jupiter.params.provider.ValueSource;
24
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27
28 class EnvValidationUtilsTest {
29
30     @ParameterizedTest
31     @ValueSource(strings = {"/var/log", "/", "/var/log/", "/second_var", "/second-var"})
32     public void shouldAcceptValidPath(String path){
33         assertTrue(EnvValidationUtils.isPathValid(path));
34     }
35
36     @ParameterizedTest
37     @ValueSource(strings = {"/var/log?", "", "var_", "var", "//", "/var//log"})
38     public void shouldRejectInvalidPath(String path){
39         assertFalse(EnvValidationUtils.isPathValid(path));
40     }
41
42     @ParameterizedTest
43     @ValueSource(strings = {"PL", "DE", "PT", "US"})
44     public void shouldAcceptValidCountryCode(String countryCode){
45         assertTrue(EnvValidationUtils.isCountryValid(countryCode));
46     }
47
48     @ParameterizedTest
49     @ValueSource(strings = {"1P", "PLP", "P#", "&*"})
50     public void shouldRejectInvalidCountryCode(String countryCode){
51         assertFalse(EnvValidationUtils.isCountryValid(countryCode));
52     }
53
54     @ParameterizedTest
55     @ValueSource(strings = {"caname", "caname1", "123caName", "ca1name"})
56     public void shouldAcceptValidAlphanumeric(String caName){
57         assertTrue(EnvValidationUtils.isAlphaNumeric(caName));
58     }
59
60     @ParameterizedTest
61     @ValueSource(strings = {"44caname$", "#caname1", "1c_aname", "ca1-name"})
62     public void shouldRejectInvalidAlphanumeric(String caName){
63         assertFalse(EnvValidationUtils.isAlphaNumeric(caName));
64     }
65
66     @ParameterizedTest
67     @ValueSource(strings = {"example.com", "www.example.com"})
68     public void shouldAcceptValidCommonName(String commonName){
69         assertTrue(EnvValidationUtils.isCommonNameValid(commonName));
70     }
71
72     @ParameterizedTest
73     @ValueSource(strings = {"https://example.com", "http://example.com", "example.com:8080", "0.0.0.0", "@#$%.com"})
74     public void shouldRejectInvalidCommonName(String commonName){
75         assertFalse(EnvValidationUtils.isCommonNameValid(commonName));
76     }
77 }