PkiAuthenticationTests & SslIntegrationTests should properly handle ipv6 addresses

Original commit: elastic/x-pack-elasticsearch@b11d90e584
This commit is contained in:
Boaz Leskes 2017-12-20 15:50:13 +01:00
parent f977632a17
commit 133d70bc6a
2 changed files with 18 additions and 4 deletions

View File

@ -32,6 +32,7 @@ import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.InputStream;
import java.net.Inet6Address;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
@ -158,7 +159,13 @@ public class PkiAuthenticationTests extends SecurityIntegTestCase {
private String getNodeUrl() {
TransportAddress transportAddress = randomFrom(internalCluster().getInstance(HttpServerTransport.class)
.boundAddress().boundAddresses());
final InetSocketAddress inetAddress = transportAddress.address();
return String.format(Locale.ROOT, "https://%s:%s/", inetAddress.getHostString(), inetAddress.getPort());
final InetSocketAddress inetSocketAddress = transportAddress.address();
final String host;
if (inetSocketAddress.getAddress() instanceof Inet6Address) {
host = "[" + inetSocketAddress.getAddress().getHostAddress() + "]";
} else {
host = inetSocketAddress.getAddress().getHostAddress();
}
return String.format(Locale.ROOT, "https://%s:%s/", host, inetSocketAddress.getPort());
}
}

View File

@ -32,6 +32,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.TrustManagerFactory;
import java.io.InputStreamReader;
import java.net.Inet6Address;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.security.KeyStore;
@ -132,7 +133,13 @@ public class SslIntegrationTests extends SecurityIntegTestCase {
private String getNodeUrl() {
TransportAddress transportAddress =
randomFrom(internalCluster().getInstance(HttpServerTransport.class).boundAddress().boundAddresses());
final InetSocketAddress inetAddress = transportAddress.address();
return String.format(Locale.ROOT, "https://%s:%s/", inetAddress.getHostString(), inetAddress.getPort());
final InetSocketAddress inetSocketAddress = transportAddress.address();
final String host;
if (inetSocketAddress.getAddress() instanceof Inet6Address) {
host = "[" + inetSocketAddress.getAddress().getHostAddress() + "]";
} else {
host = inetSocketAddress.getAddress().getHostAddress();
}
return String.format(Locale.ROOT, "https://%s:%s/", host, inetSocketAddress.getPort());
}
}