From 89cf4a7397b891e48369e5873921be4635c1b1de Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 20 Nov 2018 17:50:08 +0100 Subject: [PATCH] NETWORKING: Fix IpFiltering Test (#35730) * The port assigned to all loopback interfaces doesn't necessarily have to be the same for ipv4 and ipv6 => use actual address from profile instead of just port + loopback in test * Closes #35584 --- .../transport/filter/IpFilteringIntegrationTests.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java index b2ff18d2e69..bc17626b1f4 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/filter/IpFilteringIntegrationTests.java @@ -19,7 +19,6 @@ import org.junit.BeforeClass; import java.io.IOException; import java.io.OutputStream; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.nio.charset.StandardCharsets; @@ -69,7 +68,7 @@ public class IpFilteringIntegrationTests extends SecurityIntegTestCase { public void testThatIpFilteringIsAppliedForProfile() throws Exception { try (Socket socket = new Socket()){ - trySocketConnection(socket, new InetSocketAddress(InetAddress.getLoopbackAddress(), getProfilePort("client"))); + trySocketConnection(socket, getProfileAddress("client")); assertThat(socket.isClosed(), is(true)); } } @@ -86,9 +85,9 @@ public class IpFilteringIntegrationTests extends SecurityIntegTestCase { } } - private static int getProfilePort(String profile) { + private static InetSocketAddress getProfileAddress(String profile) { TransportAddress transportAddress = randomFrom(internalCluster().getInstance(Transport.class).profileBoundAddresses().get(profile).boundAddresses()); - return transportAddress.address().getPort(); + return transportAddress.address(); } }