Skip to content

Commit

Permalink
Fix IPV6 Scope Id in InetAddressesTests (#60368)
Browse files Browse the repository at this point in the history
Follow up to #60360, turns out at times the name of an interface that isn't loopback is not a valid scope id.
  • Loading branch information
original-brownbear authored Jul 29, 2020
1 parent cea95ef commit ee814d8
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.Enumeration;

public class InetAddressesTests extends ESTestCase {
public void testForStringBogusInput() {
Expand Down Expand Up @@ -130,7 +131,17 @@ public void testForStringIPv6Input() throws UnknownHostException {
}

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));
Expand Down

0 comments on commit ee814d8

Please sign in to comment.