mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 23:30:55 +03:00
- eh?
This commit is contained in:
@@ -25,13 +25,15 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import net.schmizz.sshj.DefaultConfig;
|
import net.schmizz.sshj.DefaultConfig;
|
||||||
import net.schmizz.sshj.SSHClient;
|
import net.schmizz.sshj.SSHClient;
|
||||||
|
import net.schmizz.sshj.transport.TransportException;
|
||||||
import net.schmizz.sshj.transport.verification.OpenSSHKnownHosts;
|
import net.schmizz.sshj.transport.verification.OpenSSHKnownHosts;
|
||||||
|
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;
|
||||||
import net.schmizz.sshj.userauth.UserAuthException;
|
import net.schmizz.sshj.userauth.UserAuthException;
|
||||||
|
|
||||||
public class IntegrationTest {
|
public class IntegrationTest {
|
||||||
|
|
||||||
private static final int DOCKER_PORT = 2222;
|
private static final int DOCKER_PORT = 2222;
|
||||||
private static final String USERNAME = "sshj";
|
private static final String USERNAME = "sickp";
|
||||||
private final static String SERVER_IP = System.getProperty("serverIP", "127.0.0.1");
|
private final static String SERVER_IP = System.getProperty("serverIP", "127.0.0.1");
|
||||||
|
|
||||||
@Test @Ignore // Should only be enabled for testing against VM
|
@Test @Ignore // Should only be enabled for testing against VM
|
||||||
@@ -44,20 +46,37 @@ public class IntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldConnect() throws IOException {
|
public void shouldAcceptCorrectKey() throws IOException {
|
||||||
SSHClient sshClient = new SSHClient(new DefaultConfig());
|
SSHClient sshClient = new SSHClient(new DefaultConfig());
|
||||||
sshClient.addHostKeyVerifier("d3:6a:a9:52:05:ab:b5:48:dd:73:60:18:0c:3a:f0:a3"); // test-containers/ssh_host_ecdsa_key's fingerprint
|
sshClient.addHostKeyVerifier("d3:6a:a9:52:05:ab:b5:48:dd:73:60:18:0c:3a:f0:a3"); // test-containers/ssh_host_ecdsa_key's fingerprint
|
||||||
sshClient.connect(SERVER_IP, DOCKER_PORT);
|
sshClient.connect(SERVER_IP, DOCKER_PORT);
|
||||||
|
assertThat("Is connected", sshClient.isConnected());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = TransportException.class)
|
||||||
|
public void shouldDeclineWrongKey() throws IOException {
|
||||||
|
SSHClient sshClient = new SSHClient(new DefaultConfig());
|
||||||
|
sshClient.addHostKeyVerifier("d4:6a:a9:52:05:ab:b5:48:dd:73:60:18:0c:3a:f0:a3");
|
||||||
|
sshClient.connect(SERVER_IP, DOCKER_PORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldConnect() throws IOException {
|
||||||
|
SSHClient sshClient = getConnectedClient();
|
||||||
sshClient.authPublickey(USERNAME, "src/test/resources/id_rsa");
|
sshClient.authPublickey(USERNAME, "src/test/resources/id_rsa");
|
||||||
assertThat("Is connected", sshClient.isAuthenticated());
|
assertThat("Is authenitcated", sshClient.isAuthenticated());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = UserAuthException.class)
|
@Test(expected = UserAuthException.class)
|
||||||
public void shouldFailWithWrongKey() throws IOException {
|
public void shouldFailWithWrongKey() throws IOException {
|
||||||
SSHClient sshClient = new SSHClient(new DefaultConfig());
|
getConnectedClient().authPublickey(USERNAME, "src/test/resources/id_dsa");
|
||||||
sshClient.addHostKeyVerifier("d3:6a:a9:52:05:ab:b5:48:dd:73:60:18:0c:3a:f0:a3"); // test-containers/ssh_host_ecdsa_key's fingerprint
|
|
||||||
sshClient.connect(SERVER_IP, DOCKER_PORT);
|
|
||||||
sshClient.authPublickey(USERNAME, "src/test/resources/id_dsa");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SSHClient getConnectedClient() throws IOException {
|
||||||
|
SSHClient sshClient = new SSHClient(new DefaultConfig());
|
||||||
|
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
|
||||||
|
sshClient.connect(SERVER_IP, DOCKER_PORT);
|
||||||
|
|
||||||
|
return sshClient;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
FROM sickp/alpine-sshd:7.5
|
FROM sickp/alpine-sshd:7.5
|
||||||
|
ADD https://raw.githubusercontent.com/Igerly/sshj/master/src/test/resources/id_rsa.pub /home/sickp/.ssh/authorized_keys
|
||||||
ADD id_rsa.pub /home/sshj/.ssh/authorized_keys
|
|
||||||
|
|
||||||
ADD test-container/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key
|
|
||||||
ADD test-container/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
|
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
echo "root:smile" | chpasswd && \
|
echo "root:sunshine" | chpasswd && \
|
||||||
adduser -D -s /bin/ash sshj && \
|
adduser -D -s /bin/ash sickp && \
|
||||||
passwd -u sshj && \
|
passwd -u sickp && \
|
||||||
chmod 600 /etc/ssh/ssh_host_ecdsa_key && \
|
chown -R sickp:sickp /home/sickp
|
||||||
chmod 644 /etc/ssh/ssh_host_ecdsa_key.pub && \
|
|
||||||
chown -R sshj:sshj /home/sshj
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user