Compare commits

..

1 Commits

Author SHA1 Message Date
Jeroen van Erp
dbe00fabc6 Working on #88 2016-04-11 16:16:08 +02:00
4 changed files with 50 additions and 5 deletions

View File

@@ -96,7 +96,7 @@ Google Group: http://groups.google.com/group/sshj-users
Fork away!
== Release history
SSHJ 0.16.0 (2016-04-11)::
SSHJ 0.16.0 (2016-??-??)::
* Fixed https://github.com/hierynomus/sshj/issues/239[#239]: Remote port forwards did not work if you used the empty string as address, or a catch-all address.
* Fixed https://github.com/hierynomus/sshj/issues/242[#242]: Added OSGI headers to sources jar manifest
* Fixed https://github.com/hierynomus/sshj/issues/236[#236]: Remote Port forwarding with dynamic port allocation fails with BufferUnderflowException

View File

@@ -18,8 +18,15 @@ package net.schmizz.sshj.sftp;
public class PathComponents {
static String adjustForParent(String parent, String path, String pathSep) {
return (path.startsWith(pathSep)) ? path // Absolute path, nothing to adjust
: (parent + (parent.endsWith(pathSep) ? "" : pathSep) + path); // Relative path
if (path.startsWith(pathSep)) { // Absolute path
return path;
// } else if (parent.isEmpty()) { // Relative path
// return path;
} else if (parent.endsWith(pathSep)) {
return parent + path;
} else {
return parent + pathSep + path;
}
}
static String trimTrailingSeparator(String somePath, String pathSep) {

View File

@@ -17,23 +17,37 @@ package com.hierynomus.sshj;
import net.schmizz.sshj.DefaultConfig;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.forwarded.RemotePortForwarder;
import net.schmizz.sshj.connection.channel.forwarded.SocketForwardingConnectListener;
import net.schmizz.sshj.transport.verification.OpenSSHKnownHosts;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
public class IntegrationTest {
@Test @Ignore // Should only be enabled for testing against VM
public void shouldConnect() throws IOException {
public void shouldConnect() throws IOException, InterruptedException {
SSHClient sshClient = new SSHClient(new DefaultConfig());
sshClient.addHostKeyVerifier(new OpenSSHKnownHosts(new File("/Users/ajvanerp/.ssh/known_hosts")));
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect("172.16.37.129");
sshClient.authPassword("jeroen", "jeroen");
assertThat("Is connected", sshClient.isAuthenticated());
sshClient.getRemotePortForwarder().bind(
// where the server should listen
new RemotePortForwarder.Forward("0.0.0.0", 8080),
// what we do with incoming connections that are forwarded to us
new SocketForwardingConnectListener(new InetSocketAddress("localhost", 8000)));
new CountDownLatch(1).await();
}
}

View File

@@ -18,14 +18,21 @@ package com.hierynomus.sshj.sftp;
import com.hierynomus.sshj.test.SshFixture;
import com.hierynomus.sshj.test.util.FileUtil;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.sftp.FileAttributes;
import net.schmizz.sshj.sftp.SFTPClient;
import org.hamcrest.CoreMatchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.theories.DataPoint;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
public class SFTPClientTest {
@Rule
@@ -51,4 +58,21 @@ public class SFTPClientTest {
sshClient.disconnect();
}
}
@Test
@DataPoint
public void shouldNotCreateAbsoluteDirectoryWhenPathIsRelative() throws IOException {
SSHClient sshClient = fixture.setupConnectedDefaultClient();
sshClient.authPassword("test", "test");
SFTPClient sftpClient = sshClient.newSFTPClient();
String foo = sftpClient.canonicalize("foo");
String fooAbs = sftpClient.canonicalize("/foo");
assertThat(sftpClient.statExistence("foo"), nullValue());
sftpClient.mkdirs("foo");
assertThat(sftpClient.statExistence("foo"), notNullValue());
sftpClient.rmdir("foo");
assertThat(sftpClient.statExistence("foo"), nullValue());
sftpClient.close();
sshClient.disconnect();
}
}