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 2014/02/06 15:10:20 UTC
[6/7] git commit: Improve tests a bit
Improve tests a bit
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/9b6b1660
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/9b6b1660
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/9b6b1660
Branch: refs/heads/master
Commit: 9b6b1660b003d00888524ad9e8f38d7a218205da
Parents: 8baa36e
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Feb 5 13:07:34 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Feb 5 13:50:12 2014 +0100
----------------------------------------------------------------------
.../java/org/apache/sshd/KeepAliveTest.java | 72 ++++++++++++++++++--
.../src/test/java/org/apache/sshd/ScpTest.java | 14 ++--
.../test/java/org/apache/sshd/ServerTest.java | 7 +-
.../src/test/java/org/apache/sshd/SftpTest.java | 2 +-
.../PEMGeneratorHostKeyProviderTest.java | 8 +++
5 files changed, 86 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b6b1660/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
index 5b8ffcf..a652d42 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
@@ -33,7 +33,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
/**
* TODO Add javadoc
@@ -45,9 +45,9 @@ public class KeepAliveTest extends BaseTest {
private SshServer sshd;
private int port;
- private int heartbeat = 500;
- private int timeout = 1000;
- private int wait = 2000;
+ private int heartbeat = 1000;
+ private int timeout = 2000;
+ private int wait = 4000;
@Before
public void setUp() throws Exception {
@@ -80,7 +80,23 @@ public class KeepAliveTest extends BaseTest {
ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertTrue((state & ClientChannel.CLOSED) != 0);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF, state);
+
+ channel.close(false);
+ client.stop();
+ }
+
+ @Test
+ public void testClientNew() throws Exception {
+ SshClient client = SshClient.setUpDefaultClient();
+ client.start();
+ ClientSession session = client.connect("smx", "localhost", port).await().getSession();
+ session.addPasswordIdentity("smx");
+ session.auth().verify();
+ ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF, state);
channel.close(false);
client.stop();
@@ -96,7 +112,24 @@ public class KeepAliveTest extends BaseTest {
ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertTrue((state & ClientChannel.CLOSED) == 0);
+ assertEquals("Wrong channel state", ClientChannel.TIMEOUT, state);
+
+ channel.close(false);
+ client.stop();
+ }
+
+ @Test
+ public void testClientWithHeartBeatNew() throws Exception {
+ SshClient client = SshClient.setUpDefaultClient();
+ client.getProperties().put(ClientFactoryManager.HEARTBEAT_INTERVAL, Integer.toString(heartbeat));
+ client.start();
+ ClientSession session = client.connect("smx", "localhost", port).await().getSession();
+ session.addPasswordIdentity("smx");
+ session.auth().verify();
+ ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.TIMEOUT, state);
channel.close(false);
client.stop();
@@ -120,7 +153,32 @@ public class KeepAliveTest extends BaseTest {
TestEchoShellFactory.TestEchoShell.latch.await();
int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertTrue((state & ClientChannel.CLOSED) != 0);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF | ClientChannel.OPENED, state);
+
+ channel.close(false);
+ client.stop();
+ }
+
+ @Test
+ public void testShellClosedOnClientTimeoutNew() throws Exception {
+ TestEchoShellFactory.TestEchoShell.latch = new CountDownLatch(1);
+
+ SshClient client = SshClient.setUpDefaultClient();
+ client.start();
+ ClientSession session = client.connect("smx", "localhost", port).await().getSession();
+ session.addPasswordIdentity("smx");
+ session.auth().verify();
+ ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream();
+ channel.setOut(out);
+ channel.setErr(err);
+ channel.open().await();
+
+
+ TestEchoShellFactory.TestEchoShell.latch.await();
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF | ClientChannel.OPENED, state);
channel.close(false);
client.stop();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b6b1660/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
index a280f3d..4b978c5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
@@ -131,7 +131,7 @@ public class ScpTest extends BaseTest {
scp.download("target/scp/remote/out.txt", "target/scp/local/out2.txt");
assertFileLength(new File("target/scp/local/out2.txt"), data.length(), 5000);
- session.close(false);
+ session.close(false).await();
client.stop();
}
@@ -191,7 +191,7 @@ public class ScpTest extends BaseTest {
assertFileLength(new File("target/scp/local/dir/out1.txt"), data.length(), 5000);
assertFileLength(new File("target/scp/local/dir/out2.txt"), data.length(), 5000);
- session.close(false);
+ session.close(false).await();
client.stop();
}
@@ -225,7 +225,7 @@ public class ScpTest extends BaseTest {
assertFileLength(new File("target/scp/local/dir/out1.txt"), data.length(), 5000);
assertFileLength(new File("target/scp/local/dir/out2.txt"), data.length(), 5000);
- session.close(false);
+ session.close(false).await();
client.stop();
}
@@ -259,7 +259,7 @@ public class ScpTest extends BaseTest {
assertFileLength(new File("target/scp/local/out1.txt"), data.length(), 5000);
assertFileLength(new File("target/scp/local/out2.txt"), data.length(), 5000);
- session.close(false);
+ session.close(false).await();
client.stop();
}
@@ -299,7 +299,7 @@ public class ScpTest extends BaseTest {
assertFileLength(new File("target/scp/local/out1.txt"), data.length(), 5000);
assertFileLength(new File("target/scp/local/dir/out2.txt"), data.length(), 5000);
- session.close(false);
+ session.close(false).await();
client.stop();
}
@@ -349,7 +349,7 @@ public class ScpTest extends BaseTest {
assertFileLength(new File("target/scp/local/dir/out2.txt"), data.length(), 5000);
assertEquals(lastMod, new File("target/scp/local/dir/out2.txt").lastModified());
- session.close(false);
+ session.close(false).await();
client.stop();
}
@@ -506,6 +506,8 @@ public class ScpTest extends BaseTest {
os.flush();
header = readLine(is);
assertEquals("E", header);
+ os.write(0);
+ os.flush();
c.disconnect();
return new String(buffer);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b6b1660/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
index b878326..4f4e496 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
@@ -45,6 +45,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -137,7 +138,7 @@ public class ServerTest extends BaseTest {
client.start();
ClientSession s = client.connect("localhost", port).await().getSession();
int res = s.waitFor(ClientSession.CLOSED, 5000);
- assertTrue((res & ClientSession.CLOSED) != 0);
+ assertEquals("Session should be closed", ClientSession.CLOSED | ClientSession.WAIT_AUTH, res);
}
@Test
@@ -145,7 +146,7 @@ public class ServerTest extends BaseTest {
final CountDownLatch latch = new CountDownLatch(1);
TestEchoShellFactory.TestEchoShell.latch = new CountDownLatch(1);
- sshd.getProperties().put(SshServer.IDLE_TIMEOUT, "1000");
+ sshd.getProperties().put(SshServer.IDLE_TIMEOUT, "2500");
sshd.getSessionFactory().addListener(new SessionListener() {
public void sessionCreated(Session session) {
System.out.println("Session created");
@@ -170,7 +171,7 @@ public class ServerTest extends BaseTest {
shell.setErr(err);
shell.open().await();
int res = s.waitFor(ClientSession.CLOSED, 5000);
- assertTrue((res & ClientSession.CLOSED) != 0);
+ assertEquals("Session should be closed", ClientSession.CLOSED | ClientSession.AUTHED, res);
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertTrue(TestEchoShellFactory.TestEchoShell.latch.await(1, TimeUnit.SECONDS));
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b6b1660/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
index f4fba4c..cc0770b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
@@ -215,7 +215,7 @@ public class SftpTest extends BaseTest {
URI url = getClass().getClassLoader().getResource(SshClient.class.getName().replace('.', '/') + ".class").toURI();
URI base = new File(System.getProperty("user.dir")).getAbsoluteFile().toURI();
String path = new File(base.relativize(url).getPath()).getParent() + "/";
-// String path = "target/classes/org/apache/sshd/";
+ path = path.replace('\\', '/');
Vector res = c.ls(path);
for (Object f : res) {
System.out.println(f.toString());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/9b6b1660/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
index 2ff1752..2944239 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
@@ -39,6 +39,10 @@ public class PEMGeneratorHostKeyProviderTest extends BaseTest {
@Test
public void testDSA() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");
@@ -67,6 +71,10 @@ public class PEMGeneratorHostKeyProviderTest extends BaseTest {
@Test
public void testRSA() {
+ if (!SecurityUtils.isBouncyCastleRegistered()) {
+ return;
+ }
+
File path = new File("target/keys");
path.mkdirs();
path = new File(path, "simple.key");