You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2009/04/01 15:52:02 UTC

svn commit: r760892 - in /mina/sshd/trunk/src/test: java/org/apache/sshd/ java/org/apache/sshd/server/ java/org/apache/sshd/server/jaas/ java/org/apache/sshd/server/keyprovider/ resources/

Author: gnodet
Date: Wed Apr  1 13:51:57 2009
New Revision: 760892

URL: http://svn.apache.org/viewvc?rev=760892&view=rev
Log:
Add junit tests

Added:
    mina/sshd/trunk/src/test/java/org/apache/sshd/ScpTest.java
    mina/sshd/trunk/src/test/java/org/apache/sshd/server/
    mina/sshd/trunk/src/test/java/org/apache/sshd/server/jaas/
    mina/sshd/trunk/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java
    mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/
    mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
    mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
Modified:
    mina/sshd/trunk/src/test/java/org/apache/sshd/AbstractSessionTest.java
    mina/sshd/trunk/src/test/java/org/apache/sshd/CipherTest.java
    mina/sshd/trunk/src/test/java/org/apache/sshd/CompressionTest.java
    mina/sshd/trunk/src/test/java/org/apache/sshd/TestSpringConfig.java
    mina/sshd/trunk/src/test/resources/log4j.properties

Modified: mina/sshd/trunk/src/test/java/org/apache/sshd/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/AbstractSessionTest.java?rev=760892&r1=760891&r2=760892&view=diff
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/AbstractSessionTest.java (original)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/AbstractSessionTest.java Wed Apr  1 13:51:57 2009
@@ -27,7 +27,7 @@
 import org.junit.Test;
 
 /**
- * TODO Add javadoc
+ * Test basic stuff on AbstractSession.
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  * @version $Rev$, $Date$

Modified: mina/sshd/trunk/src/test/java/org/apache/sshd/CipherTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/CipherTest.java?rev=760892&r1=760891&r2=760892&view=diff
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/CipherTest.java (original)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/CipherTest.java Wed Apr  1 13:51:57 2009
@@ -34,6 +34,7 @@
 import org.apache.sshd.common.cipher.AES256CBC;
 import org.apache.sshd.common.cipher.BlowfishCBC;
 import org.apache.sshd.common.cipher.TripleDESCBC;
+import org.apache.sshd.common.cipher.CipherNone;
 import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
 import org.apache.sshd.common.random.BouncyCastleRandom;
 import org.apache.sshd.util.BogusPasswordAuthenticator;
@@ -44,7 +45,7 @@
 import org.junit.Test;
 
 /**
- * TODO Add javadoc
+ * Test Cipher algorithms.
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  * @version $Rev$, $Date$
@@ -68,7 +69,7 @@
     }
 
     @Test
-    @Ignore("AES192CBC is not always available by default")
+    @Ignore("AES256CBC is not always available by default")
     public void testAES256CBC() throws Exception {
         setUp(new AES256CBC.Factory());
         runTest();
@@ -136,6 +137,8 @@
 
     protected void runTest() throws Exception {
         JSch sch = new JSch();
+        JSch.setConfig("cipher.s2c", "aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,none");
+        JSch.setConfig("cipher.c2s", "aes128-cbc,3des-cbc,blowfish-cbc,aes192-cbc,aes256-cbc,none");
         sch.setLogger(new Logger() {
             public boolean isEnabled(int i) {
                 return true;

Modified: mina/sshd/trunk/src/test/java/org/apache/sshd/CompressionTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/CompressionTest.java?rev=760892&r1=760891&r2=760892&view=diff
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/CompressionTest.java (original)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/CompressionTest.java Wed Apr  1 13:51:57 2009
@@ -37,7 +37,7 @@
 import org.junit.Test;
 
 /**
- * TODO Add javadoc
+ * Test compression algorithms.
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  * @version $Rev$, $Date$

Added: mina/sshd/trunk/src/test/java/org/apache/sshd/ScpTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/ScpTest.java?rev=760892&view=auto
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/ScpTest.java (added)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/ScpTest.java Wed Apr  1 13:51:57 2009
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd;
+
+import java.net.ServerSocket;
+import java.io.OutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
+import org.apache.sshd.util.EchoShellFactory;
+import org.apache.sshd.util.BogusPasswordAuthenticator;
+import org.apache.sshd.server.command.ScpCommandFactory;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.Logger;
+import com.jcraft.jsch.UserInfo;
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelExec;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test for SCP support.
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ * @version $Rev: 760111 $, $Date: 2009-03-30 21:16:19 +0200 (Mon, 30 Mar 2009) $
+ */
+public class ScpTest {
+
+    private SshServer sshd;
+    private int port;
+    private com.jcraft.jsch.Session session;
+
+    @Before
+    public void setUp() throws Exception {
+        ServerSocket s = new ServerSocket(0);
+        port = s.getLocalPort();
+        s.close();
+
+        sshd = SshServer.setUpDefaultServer();
+        sshd.setPort(port);
+        sshd.setKeyPairProvider(new FileKeyPairProvider(new String[] { "src/test/resources/hostkey.pem" }));
+        sshd.setCommandFactory(new ScpCommandFactory());
+        sshd.setShellFactory(new EchoShellFactory());
+        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
+        sshd.start();
+
+        JSch sch = new JSch();
+        sch.setLogger(new Logger() {
+            public boolean isEnabled(int i) {
+                return true;
+            }
+
+            public void log(int i, String s) {
+                System.out.println("Log(jsch," + i + "): " + s);
+            }
+        });
+        session = sch.getSession("sshd", "localhost", port);
+        session.setUserInfo(new UserInfo() {
+            public String getPassphrase() {
+                return null;
+            }
+            public String getPassword() {
+                return "sshd";
+            }
+            public boolean promptPassword(String message) {
+                return true;
+            }
+            public boolean promptPassphrase(String message) {
+                return false;
+            }
+            public boolean promptYesNo(String message) {
+                return true;
+            }
+            public void showMessage(String message) {
+            }
+        });
+        session.connect();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        session.disconnect();
+        sshd.stop();
+    }
+
+    @Test
+    public void testScp() throws Exception {
+        String data = "0123456789\n";
+
+        File root = new File("target/scp");
+        File target = new File("target/scp/out.txt");
+        root.mkdirs();
+
+        target.delete();
+        assertFalse(target.exists());
+        sendFile("target/scp/out.txt", "out.txt", data);
+        assertTrue(target.exists());
+        assertEquals(data.length(), target.length());
+
+        target.delete();
+        assertFalse(target.exists());
+        sendFile("target/scp", "out.txt", data);
+        assertTrue(target.exists());
+        assertEquals(data.length(), target.length());
+
+        sendFileError("target", "scp", "0123456789\n");
+
+        readFileError("target/scp");
+
+        assertEquals(data, readFile("target/scp/out.txt"));
+
+
+        readDir("target/scp");
+
+        target.delete();
+        root.delete();
+
+        sendDir("target", "scp", "out.txt", data);
+        assertTrue(target.exists());
+        assertEquals(data.length(), target.length());
+    }
+
+    protected String readFile(String path) throws Exception {
+        ChannelExec c = (ChannelExec) session.openChannel("exec");
+        c.setCommand("scp -f " + path);
+        c.connect();
+        OutputStream os = c.getOutputStream();
+        InputStream is = c.getInputStream();
+        String header = readLine(is);
+        assertEquals("C0644 11 out.txt", header);
+        int length = Integer.parseInt(header.substring(6, header.indexOf(' ', 6)));
+        os.write(0);
+        os.flush();
+
+        byte[] buffer = new byte[length];
+        length = is.read(buffer, 0, buffer.length);
+        assertEquals(length, buffer.length);
+        assertEquals(0, is.read());
+        os.write(0);
+        os.flush();
+
+        c.disconnect();
+        return new String(buffer);
+    }
+
+    protected String readDir(String path) throws Exception {
+        ChannelExec c = (ChannelExec) session.openChannel("exec");
+        c.setCommand("scp -f -r " + path);
+        c.connect();
+        OutputStream os = c.getOutputStream();
+        InputStream is = c.getInputStream();
+        String header = readLine(is);
+        assertTrue(header.startsWith("D0755 0 "));
+        os.write(0);
+        os.flush();
+        header = readLine(is);
+        assertEquals("C0644 11 out.txt", header);
+        int length = Integer.parseInt(header.substring(6, header.indexOf(' ', 6)));
+        os.write(0);
+        os.flush();
+        byte[] buffer = new byte[length];
+        length = is.read(buffer, 0, buffer.length);
+        assertEquals(length, buffer.length);
+        assertEquals(0, is.read());
+        os.write(0);
+        os.flush();
+        header = readLine(is);
+        assertEquals("E", header);
+
+        c.disconnect();
+        return new String(buffer);
+    }
+
+    protected String readFileError(String path) throws Exception {
+        ChannelExec c = (ChannelExec) session.openChannel("exec");
+        c.setCommand("scp -f " + path);
+        c.connect();
+        OutputStream os = c.getOutputStream();
+        InputStream is = c.getInputStream();
+        assertEquals(2, is.read());
+        c.disconnect();
+        return null;
+    }
+
+    protected void sendFile(String path, String name, String data) throws Exception {
+        ChannelExec c = (ChannelExec) session.openChannel("exec");
+        c.setCommand("scp -t " + path);
+        c.connect();
+        OutputStream os = c.getOutputStream();
+        InputStream is = c.getInputStream();
+        os.write(("C7777 "+ data.length() + " " + name + "\n").getBytes());
+        os.flush();
+        assertEquals(0, is.read());
+        os.write(data.getBytes());
+        os.flush();
+        assertEquals(0, is.read());
+        os.write(0);
+        os.flush();
+        c.disconnect();
+    }
+
+    protected void sendFileError(String path, String name, String data) throws Exception {
+        ChannelExec c = (ChannelExec) session.openChannel("exec");
+        c.setCommand("scp -t " + path);
+        c.connect();
+        OutputStream os = c.getOutputStream();
+        InputStream is = c.getInputStream();
+        os.write(("C7777 "+ data.length() + " " + name + "\n").getBytes());
+        os.flush();
+        assertEquals(0, is.read());
+        os.write(data.getBytes());
+        os.flush();
+        assertEquals(2, is.read());
+        c.disconnect();
+    }
+
+    protected void sendDir(String path, String dirName, String fileName, String data) throws Exception {
+        ChannelExec c = (ChannelExec) session.openChannel("exec");
+        c.setCommand("scp -t -r " + path);
+        c.connect();
+        OutputStream os = c.getOutputStream();
+        InputStream is = c.getInputStream();
+
+        os.write(("D0755 0 " + dirName + "\n").getBytes());
+        os.flush();
+        assertEquals(0, is.read());
+        os.write(("C7777 "+ data.length() + " " + fileName + "\n").getBytes());
+        os.flush();
+        assertEquals(0, is.read());
+        os.write(data.getBytes());
+        os.flush();
+        assertEquals(0, is.read());
+        os.write(0);
+        os.flush();
+        os.write("E\n".getBytes());
+        assertEquals(0, is.read());
+    }
+
+    private String readLine(InputStream in) throws IOException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        for (;;) {
+            int c = in.read();
+            if (c == '\n') {
+                return baos.toString();
+            } else if (c == -1) {
+                throw new IOException("End of stream");
+            } else {
+                baos.write(c);
+            }
+        }
+    }
+
+}

