Skip to content

Commit

Permalink
Adapt to run test on IPv6 (#2538)
Browse files Browse the repository at this point in the history
  • Loading branch information
imonteroperez authored Jan 24, 2024
1 parent 29eb202 commit 953af33
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public class GitReadSaveTest extends PipelineBaseTest {
private final Logger logger = Logger.getLogger(getClass().getName());

private SSHServer sshd;

private static IP_ADDRESS = InetAddress.getLoopbackAddress().getHostAddress();

public GitReadSaveTest() {
}
Expand Down Expand Up @@ -193,12 +195,16 @@ private void startSSH(@Nullable User u) throws Exception {
sshd.start();
}
}

private String getAddress() {
return Boolean.getBoolean("java.net.preferIPv6Addresses") ? String.format("[%s]", IP_ADDRESS) : IP_ADDRESS;
}

@After
public void stopSSHServer() throws InterruptedException, IOException {
if (sshd != null) {
String ssh = "ssh -p " + sshd.getPort() + " bob@127.0.0.1";
String remote = "ssh://bob@127.0.0.1:" + sshd.getPort() + "" + repoForSSH.getRoot().getCanonicalPath();
String ssh = "ssh -p " + sshd.getPort() + " bob@" + getAddress();
String remote = "ssh://bob@" + getAddress() + ":" + sshd.getPort() + "" + repoForSSH.getRoot().getCanonicalPath();
logger.fine(ssh + " // remote: " + remote);
sshd.stop();
sshd = null;
Expand All @@ -224,7 +230,7 @@ public void testBareRepoReadWrite() throws Exception {
public void testGitScmValidate() throws Exception {
Assume.assumeFalse(Functions.isWindows()); // can't really run this on windows
startSSH();
String userHostPort = "bob@127.0.0.1:" + sshd.getPort();
String userHostPort = "bob@" + getAddress() + ":" + sshd.getPort();
String remote = "ssh://" + userHostPort + "" + repoForSSH.getRoot().getCanonicalPath();

User bob = login();
Expand Down

0 comments on commit 953af33

Please sign in to comment.