|
1 | 1 | /* |
2 | | - * Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2024, 2025 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials are made available under the |
5 | 5 | * terms of the Eclipse Public License v. 2.0, which is available at |
|
27 | 27 | import org.hamcrest.Matchers; |
28 | 28 | import org.junit.jupiter.api.Test; |
29 | 29 |
|
| 30 | +import javax.ws.rs.ProcessingException; |
| 31 | +import javax.ws.rs.client.Client; |
30 | 32 | import javax.ws.rs.client.ClientBuilder; |
31 | 33 | import javax.ws.rs.core.MultivaluedHashMap; |
| 34 | +import javax.ws.rs.core.Response; |
| 35 | +import java.net.ConnectException; |
32 | 36 | import java.net.URI; |
33 | 37 | import java.util.Collections; |
34 | 38 | import java.util.HashMap; |
@@ -155,4 +159,56 @@ public void testUriAndHeadersAndConfig() { |
155 | 159 | MatcherAssert.assertThat(configurator.isSNIRequired(), Matchers.is(true)); |
156 | 160 | MatcherAssert.assertThat(configurator.getSNIHostName(), Matchers.is("yyy.com")); |
157 | 161 | } |
| 162 | + |
| 163 | + @Test |
| 164 | + public void testIPv6Header() { |
| 165 | + final String HOST_HEADER_IPv6 = "[172:30::333b]"; |
| 166 | + final URI uri = URI.create("http://[172:30::333a]:8080/api/demo/v1"); |
| 167 | + final JerseyClient client = (JerseyClient) ClientBuilder.newClient(); |
| 168 | + Map<String, List<Object>> httpHeaders = new MultivaluedHashMap<>(); |
| 169 | + httpHeaders.put(HttpHeaders.HOST, Collections.singletonList(HOST_HEADER_IPv6 + ":8080")); |
| 170 | + SSLParamConfigurator configurator = SSLParamConfigurator.builder() |
| 171 | + .uri(uri) |
| 172 | + .headers(httpHeaders) |
| 173 | + .configuration(client.getConfiguration()) |
| 174 | + .build(); |
| 175 | + MatcherAssert.assertThat(configurator.isSNIRequired(), Matchers.is(true)); |
| 176 | + MatcherAssert.assertThat(configurator.getSNIHostName(), Matchers.is(HOST_HEADER_IPv6)); |
| 177 | + URI expected = URI.create("http://" + HOST_HEADER_IPv6 + ":8080/api/demo/v1"); |
| 178 | + MatcherAssert.assertThat(configurator.getSNIUri(), Matchers.is(expected)); |
| 179 | + MatcherAssert.assertThat(configurator.toIPRequestUri().toString(), |
| 180 | + Matchers.is(uri.toString().replace("::", ":0:0:0:0:0:"))); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + public void testIpv6Request() { |
| 185 | + Client client = ClientBuilder.newClient(); |
| 186 | + String u = "http://[::1]:8080"; |
| 187 | + try { |
| 188 | + client.target(u) |
| 189 | + .request() |
| 190 | + .header(HttpHeaders.HOST, "[172:30::333b]:8080") |
| 191 | + .get(); |
| 192 | + } catch (ProcessingException pe) { |
| 193 | + if (!ConnectException.class.isInstance(pe.getCause())) { |
| 194 | + throw pe; |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + @Test |
| 200 | + public void testIpv6RequestNoPort() { |
| 201 | + Client client = ClientBuilder.newClient(); |
| 202 | + String u = "http://[::1]"; |
| 203 | + try { |
| 204 | + client.target(u) |
| 205 | + .request() |
| 206 | + .header(HttpHeaders.HOST, "[172:30::333b]") |
| 207 | + .get(); |
| 208 | + } catch (ProcessingException pe) { |
| 209 | + if (!ConnectException.class.isInstance(pe.getCause())) { |
| 210 | + throw pe; |
| 211 | + } |
| 212 | + } |
| 213 | + } |
158 | 214 | } |
0 commit comments