Modified: mina/sshd/trunk/src/test/java/org/apache/sshd/TestSpringConfig.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/TestSpringConfig.java?rev=760892&r1=760891&r2=760892&view=diff
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/TestSpringConfig.java (original)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/TestSpringConfig.java Wed Apr  1 13:51:57 2009
@@ -30,7 +30,7 @@
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
- * TODO Add javadoc
+ * Test for spring based configuration.
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  * @version $Rev$, $Date$

Added: mina/sshd/trunk/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java?rev=760892&view=auto
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java (added)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java Wed Apr  1 13:51:57 2009
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.server.jaas;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.io.IOException;
+
+import javax.security.auth.login.Configuration;
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import static org.junit.Assert.*;
+
+/**
+ * TODO Add javadoc
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ * @version $Rev: 728050 $, $Date: 2008-12-19 16:50:58 +0100 (Fri, 19 Dec 2008) $
+ */
+public class JaasPasswordAuthenticatorTest {
+
+    @Before
+    public void setUp() {
+        Configuration config = new Configuration() {
+            public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
+                return new AppConfigurationEntry[] {
+                        new AppConfigurationEntry(DummyLoginModule.class.getName(),
+                                                  AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+                                                  new HashMap<String,Object>())
+                };
+            }
+            public void refresh() {
+            }
+        };
+        Configuration.setConfiguration(config);
+    }
+
+    @After
+    public void tearDown() {
+        Configuration.setConfiguration(null);
+    }
+
+    @Test
+    public void testAuthenticator() {
+        JaasPasswordAuthenticator auth = new JaasPasswordAuthenticator();
+        assertNull(auth.getDomain());
+        auth.setDomain("domain");
+        assertEquals("domain", auth.getDomain());
+        assertNotNull(auth.authenticate("sshd", "sshd"));
+        assertNull(auth.authenticate("sshd", "dummy"));
+    }
+
+
+    protected static class DummyLoginModule implements LoginModule {
+
+        private Subject subject;
+        private CallbackHandler callbackHandler;
+
+        public DummyLoginModule() {
+        }
+
+        public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
+            this.subject = subject;
+            this.callbackHandler = callbackHandler;
+        }
+
+        public boolean login() throws LoginException {
+            Callback[] callbacks = new Callback[2];
+            callbacks[0] = new NameCallback("Username: ");
+            callbacks[1] = new PasswordCallback("Password: ", false);
+            try {
+                callbackHandler.handle(callbacks);
+            } catch (IOException ioe) {
+                throw new LoginException(ioe.getMessage());
+            } catch (UnsupportedCallbackException uce) {
+                throw new LoginException(uce.getMessage() + " not available to obtain information from user");
+            }
+            String user = ((NameCallback) callbacks[0]).getName();
+            char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
+            return user.equals(new String(tmpPassword));
+        }
+
+        public boolean commit() throws LoginException {
+            return true;
+        }
+
+        public boolean abort() throws LoginException {
+            return true;
+        }
+
+        public boolean logout() throws LoginException {
+            return true;
+        }
+    }
+}

