Follow up to #60360, turns out at times the name of an interface that isn't loopback is not a valid scope id.
This commit is contained in:
parent
1f6a3765e4
commit
0778274b72
|
@ -23,6 +23,7 @@ import org.hamcrest.Matchers;
|
|||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class InetAddressesTests extends ESTestCase {
|
||||
public void testForStringBogusInput() {
|
||||
|
@ -130,7 +131,17 @@ public class InetAddressesTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testForStringIPv6WithScopeIdInput() throws java.io.IOException {
|
||||
String ipStr = "0:0:0:0:0:0:0:1%" + NetworkInterface.getNetworkInterfaces().nextElement().getName();
|
||||
final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||
String scopeId = null;
|
||||
while (interfaces.hasMoreElements()) {
|
||||
final NetworkInterface nint = interfaces.nextElement();
|
||||
if (nint.isLoopback()) {
|
||||
scopeId = nint.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(scopeId);
|
||||
String ipStr = "0:0:0:0:0:0:0:1%" + scopeId;
|
||||
InetAddress ipv6Addr = InetAddress.getByName(ipStr);
|
||||
assertEquals(ipv6Addr, InetAddresses.forString(ipStr));
|
||||
assertTrue(InetAddresses.isInetAddress(ipStr));
|
||||
|
|
Loading…
Reference in New Issue