summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/gitblit/tests/SshDaemonTest.java
diff options
context:
space:
mode:
authorDavid Ostrovsky <david@ostrovsky.org>2014-03-16 22:55:30 +0100
committerJames Moger <james.moger@gitblit.com>2014-04-10 18:58:08 -0400
commit5d58a05a9843ec90d06ca42061ff638418f73687 (patch)
tree1d6e8b7cdd2d5f24659cb1f0766719a3ba62a79a /src/test/java/com/gitblit/tests/SshDaemonTest.java
parent75ebd391b88884581b1139c87c98bb687941a8fe (diff)
downloadgitblit-5d58a05a9843ec90d06ca42061ff638418f73687.tar.gz
gitblit-5d58a05a9843ec90d06ca42061ff638418f73687.zip
Add SSH daemon test
Diffstat (limited to 'src/test/java/com/gitblit/tests/SshDaemonTest.java')
-rw-r--r--src/test/java/com/gitblit/tests/SshDaemonTest.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/test/java/com/gitblit/tests/SshDaemonTest.java b/src/test/java/com/gitblit/tests/SshDaemonTest.java
new file mode 100644
index 00000000..5294f691
--- /dev/null
+++ b/src/test/java/com/gitblit/tests/SshDaemonTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.security.KeyPair;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.sshd.ClientChannel;
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.SshClient;
+import org.apache.sshd.common.KeyPairProvider;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.gitblit.Constants;
+
+public class SshDaemonTest extends GitblitUnitTest {
+
+ private static final AtomicBoolean started = new AtomicBoolean(false);
+ private static KeyPair pair;
+
+ @BeforeClass
+ public static void startGitblit() throws Exception {
+ started.set(GitBlitSuite.startGitblit());
+ pair = SshUtils.createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA);
+ }
+
+ @AfterClass
+ public static void stopGitblit() throws Exception {
+ if (started.get()) {
+ GitBlitSuite.stopGitblit();
+ }
+ }
+
+ @Test
+ public void testPublicKeyAuthentication() throws Exception {
+ SshClient client = SshClient.setUpDefaultClient();
+ client.start();
+ ClientSession session = client.connect("localhost", GitBlitSuite.sshPort).await().getSession();
+ pair.getPublic().getEncoded();
+ assertTrue(session.authPublicKey("admin", pair).await().isSuccess());
+ }
+
+ @Test
+ public void testVersionCommand() throws Exception {
+ SshClient client = SshClient.setUpDefaultClient();
+ client.start();
+ ClientSession session = client.connect("localhost", GitBlitSuite.sshPort).await().getSession();
+ pair.getPublic().getEncoded();
+ assertTrue(session.authPublicKey("admin", pair).await().isSuccess());
+
+ ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_EXEC, "gitblit version");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Writer w = new OutputStreamWriter(baos);
+ w.close();
+ channel.setIn(new ByteArrayInputStream(baos.toByteArray()));
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream();
+ channel.setOut(out);
+ channel.setErr(err);
+ channel.open();
+
+ channel.waitFor(ClientChannel.CLOSED, 0);
+
+ String result = out.toString().trim();
+ channel.close(false);
+ client.stop();
+
+ assertEquals(Constants.getGitBlitVersion(), result);
+ }
+}