Added: mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java?rev=760892&view=auto
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java (added)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java Wed Apr  1 13:51:57 2009
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.server.keyprovider;
+
+import java.io.File;
+
+import org.junit.Test;
+import org.apache.sshd.common.KeyPairProvider;
+
+import static org.junit.Assert.*;
+
+/**
+ * TODO Add javadoc
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ * @version $Rev: 728050 $, $Date: 2008-12-19 16:50:58 +0100 (Fri, 19 Dec 2008) $
+ */
+public class PEMGeneratorHostKeyProviderTest {
+
+    @Test
+    public void testDSA() {
+        File path = new File("target/keys");
+        path.mkdirs();
+        path = new File(path, "simple.key");
+        path.delete();
+
+        // Generate
+        PEMGeneratorHostKeyProvider provider = new PEMGeneratorHostKeyProvider();
+        provider.setAlgorithm("DSA");
+        provider.setKeySize(512);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_DSS, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_DSS));
+
+        // Read existing
+        provider = new PEMGeneratorHostKeyProvider();
+        provider.setAlgorithm("DSA");
+        provider.setKeySize(512);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_DSS, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_DSS));
+    }
+
+    @Test
+    public void testRSA() {
+        File path = new File("target/keys");
+        path.mkdirs();
+        path = new File(path, "simple.key");
+        path.delete();
+
+        // Generate
+        PEMGeneratorHostKeyProvider provider = new PEMGeneratorHostKeyProvider();
+        provider.setAlgorithm("RSA");
+        provider.setKeySize(32);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
+
+        // Read existing
+        provider = new PEMGeneratorHostKeyProvider();
+        provider.setAlgorithm("RSA");
+        provider.setKeySize(32);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
+    }
+}
\ No newline at end of file

