Skip to content

Commit

Permalink
[SUREFIRE-2220] SurefireForkChannel#getForkNodeConnectionString() ret…
Browse files Browse the repository at this point in the history
…urns invalid URI string if localHost resolves to IPv6 address

This closes #697
  • Loading branch information
michael-o committed Dec 9, 2023
1 parent 05322d9 commit 2d6cbc6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketOption;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
Expand Down Expand Up @@ -112,7 +114,19 @@ public void tryConnectToClient() {

@Override
public String getForkNodeConnectionString() {
return "tcp://" + localHost + ":" + localPort + (isBlank(sessionId) ? "" : "?sessionId=" + sessionId);
try {
URI uri = new URI(
"tcp",
null,
localHost,
localPort,
null,
isBlank(sessionId) ? null : "sessionId=" + sessionId,
null);
return uri.toASCIIString();
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ public Object getConsoleLock() {
assertThat(channel.getCountdownCloseablePermits()).isEqualTo(3);

String localHost = InetAddress.getLoopbackAddress().getHostAddress();
assertThat(channel.getForkNodeConnectionString())
.startsWith("tcp://" + localHost + ":")
.isNotEqualTo("tcp://" + localHost + ":")
.endsWith("?sessionId=" + sessionId);

URI uri = new URI(channel.getForkNodeConnectionString());

String connectionString = channel.getForkNodeConnectionString();
URI uri = new URI(connectionString);
assertThat(uri.getScheme()).isEqualTo("tcp");
String uriHost = uri.getHost();
if (uriHost.startsWith("[") && uriHost.endsWith("]")) {
uriHost = uriHost.substring(1, uriHost.length() - 1);
}
assertThat(uriHost).isEqualTo(localHost);
assertThat(uri.getPort()).isPositive();
assertThat(uri.getQuery()).isEqualTo("sessionId=" + sessionId);

final TestLessInputStreamBuilder builder = new TestLessInputStreamBuilder();
TestLessInputStream commandReader = builder.build();
Expand Down

0 comments on commit 2d6cbc6

Please sign in to comment.