|
10 | 10 |
|
11 | 11 | import org.junit.jupiter.api.Nested; |
12 | 12 | import org.junit.jupiter.api.Test; |
| 13 | +import org.junit.jupiter.params.ParameterizedTest; |
| 14 | +import org.junit.jupiter.params.provider.ValueSource; |
13 | 15 |
|
14 | 16 | import static org.assertj.core.api.Assertions.assertThatCode; |
15 | 17 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
@@ -118,6 +120,25 @@ void differentPortWithWildcard() { |
118 | 120 | assertThatCode(() -> wildcardValidator.validate(accessor)).doesNotThrowAnyException(); |
119 | 121 | } |
120 | 122 |
|
| 123 | + @ParameterizedTest |
| 124 | + @ValueSource(strings = { "http://localhost:1", "http://localhost:65535" }) |
| 125 | + void boundaryPortsWithWildcard(String origin) { |
| 126 | + var accessor = originAccessor(origin); |
| 127 | + |
| 128 | + assertThatCode(() -> wildcardValidator.validate(accessor)).doesNotThrowAnyException(); |
| 129 | + } |
| 130 | + |
| 131 | + @ParameterizedTest |
| 132 | + @ValueSource(strings = { "http://localhost:", "http://localhost:evil.com", "http://localhost:3000.evil.com", |
| 133 | + "http://localhost:@evil.com", "http://localhost:80a", "http://localhost: 80", |
| 134 | + "http://localhost:3000/path", "http://localhost:0", "http://localhost:65536", |
| 135 | + "http://localhost:123456", "http://localhost:-1", "http://localhost:+80" }) |
| 136 | + void invalidPortWithWildcard(String origin) { |
| 137 | + var accessor = originAccessor(origin); |
| 138 | + |
| 139 | + assertThatThrownBy(() -> wildcardValidator.validate(accessor)).isEqualTo(INVALID_ORIGIN); |
| 140 | + } |
| 141 | + |
121 | 142 | @Test |
122 | 143 | void differentHostWithWildcard() { |
123 | 144 | var accessor = originAccessor("http://example.com:3000"); |
@@ -273,6 +294,33 @@ void noPort() { |
273 | 294 | assertThatCode(() -> wildcardHostValidator.validate(accessor)).doesNotThrowAnyException(); |
274 | 295 | } |
275 | 296 |
|
| 297 | + @ParameterizedTest |
| 298 | + @ValueSource(strings = { "localhost:1", "localhost:65535" }) |
| 299 | + void boundaryPorts(String host) { |
| 300 | + var accessor = hostAccessor(host); |
| 301 | + |
| 302 | + assertThatCode(() -> wildcardHostValidator.validate(accessor)).doesNotThrowAnyException(); |
| 303 | + } |
| 304 | + |
| 305 | + @ParameterizedTest |
| 306 | + @ValueSource(strings = { "localhost:", "localhost:evil.com", "localhost:3000.evil.com", |
| 307 | + "localhost:@evil.com", "localhost:80a", "localhost: 80", "localhost:3000/path", "localhost:0", |
| 308 | + "localhost:65536", "localhost:123456", "localhost:-1", "localhost:+80" }) |
| 309 | + void invalidPort(String host) { |
| 310 | + var accessor = hostAccessor(host); |
| 311 | + |
| 312 | + assertThatThrownBy(() -> wildcardHostValidator.validate(accessor)).isEqualTo(INVALID_HOST); |
| 313 | + } |
| 314 | + |
| 315 | + @ParameterizedTest |
| 316 | + @ValueSource(strings = { "127.0.0.1:evil.com", "127.0.0.1:80.evil.com", "127.0.0.1:@evil.com" }) |
| 317 | + void nonNumericPortIpv4(String host) { |
| 318 | + var ipValidator = DefaultServerTransportSecurityValidator.builder().allowedHost("127.0.0.1:*").build(); |
| 319 | + |
| 320 | + assertThatThrownBy(() -> ipValidator.validate(hostAccessor(host))).isEqualTo(INVALID_HOST); |
| 321 | + assertThatCode(() -> ipValidator.validate(hostAccessor("127.0.0.1:8080"))).doesNotThrowAnyException(); |
| 322 | + } |
| 323 | + |
276 | 324 | @Test |
277 | 325 | void differentHost() { |
278 | 326 | var accessor = hostAccessor("example.com:3000"); |
|
0 commit comments