mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 15:20:54 +03:00
Started better integration testing setup with Mina
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user