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.csr.UriValidator.isValid;
26 import org.junit.jupiter.params.ParameterizedTest;
27 import org.junit.jupiter.params.provider.ValueSource;
29 class UriValidatorTest {
32 * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
36 @ValueSource(strings = {"http:/", "http:", "http://", "h4ttp://"})
37 void shouldTrueForValidScheme(String uri) {
38 assertThat(isValid(uri)).isTrue();
42 @ValueSource(strings = {"example.com", "www.example.com", "0.0.0.0", "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"})
43 void shouldFalseForUriWithoutScheme(String uri) {
44 assertThat(isValid(uri)).isFalse();
48 @ValueSource(strings = {"*http://", "_http://", "?http://", "4http://"})
49 void shouldFalseForUriWithInvalidScheme(String uri) {
50 assertThat(isValid(uri)).isFalse();
54 * authority = [ userinfo "@" ] host [ ":" port ]
56 * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
58 * host = IP-literal / IPv4address / reg-name
62 @ValueSource(strings = {
63 "http://user:password@example.com",
64 "http://user@example.com",
65 "http://user:password:test@example.com",
66 "http://user-info:password@example.com"})
67 void shouldTrueForValidUserInAuthority(String uri) {
68 assertThat(isValid(uri)).isTrue();
72 @ValueSource(strings = {
73 "http://user:password",
74 "http://user:password:test:"})
75 void shouldFalseForMissingHostInAuthority(String uri) {
76 assertThat(isValid(uri)).isFalse();
80 @ValueSource(strings = {
81 "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/test",
82 "https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/",
84 "http://8.8.8.8/test"})
85 void shouldTrueForUriContainsIP(String uri) {
86 assertThat(isValid(uri)).isTrue();
90 @ValueSource(strings = {
91 "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443/test",
92 "https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443/",
93 "http://8.8.8.8:8080/test",
94 "https://8.8.8.8:443/"})
95 void shouldTrueForUriContainsIPAndPort(String uri) {
96 assertThat(isValid(uri)).isTrue();
100 @ValueSource(strings = {
101 "http:/path.to.file",
103 "http:/ptah/to/file"})
104 void shouldTrueForMissingAuthority(String uri) {
105 assertThat(isValid(uri)).isTrue();
109 * PATH QUERY FRAGMENT
113 @ValueSource(strings = {
114 "http://example.com/path/to/file",
115 "http://example.com/path",
116 "http://example.com/",})
117 void shouldTrueForPathWithAuthority(String uri) {
118 assertThat(isValid(uri)).isTrue();
122 @ValueSource(strings = {
123 "http:/path/to/file",
126 void shouldTrueForPathWithoutAuthority(String uri) {
127 assertThat(isValid(uri)).isTrue();
132 @ValueSource(strings = {
133 "http://example.com/test.txt?test=test1&test2=test3#onap",
134 "http://example.com?",
135 "http://example.com?test=tes1&#",
136 "http://example.com#onap"})
137 void shouldTrueForUriWithQueryAndFragmentInPath(String uri) {
138 assertThat(isValid(uri)).isTrue();
142 @ValueSource(strings = {
143 "http://example.com/test.txt?#onap#?",
144 "http://example.com?##",
145 "http://www.example.com/file%GF.html"})
146 void shouldFalseForUriWithWrongQueryOrWrongFragmentInPath(String uri) {
147 assertThat(isValid(uri)).isFalse();
151 @ValueSource(strings = {
152 "ftp://ftp.is.co.za/rfc/rfc1808.txt",
153 "http://www.ietf.org/rfc/rfc2396.txt",
154 "ldap://[2001:db8::7]/c=GB?objectClass?one",
155 "mailto:John.Doe@example.com",
156 "news:comp.infosystems.www.servers.unix",
157 "tel:+1-816-555-1212",
158 "telnet://192.0.2.16:80/",
159 "urn:oasis:names:specification:docbook:dtd:xml:4.1.2"})
160 void shouldTrueForRFC3986Examples(String uri) {
161 assertThat(isValid(uri)).isTrue();