KARAF-3882: more work on test.

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/85bff8a9
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/85bff8a9
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/85bff8a9

Branch: refs/heads/master
Commit: 85bff8a98ab08a9911b9580a583ad10c8482027b
Parents: 4a5ce23
Author: Benson Margulies <[email protected]>
Authored: Sun Jul 26 21:15:27 2015 -0400
Committer: Benson Margulies <[email protected]>
Committed: Sun Jul 26 21:15:27 2015 -0400

----------------------------------------------------------------------
 .../apache/karaf/itests/SshKeyFormatTest.java   | 39 +++++++++++++++-----
 1 file changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/85bff8a9/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java 
b/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
index a57b13a..3e0e631 100644
--- a/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
@@ -22,22 +22,19 @@ package org.apache.karaf.itests;
 
 import org.apache.sshd.ClientSession;
 import org.apache.sshd.SshClient;
+import org.apache.sshd.client.ServerKeyVerifier;
 import org.apache.sshd.client.future.ConnectFuture;
 import org.junit.Test;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.TestProbeBuilder;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.OutputStream;
-import java.util.Map;
+import java.net.SocketAddress;
+import java.security.PublicKey;
 
-import static org.ops4j.pax.exam.CoreOptions.composite;
-import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.*;
 import static 
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
 
-
 /**
  * Test use of PEM keys.
  */
@@ -47,8 +44,9 @@ public class SshKeyFormatTest extends SshCommandTestBase {
     public Option[] config() {
         File keyFile = new File("src/test/resources/test.pem");
         return options(composite(super.config()),
-                editConfigurationFilePut("org.apache.karaf.shell.cfg", 
"hostKey", keyFile.getAbsolutePath()),
-                editConfigurationFilePut("org.apache.karaf.shell.cfg", 
"hostKeyFormat", "PEM")
+                editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", 
"hostKey", keyFile.getAbsolutePath()),
+                editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", 
"hostKeyFormat", "PEM"),
+                
vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005")
                 );
     }
 
@@ -56,10 +54,31 @@ public class SshKeyFormatTest extends SshCommandTestBase {
     @Test
     public void usePemKey() throws Exception {
         SshClient client = SshClient.setUpDefaultClient();
+        client.setServerKeyVerifier(new ServerKeyVerifier() {
+            @Override
+            public boolean verifyServerKey(ClientSession sshClientSession, 
SocketAddress remoteAddress, PublicKey serverKey) {
+                System.err.println(serverKey.getAlgorithm());
+                System.err.println(serverKey.getFormat());
+                StringBuilder dump = new StringBuilder();
+                for (byte b : serverKey.getEncoded()) {
+                    dump.append(String.format("%02x", b));
+                }
+                System.err.println(dump.toString());
+                return true;
+            }
+        });
         client.start();
         ConnectFuture future = client.connect("karaf", "localhost", 
8101).await();
         ClientSession session = future.getSession();
-        Map<Object, Object> metadata = session.getMetadataMap();
+        int ret = ClientSession.WAIT_AUTH;
+        while ((ret & ClientSession.WAIT_AUTH) != 0) {
+            session.addPasswordIdentity("karaf");
+            session.auth().verify();
+            ret = session.waitFor(ClientSession.WAIT_AUTH | 
ClientSession.CLOSED | ClientSession.AUTHED, 0);
+        }
+        if ((ret & ClientSession.CLOSED) != 0) {
+            throw new Exception("Could not open SSH channel");
+        }
         session.close(true);
     }
 }

Reply via email to