From 9d697ede120dd5b1b898fb90912d970a8e7e4c13 Mon Sep 17 00:00:00 2001 From: Iger Date: Sun, 3 Dec 2017 22:28:02 +0200 Subject: [PATCH] - minor improvements --- .../com/hierynomus/sshj/IntegrationTest.java | 20 ++++++++++++++++--- src/test/resources/Dockerfile | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/hierynomus/sshj/IntegrationTest.java b/src/test/java/com/hierynomus/sshj/IntegrationTest.java index 1fefa5a9..89f66c7f 100644 --- a/src/test/java/com/hierynomus/sshj/IntegrationTest.java +++ b/src/test/java/com/hierynomus/sshj/IntegrationTest.java @@ -26,9 +26,14 @@ import org.junit.Test; import net.schmizz.sshj.DefaultConfig; import net.schmizz.sshj.SSHClient; import net.schmizz.sshj.transport.verification.OpenSSHKnownHosts; +import net.schmizz.sshj.userauth.UserAuthException; public class IntegrationTest { + private static final int DOCKER_PORT = 2222; + private static final String USERNAME = "sshj"; + private final static String SERVER_IP = System.getProperty("serverIP", "127.0.0.1"); + @Test @Ignore // Should only be enabled for testing against VM public void shouldConnectVM() throws IOException { SSHClient sshClient = new SSHClient(new DefaultConfig()); @@ -38,12 +43,21 @@ public class IntegrationTest { assertThat("Is connected", sshClient.isAuthenticated()); } - @Test // Should only be enabled for testing against VM + @Test public void shouldConnect() throws IOException { 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.connect("127.0.0.1", 2222); - sshClient.authPublickey("sshj", "src/test/resources/id_rsa"); + sshClient.connect(SERVER_IP, DOCKER_PORT); + sshClient.authPublickey(USERNAME, "src/test/resources/id_rsa"); assertThat("Is connected", sshClient.isAuthenticated()); } + + @Test(expected = UserAuthException.class) + public void shouldFailWithWrongKey() throws IOException { + 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.connect(SERVER_IP, DOCKER_PORT); + sshClient.authPublickey(USERNAME, "src/test/resources/id_dsa"); + } + } diff --git a/src/test/resources/Dockerfile b/src/test/resources/Dockerfile index 93e13301..ab836e27 100644 --- a/src/test/resources/Dockerfile +++ b/src/test/resources/Dockerfile @@ -1,4 +1,5 @@ FROM sickp/alpine-sshd:7.5 + ADD id_rsa.pub /home/sshj/.ssh/authorized_keys ADD test-container/ssh_host_ecdsa_key /etc/ssh/ssh_host_ecdsa_key