From dd8ad297708c049cf1cc889b5acb8577ab73bce1 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Fri, 14 Jan 2022 16:23:33 -0500 Subject: [PATCH] Fixing org.opensearch.common.network.InetAddressesTests.testForStringIPv6WithScopeIdInput (#1913) Signed-off-by: Andriy Redko --- .../opensearch/common/network/InetAddressesTests.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/test/java/org/opensearch/common/network/InetAddressesTests.java b/server/src/test/java/org/opensearch/common/network/InetAddressesTests.java index 138a1097cc5..3de32f1e22f 100644 --- a/server/src/test/java/org/opensearch/common/network/InetAddressesTests.java +++ b/server/src/test/java/org/opensearch/common/network/InetAddressesTests.java @@ -33,11 +33,18 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.test.OpenSearchTestCase; import org.hamcrest.Matchers; +import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.UnknownHostException; +import java.util.Collections; import java.util.Enumeration; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assume.assumeThat; + public class InetAddressesTests extends OpenSearchTestCase { public void testForStringBogusInput() { String[] bogusInputs = { @@ -147,11 +154,12 @@ public class InetAddressesTests extends OpenSearchTestCase { String scopeId = null; while (interfaces.hasMoreElements()) { final NetworkInterface nint = interfaces.nextElement(); - if (nint.isLoopback()) { + if (nint.isLoopback() && Collections.list(nint.getInetAddresses()).stream().anyMatch(Inet6Address.class::isInstance)) { scopeId = nint.getName(); break; } } + assumeThat("The loopback interface has no IPv6 address assigned", scopeId, is(not(nullValue()))); assertNotNull(scopeId); String ipStr = "0:0:0:0:0:0:0:1%" + scopeId; InetAddress ipv6Addr = InetAddress.getByName(ipStr);