Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] [1.x] Fixing org.opensearch.common.network.InetAddressesTests.testForStringPv6WithScopeIdInput (#1913) #1914

Merged
merged 1 commit into from
Jan 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@
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 = {
Expand Down Expand Up @@ -147,11 +154,12 @@ public void testForStringIPv6WithScopeIdInput() throws java.io.IOException {
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);
Expand Down