summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-03-17 21:30:46 -0400
committerJames Moger <james.moger@gitblit.com>2014-04-10 18:58:09 -0400
commit245836904ba5cecdc31773cf7c9616396c8ad8c0 (patch)
treec7da9a20350ed911421647ccb1519728081f1c19 /src/test
parent9d44ade215922fd9e7bda7c604b31c31d217d750 (diff)
downloadgitblit-245836904ba5cecdc31773cf7c9616396c8ad8c0.tar.gz
gitblit-245836904ba5cecdc31773cf7c9616396c8ad8c0.zip
Elevate the public key manager to a top-level manager
Diffstat (limited to 'src/test')
-rw-r--r--src/test/config/test-gitblit.properties2
-rw-r--r--src/test/java/com/gitblit/tests/BogusPublicKeyAuthenticator.java39
-rw-r--r--src/test/java/com/gitblit/tests/GitBlitSuite.java18
-rw-r--r--src/test/java/com/gitblit/tests/SshDaemonTest.java25
4 files changed, 30 insertions, 54 deletions
diff --git a/src/test/config/test-gitblit.properties b/src/test/config/test-gitblit.properties
index 7d8e9a79..1a52eaf4 100644
--- a/src/test/config/test-gitblit.properties
+++ b/src/test/config/test-gitblit.properties
@@ -8,7 +8,7 @@ git.searchRepositoriesSubfolders = true
git.enableGitServlet = true
git.daemonPort = 8300
git.sshPort = 29418
-git.sshPublicKeyAuthenticator = com.gitblit.tests.BogusPublicKeyAuthenticator
+git.sshKeysManager = com.gitblit.transport.ssh.MemoryKeyManager
groovy.scriptsFolder = src/main/distrib/data/groovy
groovy.preReceiveScripts = blockpush
groovy.postReceiveScripts = sendmail
diff --git a/src/test/java/com/gitblit/tests/BogusPublicKeyAuthenticator.java b/src/test/java/com/gitblit/tests/BogusPublicKeyAuthenticator.java
deleted file mode 100644
index 80be1a01..00000000
--- a/src/test/java/com/gitblit/tests/BogusPublicKeyAuthenticator.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.security.PublicKey;
-
-import org.apache.sshd.server.session.ServerSession;
-
-import com.gitblit.manager.IAuthenticationManager;
-import com.gitblit.transport.ssh.CachingPublicKeyAuthenticator;
-import com.gitblit.transport.ssh.IKeyManager;
-
-public class BogusPublicKeyAuthenticator extends CachingPublicKeyAuthenticator {
-
- public BogusPublicKeyAuthenticator(IKeyManager keyManager,
- IAuthenticationManager authManager) {
- super(keyManager, authManager);
- }
-
- @Override
- protected boolean doAuthenticate(String username, PublicKey suppliedKey,
- ServerSession session) {
- // TODO(davido): put authenticated user in session
- return true;
- }
-}
diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java
index 17d609e7..b8d3b181 100644
--- a/src/test/java/com/gitblit/tests/GitBlitSuite.java
+++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java
@@ -61,7 +61,7 @@ import com.gitblit.utils.JGitUtils;
MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,
DiffUtilsTest.class, MetricUtilsTest.class, X509UtilsTest.class,
GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class, GitDaemonTest.class,
- GroovyScriptTest.class, LuceneExecutorTest.class, RepositoryModelTest.class, SshDaemonTest.class,
+ SshDaemonTest.class, GroovyScriptTest.class, LuceneExecutorTest.class, RepositoryModelTest.class,
FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdAuthenticationTest.class,
ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class, FileTicketServiceTest.class,
BranchTicketServiceTest.class, RedisTicketServiceTest.class, AuthenticationManagerTest.class })
@@ -78,20 +78,12 @@ public class GitBlitSuite {
static int port = 8280;
static int gitPort = 8300;
static int shutdownPort = 8281;
- static int sshPort = 29418;
-
-// Overriding of keys doesn't seem to work
-// static {
-// try {
-// sshPort = SshUtils.getFreePort();
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// }
+ static int sshPort = 39418;
public static String url = "http://localhost:" + port;
public static String gitServletUrl = "http://localhost:" + port + "/git";
public static String gitDaemonUrl = "git://localhost:" + gitPort;
+ public static String sshDaemonUrl = "ssh://admin@localhost:" + sshPort;
public static String account = "admin";
public static String password = "admin";
@@ -149,9 +141,7 @@ public class GitBlitSuite {
"" + shutdownPort, "--gitPort", "" + gitPort, "--repositoriesFolder",
"\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
GitBlitSuite.USERSCONF.getAbsolutePath(), "--settings", GitBlitSuite.SETTINGS.getAbsolutePath(),
- "--baseFolder", "data");
- // doesn't work
- //, "--sshPort", "" + sshPort);
+ "--baseFolder", "data", "--sshPort", "" + sshPort);
}
});
diff --git a/src/test/java/com/gitblit/tests/SshDaemonTest.java b/src/test/java/com/gitblit/tests/SshDaemonTest.java
index 5294f691..45d31c29 100644
--- a/src/test/java/com/gitblit/tests/SshDaemonTest.java
+++ b/src/test/java/com/gitblit/tests/SshDaemonTest.java
@@ -26,11 +26,15 @@ import org.apache.sshd.ClientChannel;
import org.apache.sshd.ClientSession;
import org.apache.sshd.SshClient;
import org.apache.sshd.common.KeyPairProvider;
+import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.gitblit.Constants;
+import com.gitblit.transport.ssh.IPublicKeyManager;
+import com.gitblit.transport.ssh.MemoryKeyManager;
public class SshDaemonTest extends GitblitUnitTest {
@@ -50,6 +54,27 @@ public class SshDaemonTest extends GitblitUnitTest {
}
}
+ protected MemoryKeyManager getKeyManager() {
+ IPublicKeyManager mgr = gitblit().getPublicKeyManager();
+ if (mgr instanceof MemoryKeyManager) {
+ return (MemoryKeyManager) gitblit().getPublicKeyManager();
+ } else {
+ throw new RuntimeException("unexpected key manager type " + mgr.getClass().getName());
+ }
+ }
+
+ @Before
+ public void prepare() {
+ MemoryKeyManager keyMgr = getKeyManager();
+ keyMgr.addKey("admin", pair.getPublic());
+ }
+
+ @After
+ public void tearDown() {
+ MemoryKeyManager keyMgr = getKeyManager();
+ keyMgr.removeAllKeys("admin");
+ }
+
@Test
public void testPublicKeyAuthentication() throws Exception {
SshClient client = SshClient.setUpDefaultClient();