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;
23 import static org.assertj.core.api.Assertions.assertThat;
25 import org.junit.jupiter.params.ParameterizedTest;
26 import org.junit.jupiter.params.provider.ValueSource;
28 class UriValidatorTest {
31 * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
35 @ValueSource(strings = {"http:/", "http:", "http://"})
36 void shouldTrueForValidScheme(String uri) {
37 assertThat(UriValidator.isValidUri(uri)).isTrue();
41 @ValueSource(strings = {"example.com", "www.example.com", "0.0.0.0", "[2001:0db8:85a3:0000:0000:8a2e:0370:7334]"})
42 void shouldFalseForUriWithoutScheme(String uri) {
43 assertThat(UriValidator.isValidUri(uri)).isFalse();
47 @ValueSource(strings = {"*http://", "_http://", "?http://"})
48 void shouldFalseForUriWithInvalidScheme(String uri) {
49 assertThat(UriValidator.isValidUri(uri)).isFalse();
53 * authority = [ userinfo "@" ] host [ ":" port ]
55 * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
57 * host = IP-literal / IPv4address / reg-name
61 @ValueSource(strings = {
62 "http://user:password@example.com",
63 "http://user@example.com",
64 "http://user:password:test@example.com",
65 "http://user-info:password@example.com"})
66 void shouldTrueForValidUserInAuthority(String uri) {
67 assertThat(UriValidator.isValidUri(uri)).isTrue();
71 @ValueSource(strings = {
72 "http://user:password",
73 "http://user:password:test:"})
74 void shouldFalseForMissingHostInAuthority(String uri) {
75 assertThat(UriValidator.isValidUri(uri)).isFalse();
79 @ValueSource(strings = {
80 "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/test",
81 "https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]/",
83 "http://8.8.8.8/test"})
84 void shouldTrueForUriContainsIP(String uri) {
85 assertThat(UriValidator.isValidUri(uri)).isTrue();
89 @ValueSource(strings = {
90 "http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:443/test",
91 "https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443/",
92 "http://8.8.8.8:8080/test",
93 "https://8.8.8.8:443/"})
94 void shouldTrueForUriContainsIPAndPort(String uri) {
95 assertThat(UriValidator.isValidUri(uri)).isTrue();
99 @ValueSource(strings = {
100 "http:/path.to.file",
102 "http:/ptah/to/file"})
103 void shouldTrueForMissingAuthority(String uri) {
104 assertThat(UriValidator.isValidUri(uri)).isTrue();
108 * PATH QUERY FRAGMENT
112 @ValueSource(strings = {
113 "http://example.com/path/to/file",
114 "http://example.com/path",
115 "http://example.com/",})
116 void shouldTrueForPathWithAuthority(String uri) {
117 assertThat(UriValidator.isValidUri(uri)).isTrue();
121 @ValueSource(strings = {
122 "http:/path/to/file",
125 void shouldTrueForPathWithoutAuthority(String uri) {
126 assertThat(UriValidator.isValidUri(uri)).isTrue();
131 @ValueSource(strings = {
132 "http://example.com/test.txt?test=test1&test2=test3#onap",
133 "http://example.com?",
134 "http://example.com?test=tes1&#",
135 "http://example.com#onap"})
136 void shouldTrueForUriWithQueryAndFragmentInPath(String uri) {
137 assertThat(UriValidator.isValidUri(uri)).isTrue();
141 @ValueSource(strings = {
142 "http://example.com/test.txt?#onap#?",
143 "http://example.com?##",
144 "http://www.example.com/file%GF.html"})
145 void shouldFalseForUriWithWrongQueryOrWrongFragmentInPath(String uri) {
146 assertThat(UriValidator.isValidUri(uri)).isFalse();
150 @ValueSource(strings = {
151 "ftp://ftp.is.co.za/rfc/rfc1808.txt",
152 "http://www.ietf.org/rfc/rfc2396.txt",
153 "ldap://[2001:db8::7]/c=GB?objectClass?one",
154 "mailto:John.Doe@example.com",
155 "news:comp.infosystems.www.servers.unix",
156 "tel:+1-816-555-1212",
157 "telnet://192.0.2.16:80/",
158 "urn:oasis:names:specification:docbook:dtd:xml:4.1.2"})
159 void shouldTrueForRFC3986Examples(String uri) {
160 assertThat(UriValidator.isValidUri(uri)).isTrue();