Skip to content
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 @@ -11,6 +11,7 @@
import org.junit.Test;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnixDomainSocketAddress;
import java.nio.channels.SocketChannel;
Expand All @@ -19,11 +20,23 @@

public class SocketChannelInterceptorTests extends AgentTestCase {
@Test
public void test() throws IOException {
public void testConnections() throws IOException {
try (SocketChannel channel = SocketChannel.open()) {
assertThrows(SecurityException.class, () -> channel.connect(new InetSocketAddress("localhost", 9200)));

assertThrows(SecurityException.class, () -> channel.connect(UnixDomainSocketAddress.of("fake-path")));

assertThrows(SecurityException.class, () -> channel.connect(new InetSocketAddress("opensearch.org", 80)));
}
}

@Test
public void testHostnameResolution() throws IOException {
try (SocketChannel channel = SocketChannel.open()) {
InetAddress[] addresses = InetAddress.getAllByName("localhost");
for (InetAddress address : addresses) {
assertThrows(SecurityException.class, () -> channel.connect(new InetSocketAddress(address, 9200)));
}
}
}
}
Loading