Added: mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java?rev=760892&view=auto
==============================================================================
--- mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java (added)
+++ mina/sshd/trunk/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java Wed Apr  1 13:51:57 2009
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.server.keyprovider;
+
+import java.io.File;
+
+import org.junit.Test;
+import org.apache.sshd.common.KeyPairProvider;
+
+import static org.junit.Assert.*;
+
+/**
+ * TODO Add javadoc
+ *
+ * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
+ * @version $Rev: 728050 $, $Date: 2008-12-19 16:50:58 +0100 (Fri, 19 Dec 2008) $
+ */
+public class SimpleGeneratorHostKeyProviderTest {
+
+    @Test
+    public void testDSA() {
+        File path = new File("target/keys");
+        path.mkdirs();
+        path = new File(path, "simple.key");
+        path.delete();
+
+        // Generate
+        SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
+        provider.setAlgorithm("DSA");
+        provider.setKeySize(512);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_DSS, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_DSS));
+
+        // Read existing
+        provider = new SimpleGeneratorHostKeyProvider();
+        provider.setAlgorithm("DSA");
+        provider.setKeySize(512);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_DSS, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_DSS));
+    }
+
+    @Test
+    public void testRSA() {
+        File path = new File("target/keys");
+        path.mkdirs();
+        path = new File(path, "simple.key");
+        path.delete();
+
+        // Generate
+        SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
+        provider.setAlgorithm("RSA");
+        provider.setKeySize(32);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
+
+        // Read existing
+        provider = new SimpleGeneratorHostKeyProvider();
+        provider.setAlgorithm("RSA");
+        provider.setKeySize(32);
+        provider.setPath(path.getPath());
+        assertEquals(KeyPairProvider.SSH_RSA, provider.getKeyTypes());
+        assertNotNull(provider.loadKey(KeyPairProvider.SSH_RSA));
+    }
+}

Modified: mina/sshd/trunk/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/src/test/resources/log4j.properties?rev=760892&r1=760891&r2=760892&view=diff
==============================================================================
--- mina/sshd/trunk/src/test/resources/log4j.properties (original)
+++ mina/sshd/trunk/src/test/resources/log4j.properties Wed Apr  1 13:51:57 2009
@@ -21,7 +21,7 @@
 #
 # The logging properties used during tests..
 #
-log4j.rootLogger=WARN, stdout
+log4j.rootLogger=DEBUG, stdout
 #log4j.logger.org.apache.mina=TRACE
 #log4j.logger.org.apache.sshd.common.channel.Window=DEBUG