Skip to content
Open
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 @@ -74,13 +74,26 @@ public void testNoRegistryHostBindsToHost() throws Exception
connectorServer = new ConnectorServer(new JMXServiceURL("service:jmx:rmi:///jndi/rmi:///jmxrmi"), objectName);
connectorServer.start();

// Verify that I can connect to the RMI registry using a non-loopback address.
new Socket(InetAddress.getLocalHost(), 1099).close();
assertThrows(ConnectException.class, () ->
InetAddress localHost = InetAddress.getLocalHost();
InetAddress loopback = InetAddress.getLoopbackAddress();

// Verify that RMI registry binds to whatever InetAddress.getLocalHost() returns
new Socket(localHost, 1099).close();

// Only test loopback restriction if localhost resolves to a non-loopback address
if (!localHost.isLoopbackAddress())
{
assertThrows(ConnectException.class, () ->
{
// Verify that I cannot connect to the RMI registry using the loopback address.
new Socket(loopback, 1099).close();
});
}
else
{
// Verify that I cannot connect to the RMI registry using the loopback address.
new Socket(InetAddress.getLoopbackAddress(), 1099).close();
});
// If localhost is loopback, verify both work (they're the same address)
new Socket(loopback, 1099).close();
}
}

@Test
Expand All @@ -92,13 +105,26 @@ public void testNoRegistryHostNonDefaultRegistryPort() throws Exception
connectorServer = new ConnectorServer(new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + registryPort + "/jmxrmi"), objectName);
connectorServer.start();

// Verify that I can connect to the RMI registry using a non-loopback address.
new Socket(InetAddress.getLocalHost(), registryPort).close();
assertThrows(ConnectException.class, () ->
InetAddress localHost = InetAddress.getLocalHost();
InetAddress loopback = InetAddress.getLoopbackAddress();

// Verify that RMI registry binds to whatever InetAddress.getLocalHost() returns
new Socket(localHost, registryPort).close();

// Only test loopback restriction if localhost resolves to a non-loopback address
if (!localHost.isLoopbackAddress())
{
// Verify that I cannot connect to the RMI registry using the loopback address.
new Socket(InetAddress.getLoopbackAddress(), registryPort).close();
});
assertThrows(ConnectException.class, () ->
{
// Verify that I cannot connect to the RMI registry using the loopback address.
new Socket(loopback, registryPort).close();
});
}
else
{
// If localhost is loopback, verify both work (they're the same address)
new Socket(loopback, registryPort).close();
}
}

@Test
Expand Down Expand Up @@ -142,13 +168,26 @@ public void testNoRMIHostBindsToHost() throws Exception
connectorServer = new ConnectorServer(new JMXServiceURL("service:jmx:rmi:///jndi/rmi:///jmxrmi"), objectName);
connectorServer.start();

// Verify that I can connect to the RMI server using a non-loopback address.
new Socket(InetAddress.getLocalHost(), connectorServer.getAddress().getPort()).close();
assertThrows(ConnectException.class, () ->
InetAddress localHost = InetAddress.getLocalHost();
InetAddress loopback = InetAddress.getLoopbackAddress();

// Verify that RMI server binds to whatever InetAddress.getLocalHost() returns
new Socket(localHost, connectorServer.getAddress().getPort()).close();

// Only test loopback restriction if localhost resolves to a non-loopback address
if (!localHost.isLoopbackAddress())
{
assertThrows(ConnectException.class, () ->
{
// Verify that I cannot connect to the RMI server using the loopback address.
new Socket(loopback, connectorServer.getAddress().getPort()).close();
});
}
else
{
// Verify that I cannot connect to the RMI server using the loopback address.
new Socket(InetAddress.getLoopbackAddress(), connectorServer.getAddress().getPort()).close();
});
// If localhost is loopback, verify both work (they're the same address)
new Socket(loopback, connectorServer.getAddress().getPort()).close();
}
}

@Test
Expand Down