Started better integration testing setup with Mina

This commit is contained in:
Jeroen van Erp
2015-06-16 14:12:24 +02:00
parent 1c5b462206
commit 7c26ac669a
2 changed files with 65 additions and 4 deletions

View File

@@ -0,0 +1,60 @@
package com.hierynomus.sshj;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.session.ServerSession;
import org.junit.After;
import org.junit.Before;
import java.io.IOException;
import java.net.ServerSocket;
public class SshIntegrationTestBase {
public static final String hostkey = "src/test/resources/hostkey.pem";
public static final String fingerprint = "ce:a7:c1:cf:17:3f:96:49:6a:53:1a:05:0b:ba:90:db";
public static final String hostname = "localhost";
protected SshServer server = null;
@Before
public void setupSshServer() throws IOException {
server = SshServer.setUpDefaultServer();
server.setPort(randomPort());
configureSshServer();
server.start();
}
@After
public void stopSshServer() throws Exception {
server.stop();
}
protected void configureSshServer() {
server.setKeyPairProvider(new FileKeyPairProvider(new String[]{hostkey}));
server.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
return username.equals(password);
}
});
}
private int randomPort() {
try {
ServerSocket s = null;
try {
s = new ServerSocket(0);
return s.getLocalPort();
} finally {
if (s != null)
s.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -1,5 +1,6 @@
package nl.javadude.sshj.connection.channel;
package com.hierynomus.sshj.connection.channel;
import com.hierynomus.sshj.SshIntegrationTestBase;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
@@ -11,8 +12,7 @@ import java.io.IOException;
import static org.hamcrest.MatcherAssert.assertThat;
public class ChannelCloseEofTest {
public class ChannelCloseEofTest extends SshIntegrationTestBase {
private SSHClient sshClient;
@Before
@@ -28,7 +28,7 @@ public class ChannelCloseEofTest {
@Test
public void shouldCorrectlyHandleSessionChannelEof() throws IOException, InterruptedException {
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect("172.16.37.129");
sshClient.connect(server.getHost(), server.getPort());
sshClient.authPassword("jeroen", "jeroen");
Session session = sshClient.startSession();
session.allocateDefaultPTY();
@@ -36,4 +36,5 @@ public class ChannelCloseEofTest {
Thread.sleep(1000);
assertThat("Should still be connected", sshClient.isConnected());
}
}