Skip to content

Commit 430cbfc

Browse files
authored
Make all tests runnable on Windows (#814)
1 parent ec467a3 commit 430cbfc

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.bat text eol=crlf
2+
src/itest/docker-image/** eol=lf

src/test/java/com/hierynomus/sshj/test/SshFixture.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.schmizz.sshj.SSHClient;
2121
import net.schmizz.sshj.util.gss.BogusGSSAuthenticator;
2222
import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
23+
import org.apache.sshd.common.util.OsUtils;
2324
import org.apache.sshd.scp.server.ScpCommandFactory;
2425
import org.apache.sshd.server.SshServer;
2526
import org.apache.sshd.server.shell.ProcessShellFactory;
@@ -38,6 +39,7 @@
3839
public class SshFixture extends ExternalResource {
3940
public static final String hostkey = "hostkey.pem";
4041
public static final String fingerprint = "ce:a7:c1:cf:17:3f:96:49:6a:53:1a:05:0b:ba:90:db";
42+
public static final String listCommand = OsUtils.isWin32() ? "cmd.exe /C dir" : "ls";
4143

4244
private final SshServer server = defaultSshServer();
4345
private SSHClient client = null;
@@ -110,7 +112,7 @@ private SshServer defaultSshServer() {
110112
ScpCommandFactory commandFactory = new ScpCommandFactory();
111113
commandFactory.setDelegateCommandFactory((session, command) -> new ProcessShellFactory(command, command.split(" ")).createShell(session));
112114
sshServer.setCommandFactory(commandFactory);
113-
sshServer.setShellFactory(new ProcessShellFactory("ls", "ls"));
115+
sshServer.setShellFactory(new ProcessShellFactory(listCommand, listCommand.split(" ")));
114116
return sshServer;
115117
}
116118

src/test/java/net/schmizz/sshj/LoadsOfConnects.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void loadsOfConnects() {
4040
SSHClient client = fixture.setupConnectedDefaultClient();
4141
client.authPassword("test", "test");
4242
Session s = client.startSession();
43-
Session.Command c = s.exec("ls");
43+
Session.Command c = s.exec(SshFixture.listCommand);
4444
IOUtils.readFully(c.getErrorStream());
4545
IOUtils.readFully(c.getInputStream());
4646
c.close();

0 commit comments

Comments
 (0)