2 * ============LICENSE_START=======================================================
3 * oom-certservice-client
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.oom.certservice.client.configuration.validation.csr;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.onap.oom.certservice.client.configuration.validation.client.ClientEnvsValueValidators.isPathValid;
25 import static org.onap.oom.certservice.client.configuration.validation.csr.CsrEnvsValueValidators.isCountryValid;
26 import static org.onap.oom.certservice.client.configuration.validation.csr.CsrEnvsValueValidators.isDomainNameValid;
27 import static org.onap.oom.certservice.client.configuration.validation.csr.CsrEnvsValueValidators.isEmailAddressValid;
28 import static org.onap.oom.certservice.client.configuration.validation.csr.CsrEnvsValueValidators.isIpAddressValid;
29 import static org.onap.oom.certservice.client.configuration.validation.csr.CsrEnvsValueValidators.isSpecialCharPresent;
30 import static org.onap.oom.certservice.client.configuration.validation.csr.CsrEnvsValueValidators.isUriValid;
32 import org.junit.jupiter.params.ParameterizedTest;
33 import org.junit.jupiter.params.provider.ValueSource;
35 class CsrEnvsValueValidatorsTest {
38 @ValueSource(strings = {"/var/log", "/", "/var/log/", "/second_var", "/second-var"})
39 void shouldAcceptValidPath(String path) {
40 assertThat(isPathValid(path)).isTrue();
44 @ValueSource(strings = {"/var/log?", "", "var_", "var", "//", "/var//log"})
45 void shouldRejectInvalidPath(String path) {
46 assertThat(isPathValid(path)).isFalse();
50 @ValueSource(strings = {"PL", "DE", "PN", "US", "IO", "CA", "KH", "CO", "DK", "EC", "CZ", "CN", "BR", "BD", "BE"})
51 void shouldAcceptValidCountryCode(String countryCode) {
52 assertThat(isCountryValid(countryCode)).isTrue();
56 @ValueSource(strings = {"", "QQ", "AFG", "D", "&*", "!", "ONAP", "p", "pl", "us", "afg"})
57 void shouldRejectInvalidCountryCode(String countryCode) {
58 assertThat(isCountryValid(countryCode)).isFalse();
62 @ValueSource(strings = {"sample@example.com", "onap@domain.pl", "alex.supertramp@onap.com",
63 "al.super^tramp@onap.org"})
64 void shouldAcceptValidEmailAddr(String emailAddr) {
65 assertThat(isEmailAddressValid(emailAddr)).isTrue();
69 @ValueSource(strings = {"<sample@example.com>", "onap@domain", "(mailto)user@onap.com", "mailto:axe@axe.de",
70 "incoreectdomaim@onap.ux"})
71 void shouldRejectInvalidEmailAddr(String address) {
72 assertThat(isEmailAddressValid(address)).isFalse();
76 @ValueSource(strings = {"192.168.0.1", "10.183.34.201", "ff:ff:ff:ff::", "ff:ff:ff:ff:ff:ff:ff:ff"})
77 void shouldAcceptValidIpAddress(String address) {
78 assertThat(isIpAddressValid(address)).isTrue();
82 @ValueSource(strings = {"192.168.0.", "ff:ff:ee:a1:", "fg:ff:ff:ff::", "http://10.183.34.201",
83 "10.183.34.201:8080"})
84 void shouldRejectInvalidIpAddress(String address) {
85 assertThat(isIpAddressValid(address)).isFalse();
89 @ValueSource(strings = {"sample.com", "Sample.com", "onap.org", "SRI-NIC.ARPA", "ves-collector", "sample"})
90 void shouldAcceptValidDomainName(String domain) {
91 assertThat(isDomainNameValid(domain)).isTrue();
95 @ValueSource(strings = {" ", "", "sample@onap.org", "192.168.0.1", "http://sample.com"})
96 void shouldRejectInvalidDomainNames(String domain) {
97 assertThat(isDomainNameValid(domain)).isFalse();
101 @ValueSource(strings = {"http://sample.com/path", "ftp://sample.com/path/file.txt", "https://ves.pl"})
102 void shouldBeTrueForValidUris(String text) {
103 assertThat(isUriValid(text)).isTrue();
106 @ValueSource(strings = {"3http://sample.com", "192.168.0.1", "www.example.com"})
107 void shouldBeFalseForInvalidUris(String text) {
108 assertThat(isUriValid(text)).isFalse();
112 @ValueSource(strings = {"/text~", "/text#", "/text@", "/text*","/text$", "/text+", "/text%", "/text!", "/text(",
113 "/text)", "/text?", "/text|", "/text_", "/text^"})
114 void shouldBeTrueForStringsWithSpecialChars(String text) {
115 assertThat(isSpecialCharPresent(text)).isTrue();
118 @ValueSource(strings = {"text", ""})
119 void shouldBeFalseForStringsWithoutSpecialChars(String text) {
120 assertThat(isSpecialCharPresent(text)).isFalse();