PkiAuthenticationTests & SslIntegrationTests should instead use NetworkAddress's format magic

Original commit: elastic/x-pack-elasticsearch@601e8e774d
This commit is contained in:
Boaz Leskes 2017-12-20 16:05:41 +01:00
parent 133d70bc6a
commit 5e51422f4d
2 changed files with 4 additions and 16 deletions

View File

@ -14,6 +14,7 @@ import org.elasticsearch.action.DocWriteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.NoNodeAvailableException;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
@ -32,7 +33,6 @@ 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;
@ -160,12 +160,6 @@ public class PkiAuthenticationTests extends SecurityIntegTestCase {
TransportAddress transportAddress = randomFrom(internalCluster().getInstance(HttpServerTransport.class)
.boundAddress().boundAddresses());
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());
return String.format(Locale.ROOT, "https://%s/", NetworkAddress.format(inetSocketAddress));
}
}

View File

@ -18,6 +18,7 @@ import org.apache.http.impl.client.HttpClients;
import org.elasticsearch.client.transport.NoNodeAvailableException;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.network.NetworkAddress;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
@ -32,7 +33,6 @@ 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;
@ -134,12 +134,6 @@ public class SslIntegrationTests extends SecurityIntegTestCase {
TransportAddress transportAddress =
randomFrom(internalCluster().getInstance(HttpServerTransport.class).boundAddress().boundAddresses());
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());
return String.format(Locale.ROOT, "https://%s/", NetworkAddress.format(inetSocketAddress));
}
}