Skip to content

Commit e1ea5d6

Browse files
authored
Tolerate IPv6 scoped IPs from JnlpAgentEndpointResolver.getResolvedHttpProxyAddress (#769)
* Tolerate IPv6 scoped IPs from `JnlpAgentEndpointResolver.getResolvedHttpProxyAddress` * Spotless
1 parent 6b8b20e commit e1ea5d6

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.net.SocketAddress;
4545
import java.net.SocketTimeoutException;
4646
import java.net.URI;
47+
import java.net.URISyntaxException;
4748
import java.net.URL;
4849
import java.net.URLConnection;
4950
import java.nio.charset.StandardCharsets;
@@ -486,9 +487,13 @@ public void waitForReady() throws InterruptedException {
486487
@CheckForNull
487488
static InetSocketAddress getResolvedHttpProxyAddress(@NonNull String host, int port) throws IOException {
488489
InetSocketAddress targetAddress = null;
489-
Iterator<Proxy> proxies = ProxySelector.getDefault()
490-
.select(URI.create(String.format("http://%s:%d", host, port)))
491-
.iterator();
490+
URI uri;
491+
try {
492+
uri = new URI("http", null, host, port, null, null, null);
493+
} catch (URISyntaxException x) {
494+
throw new IOException(x);
495+
}
496+
Iterator<Proxy> proxies = ProxySelector.getDefault().select(uri).iterator();
492497
while (targetAddress == null && proxies.hasNext()) {
493498
Proxy proxy = proxies.next();
494499
if (proxy.type() == Proxy.Type.DIRECT) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright 2024 CloudBees, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package org.jenkinsci.remoting.engine;
26+
27+
import java.net.Inet6Address;
28+
import org.junit.Test;
29+
30+
public final class JnlpAgentEndpointResolverTest {
31+
32+
/** @see Inet6Address */
33+
@Test
34+
public void getResolvedHttpProxyAddressIPv6() throws Exception {
35+
JnlpAgentEndpointResolver.getResolvedHttpProxyAddress("localhost", 12345);
36+
JnlpAgentEndpointResolver.getResolvedHttpProxyAddress("127.0.0.1", 12345);
37+
// Ignore return value, just assert that it does not throw an exception:
38+
JnlpAgentEndpointResolver.getResolvedHttpProxyAddress("0:0:0:0:0:0:0:1%lo", 12345);
39+
}
40+
}

0 commit comments

Comments
 (0)