You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/06/15 18:52:51 UTC
svn commit: r1136120 - in /oodt/branches/protocol/protocol-sftp/src:
main/java/org/apache/oodt/cas/protocol/sftp/
main/java/org/apache/oodt/cas/protocol/sftp/auth/
test/org/apache/oodt/cas/protocol/sftp/
Author: bfoster
Date: Wed Jun 15 16:52:50 2011
New Revision: 1136120
URL: http://svn.apache.org/viewvc?rev=1136120&view=rev
Log:
- unit-test updates
---------------
OODT-194
Modified:
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java
oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java
oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
Modified: oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java?rev=1136120&r1=1136119&r2=1136120&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java (original)
+++ oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java Wed Jun 15 16:52:50 2011
@@ -93,13 +93,15 @@ public class JschSftpProtocol implements
session = jsch.getSession(auth.getUser(), host, this.port);
session.setUserInfo(new UserInfo() {
public String getPassphrase() {
- return "";
+ return (auth instanceof HostKeyAuthentication) ? ((HostKeyAuthentication) auth)
+ .getPassphrase() : null;
}
public String getPassword() {
return auth.getPass();
}
public boolean promptPassphrase(String arg0) {
- return false;
+ return (auth instanceof HostKeyAuthentication && ((HostKeyAuthentication) auth)
+ .getPassphrase() != null);
}
public boolean promptPassword(String arg0) {
return true;
Modified: oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java?rev=1136120&r1=1136119&r2=1136120&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java (original)
+++ oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java Wed Jun 15 16:52:50 2011
@@ -27,13 +27,23 @@ import org.apache.oodt.cas.protocol.auth
public class HostKeyAuthentication extends BasicAuthentication {
private String hostKeyFile;
+ private String passphrase;
public HostKeyAuthentication(String user, String pass, String hostKeyFile) {
+ this(user, pass, hostKeyFile, null);
+ }
+
+ public HostKeyAuthentication(String user, String pass, String hostKeyFile, String passphrase) {
super(user, pass);
this.hostKeyFile = hostKeyFile;
+ this.passphrase = passphrase;
}
public String getHostKeyFile() {
return hostKeyFile;
}
+
+ public String getPassphrase() {
+ return passphrase;
+ }
}
Modified: oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java?rev=1136120&r1=1136119&r2=1136120&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java (original)
+++ oodt/branches/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java Wed Jun 15 16:52:50 2011
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.concurrent.Executors;
//OODT imports
+import org.apache.commons.io.FileUtils;
import org.apache.oodt.cas.protocol.ProtocolFile;
import org.apache.oodt.cas.protocol.exceptions.ProtocolException;
import org.apache.oodt.cas.protocol.sftp.auth.HostKeyAuthentication;
@@ -45,6 +46,8 @@ import junit.framework.TestCase;
*/
public class TestJschSftpProtocol extends TestCase {
+ private static final int PORT = 2022;
+
@Override
public void setUp() {
XmlServerConfigurationContext context = new XmlServerConfigurationContext();
@@ -80,7 +83,7 @@ public class TestJschSftpProtocol extend
}
public void testCDandPWDandLS() throws IOException, ProtocolException {
- JschSftpProtocol sftpProtocol = new JschSftpProtocol(2022);
+ JschSftpProtocol sftpProtocol = new JschSftpProtocol(PORT);
sftpProtocol.connect("localhost", new HostKeyAuthentication("bfoster", "",
new File("src/testdata/sample-dsa.pub").getAbsoluteFile().getAbsolutePath()));
ProtocolFile homeDir = sftpProtocol.pwd();
@@ -97,4 +100,18 @@ public class TestJschSftpProtocol extend
assertEquals(new ProtocolFile(testDir, "sshTestFile", false), testFile);
}
+ public void testGET() throws ProtocolException, IOException {
+ JschSftpProtocol sftpProtocol = new JschSftpProtocol(PORT);
+ sftpProtocol.connect("localhost", new HostKeyAuthentication("bfoster", "",
+ new File("src/testdata/sample-dsa.pub").getAbsoluteFile().getAbsolutePath()));
+ File bogusFile = File.createTempFile("bogus", "bogus");
+ File tmpFile = new File(bogusFile.getParentFile(), "TestJschSftpProtocol");
+ bogusFile.delete();
+ tmpFile.mkdirs();
+ sftpProtocol.cd(new ProtocolFile("sshTestDir", true));
+ File testDownloadFile = new File(tmpFile, "testDownloadFile");
+ sftpProtocol.get(new ProtocolFile("sshTestFile", false), testDownloadFile);
+ assertTrue(FileUtils.contentEquals(new File("src/testdata/sshTestDir/sshTestFile"), testDownloadFile));
+ FileUtils.forceDelete(tmpFile);
+ }
}