You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@oodt.apache.org by holenoter <ho...@me.com> on 2011/10/07 18:59:18 UTC

Re: svn commit: r1180102 - in /oodt/trunk/protocol/protocol-sftp: ./ src/test/org/apache/oodt/cas/protocol/sftp/ src/testdata/sshTestDir/

haha... i can't spell!

On Oct 07, 2011, at 09:57 AM, bfoster@apache.org wrote:

> Author: bfoster
> Date: Fri Oct 7 16:57:56 2011
> New Revision: 1180102
>
> URL: http://svn.apache.org/viewvc?rev=1180102&view=rev
> Log:
> - okay this time i've got, this time i've really got it! *figures crossed*
>
> Added:
> oodt/trunk/protocol/protocol-sftp/src/testdata/sshTestDir/
> oodt/trunk/protocol/protocol-sftp/src/testdata/sshTestDir/sshTestFile
> Modified:
> oodt/trunk/protocol/protocol-sftp/pom.xml
> oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java
> oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
>
> Modified: oodt/trunk/protocol/protocol-sftp/pom.xml
> URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/protocol-sftp/pom.xml?rev=1180102&r1=1180101&r2=1180102&view=diff
> ==============================================================================
> --- oodt/trunk/protocol/protocol-sftp/pom.xml (original)
> +++ oodt/trunk/protocol/protocol-sftp/pom.xml Fri Oct 7 16:57:56 2011
> @@ -50,17 +50,6 @@
> </build>
> </profile>
> </profiles>
> - <build>
> - <resources>
> - <resource>
> - <targetPath>org/apache/oodt/cas/protocol/sftp</targetPath>
> - <directory>${basedir}/src/main/resources/policy</directory>
> - <includes>
> - <include>sftp-protocol-config.xml</include>
> - </includes>
> - </resource>
> - </resources>
> - </build>
> <dependencies>
> <dependency>
> <groupId>org.apache.oodt</groupId>
> @@ -75,15 +64,15 @@
> <dependency>
> <groupId>sshtools</groupId>
> <artifactId>j2ssh-core</artifactId>
> - <version>0.2.2</version>
> + <version>0.2.9</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>sshtools</groupId>
> <artifactId>j2ssh-daemon</artifactId>
> - <version>0.2.2</version>
> - <scope>test</scope>
> - </dependency>
> + <version>0.2.9</version>
> + <scope>test</scope>
> + </dependency>
> <dependency>
> <groupId>commons-io</groupId>
> <artifactId>commons-io</artifactId>
> @@ -99,7 +88,7 @@
> <artifactId>mina-core</artifactId>
> <version>2.0.4</version>
> </dependency>
> - <dependency>
> + <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>3.8.2</version>
>
> Modified: oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java?rev=1180102&r1=1180101&r2=1180102&view=diff
> ==============================================================================
> --- oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java (original)
> +++ oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java Fri Oct 7 16:57:56 2011
> @@ -18,14 +18,9 @@ package org.apache.oodt.cas.protocol.sft
>
> //JDK imports
> import java.io.File;
> -import java.io.FileOutputStream;
> import java.io.IOException;
> -import java.io.PrintStream;
> -import java.util.HashMap;
> -import java.util.UUID;
>
> //Apache imports
> -import org.apache.commons.io.FileUtils;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> @@ -43,11 +38,8 @@ public class DummyAuthenticationProvider
>
> Log log = LogFactory.getLog(DummyAuthenticationProvider.class);
>
> - private HashMap<String, String> userHomeDirs;
> -
> public DummyAuthenticationProvider() {
> log.error("DummyAuthenticationProvider is in use. This is only for testing.");
> - userHomeDirs = new HashMap<String, String>();
> }
>
> @Override
> @@ -58,11 +50,7 @@ public class DummyAuthenticationProvider
>
> @Override
> public String getHomeDirectory(String username) throws IOException {
> - String homeDir = userHomeDirs.get(username);
> - if (homeDir != null) {
> - return homeDir;
> - }
> - return setupHomeDir(username);
> + return new File("src/testdata").getAbsolutePath();
> }
>
> @Override
> @@ -80,28 +68,4 @@ public class DummyAuthenticationProvider
> public boolean logonUser(String username) throws IOException {
> return true;
> }
> -
> - private String setupHomeDir(String username) throws IOException {
> - File tempFile = File.createTempFile("bogus", "bogus");
> - File tmpDir = tempFile.getParentFile();
> - tempFile.delete();
> - FileUtils.forceDeleteOnExit(tmpDir);
> - File homeDirFile = new File(tmpDir, "JschSftpTest/" + UUID.randomUUID());
> - File sshTestDir = new File(homeDirFile, "sshTestDir");
> - sshTestDir.mkdirs();
> - PrintStream ps = null;
> - try {
> - ps = new PrintStream(new FileOutputStream(new File(sshTestDir, "sshTestFile")));
> - ps.println("This is a ");
> - ps.println("test");
> - ps.println("file to test SFTP GET");
> - } catch (IOException e) {
> - throw e;
> - } finally {
> - try { ps.close(); } catch (Exception ignore) {}
> - }
> - System.out.println("HOME: " + homeDirFile.getAbsolutePath());
> - userHomeDirs.put(username, homeDirFile.getAbsolutePath());
> - return homeDirFile.getAbsolutePath();
> - }
> }
>
> Modified: oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java
> URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java?rev=1180102&r1=1180101&r2=1180102&view=diff
> ==============================================================================
> --- oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java (original)
> +++ oodt/trunk/protocol/protocol-sftp/src/test/org/apache/oodt/cas/protocol/sftp/TestJschSftpProtocol.java Fri Oct 7 16:57:56 2011
> @@ -17,14 +17,18 @@
> package org.apache.oodt.cas.protocol.sftp;
>
> //JUnit imports
> +import java.io.BufferedReader;
> import java.io.File;
> -import java.io.FileNotFoundException;
> +import java.io.FileOutputStream;
> +import java.io.FileReader;
> import java.io.IOException;
> import java.io.InputStream;
> +import java.io.PrintStream;
> import java.util.ArrayList;
> import java.util.List;
> -import java.util.concurrent.Executors;
> +import java.util.logging.Logger;
>
> +//JAVAX imports
> import javax.xml.parsers.ParserConfigurationException;
>
> //OODT imports
> @@ -46,7 +50,6 @@ import com.sshtools.j2ssh.configuration.
>
> //JUnit imports
> import junit.framework.TestCase;
> -
> /**
> * Test class for {@link JschSftpProtocol}.
> *
> @@ -54,44 +57,49 @@ import junit.framework.TestCase;
> */
> public class TestJschSftpProtocol extends TestCase {
>
> - TestXmlServerConfigurationContext context;
> + static TestXmlServerConfigurationContext context;
> + static final Logger LOG = Logger.getLogger(TestJschSftpProtocol.class.getName());
> + static Thread thread;
> + File publicKeysDir;
>
> - @Override
> - public void setUp() {
> + @Override
> + public void setUp() {
> try {
> + publicKeysDir = new File("src/testdata/publicKeys");
> + publicKeysDir.mkdirs();
> + FileUtils.forceDeleteOnExit(publicKeysDir);
> + FileUtils.copyFile(new File("src/testdata/authorization.xml"), new File("src/testdata/publicKeys/authorization.xml"));
> + FileUtils.copyFile(new File("src/testdata/server.xml"), new File("src/testdata/publicKeys/server.xml"));
> + FileUtils.copyFile(new File("src/testdata/platformxml"), new File("src/testdata/publicKeys/platform.xml"));
> ConfigurationLoader.initialize(true, context = new TestXmlServerConfigurationContext());
> } catch (Exception e) {
> fail("Failed to initialize server configuration");
> }
>
> - Executors.newSingleThreadExecutor().execute(new Runnable() {
> -
> + (thread = new Thread(new Runnable() {
> public void run() {
> try {
> SshDaemon.start();
> } catch (Exception e) {
> - try { SshDaemon.stop(); } catch (Exception ignore) { e.printStackTrace(); }
> - fail("Failed to start SSH daemon");
> + e.printStackTrace();
> }
> }
>
> - });
> - }
> + })).start();
> + }
>
> - @Override
> - public void tearDown() {
> - try {
> - SshDaemon.stop();
> - } catch (IOException e) {
> - fail("Failed to stop SSH daemon");
> - }
> + @Override
> + public void tearDown() throws IOException {
> + FileUtils.forceDelete(publicKeysDir);
> + SshDaemon.stop("");
> }
>
> public void testCDandPWDandLS() throws IOException, ProtocolException {
> - JschSftpProtocol sftpProtocol = new JschSftpProtocol(context.getPort());
> + int port = context.getPort();
> + File pubKeyFile = createPubKeyForPort(port);
> + JschSftpProtocol sftpProtocol = new JschSftpProtocol(port);
> sftpProtocol.connect("localhost", new HostKeyAuthentication("bfoster", "",
> - new File("src/testdata/sample-dsa.pub").getAbsoluteFile()
> - .getAbsolutePath()));
> + pubKeyFilegetAbsoluteFile().getAbsolutePath()));
> ProtocolFile homeDir = sftpProtocol.pwd();
> ProtocolFile testDir = new ProtocolFile(homeDir, "sshTestDir", true);
> sftpProtocol.cd(testDir);
> @@ -108,10 +116,11 @@ public class TestJschSftpProtocol extend
> }
>
> public void testGET() throws ProtocolException, IOException {
> - JschSftpProtocol sftpProtocol = new JschSftpProtocol(context.getPort());
> + int port = context.getPort();
> + File pubKeyFile = createPubKeyForPort(port);
> + JschSftpProtocol sftpProtocol = new JschSftpProtocol(port);
> sftpProtocol.connect("localhost", new HostKeyAuthentication("bfoster", "",
> - new File("src/testdata/sample-dsa.pub").getAbsoluteFile()
> - .getAbsolutePath()));
> + pubKeyFile.getAbsoluteFile().getAbsolutePath()));
> File bogusFile = File.createTempFile("bogus", "bogus");
> File tmpFile = new File(bogusFile.getParentFile(), "TestJschSftpProtocol");
> bogusFiledelete();
> @@ -119,15 +128,14 @@ public class TestJschSftpProtocol extend
> sftpProtocol.cd(new ProtocolFile("sshTestDir", true));
> File testDownloadFile = new File(tmpFile, "testDownloadFile");
> sftpProtocolget(new ProtocolFile("sshTestFile", false), testDownloadFile);
> - assertTrue(FileUtils.contentEquals(new File(
> - "src/testdata/sshTestDir/sshTestFile"), testDownloadFile));
> + assertTrue(FileUtils.contentEquals(new File("src/testdata/sshTestDir/sshTestFile"), testDownloadFile));
> FileUtils.forceDelete(tmpFile);
> }
>
> - private class TestServerConfiguration extends ServerConfiguration {
> + private static class TestServerConfiguration extends ServerConfiguration {
>
> - int commandPort = -1;
> - int port = -1;
> + int commandPort = AvailablePortFinder.getNextAvailable(12222);
> + int port = AvailablePortFinder.getNextAvailable(2022);
>
> public TestServerConfiguration(InputStream is) throws SAXException,
> ParserConfigurationException, IOException {
> @@ -136,24 +144,16 @@ public class TestJschSftpProtocol extend
>
> @Override
> public int getCommandPort() {
> - if (commandPort == -1) {
> - return commandPort = AvailablePortFinder.getNextAvailable(12222);
> - } else {
> - return commandPort;
> - }
> + return commandPort;
> }
>
> @Override
> public int getPort() {
> - if (port == -1) {
> - return port = AvailablePortFinder.getNextAvailable(2022);
> - } else {
> - return port;
> - }
> + return port;
> }
> }
>
> - private class TestXmlServerConfigurationContext extends XmlServerConfigurationContext {
> + private static class TestXmlServerConfigurationContext extends XmlServerConfigurationContext {
>
> private TestServerConfiguration serverConfig;
> private PlatformConfiguration platformConfig;
> @@ -165,12 +165,12 @@ public class TestJschSftpProtocol extend
> @Override
> public void initialize() throws ConfigurationException {
> try {
> - serverConfig = new TestServerConfiguration(ConfigurationLoader.loadFile("src/testdata/server.xml"));
> + serverConfig = new TestServerConfiguration(ConfigurationLoader.loadFile("src/testdata/publicKeys/server.xml"));
> } catch (Exception e) {
> throw new ConfigurationException(e.getMessage());
> }
> try {
> - platformConfig = new PlatformConfiguration(ConfigurationLoader.loadFile("src/testdata/platform.xml")) {};
> + platformConfig = new PlatformConfiguration(ConfigurationLoader.loadFile("src/testdata/publicKeys/platform.xml")) {};
> } catch (Exception e) {
> throw new ConfigurationException(e.getMessage());
> }
> @@ -202,4 +202,24 @@ public class TestJschSftpProtocol extend
> return serverConfig.getPort();
> }
> }
> +
> + private File createPubKeyForPort(int port) throws IOException {
> + PrintStream ps = null;
> + BufferedReader br = null;
> + try {
> + File publicKeyFile = new File(publicKeysDir, "sample-dsa.pub");
> + br = new BufferedReader(new FileReader(new File("src/testdata/sample-dsa.pub").getAbsoluteFile()));
> + ps = new PrintStream(new FileOutputStream(publicKeyFile));
> + String nextLine = null;
> + while ((nextLine = br.readLine()) != null) {
> + ps.println(nextLine.replace("2022", Integer.toString(port)));
> + }
> + return publicKeyFile;
> + } catch (IOException e) {
> + throw e;
> + } finally {
> + try { ps.close(); } catch (Exception ingore) {}
> + try { br.close(); } catch (Exception ingore) {}
> + }
> + }
> }
>
> Added: oodt/trunk/protocol/protocol-sftp/src/testdata/sshTestDir/sshTestFile
> URL: http://svn.apache.org/viewvc/oodt/trunk/protocol/protocol-sftp/src/testdata/sshTestDir/sshTestFile?rev=1180102&view=auto
> ==============================================================================
> --- oodt/trunk/protocol/protocol-sftp/src/testdata/sshTestDir/sshTestFile (added)
> +++ oodt/trunk/protocol/protocol-sftp/src/testdata/sshTestDir/sshTestFile Fri Oct 7 16:57:56 2011
> @@ -0,0 +1,3 @@
> +This is a
> +test
> +File
>
>