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
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.aaf.certservice.client.configuration;
22 import org.junit.jupiter.params.ParameterizedTest;
23 import org.junit.jupiter.params.provider.ValueSource;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
28 class EnvValidationUtilsTest {
31 @ValueSource(strings = {"/var/log", "/", "/var/log/", "/second_var", "/second-var"})
32 public void shouldAcceptValidPath(String path){
33 assertTrue(EnvValidationUtils.isPathValid(path));
37 @ValueSource(strings = {"/var/log?", "", "var_", "var", "//", "/var//log"})
38 public void shouldRejectInvalidPath(String path){
39 assertFalse(EnvValidationUtils.isPathValid(path));
43 @ValueSource(strings = {"PL", "DE", "PT", "US"})
44 public void shouldAcceptValidCountryCode(String countryCode){
45 assertTrue(EnvValidationUtils.isCountryValid(countryCode));
49 @ValueSource(strings = {"1P", "PLP", "P#", "&*"})
50 public void shouldRejectInvalidCountryCode(String countryCode){
51 assertFalse(EnvValidationUtils.isCountryValid(countryCode));
55 @ValueSource(strings = {"caname", "caname1", "123caName", "ca1name"})
56 public void shouldAcceptValidAlphanumeric(String caName){
57 assertTrue(EnvValidationUtils.isAlphaNumeric(caName));
61 @ValueSource(strings = {"44caname$", "#caname1", "1c_aname", "ca1-name"})
62 public void shouldRejectInvalidAlphanumeric(String caName){
63 assertFalse(EnvValidationUtils.isAlphaNumeric(caName));
67 @ValueSource(strings = {"example.com", "www.example.com"})
68 public void shouldAcceptValidCommonName(String commonName){
69 assertTrue(EnvValidationUtils.isCommonNameValid(commonName));
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));