mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 23:30:55 +03:00
Compare commits
1 Commits
e390394e3b
...
issue-88
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbe00fabc6 |
@@ -18,8 +18,15 @@ package net.schmizz.sshj.sftp;
|
|||||||
public class PathComponents {
|
public class PathComponents {
|
||||||
|
|
||||||
static String adjustForParent(String parent, String path, String pathSep) {
|
static String adjustForParent(String parent, String path, String pathSep) {
|
||||||
return (path.startsWith(pathSep)) ? path // Absolute path, nothing to adjust
|
if (path.startsWith(pathSep)) { // Absolute path
|
||||||
: (parent + (parent.endsWith(pathSep) ? "" : pathSep) + path); // Relative 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) {
|
static String trimTrailingSeparator(String somePath, String pathSep) {
|
||||||
|
|||||||
@@ -17,23 +17,37 @@ package com.hierynomus.sshj;
|
|||||||
|
|
||||||
import net.schmizz.sshj.DefaultConfig;
|
import net.schmizz.sshj.DefaultConfig;
|
||||||
import net.schmizz.sshj.SSHClient;
|
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.OpenSSHKnownHosts;
|
||||||
|
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
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;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
public class IntegrationTest {
|
public class IntegrationTest {
|
||||||
|
|
||||||
@Test @Ignore // Should only be enabled for testing against VM
|
@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 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.connect("172.16.37.129");
|
||||||
sshClient.authPassword("jeroen", "jeroen");
|
sshClient.authPassword("jeroen", "jeroen");
|
||||||
assertThat("Is connected", sshClient.isAuthenticated());
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,21 @@ package com.hierynomus.sshj.sftp;
|
|||||||
import com.hierynomus.sshj.test.SshFixture;
|
import com.hierynomus.sshj.test.SshFixture;
|
||||||
import com.hierynomus.sshj.test.util.FileUtil;
|
import com.hierynomus.sshj.test.util.FileUtil;
|
||||||
import net.schmizz.sshj.SSHClient;
|
import net.schmizz.sshj.SSHClient;
|
||||||
|
import net.schmizz.sshj.sftp.FileAttributes;
|
||||||
import net.schmizz.sshj.sftp.SFTPClient;
|
import net.schmizz.sshj.sftp.SFTPClient;
|
||||||
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.theories.DataPoint;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
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 {
|
public class SFTPClientTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@@ -51,4 +58,21 @@ public class SFTPClientTest {
|
|||||||
sshClient.disconnect();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user