summaryrefslogtreecommitdiffstats
path: root/tests/com
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-12-04 16:55:42 -0500
committerJames Moger <james.moger@gitblit.com>2011-12-04 16:55:42 -0500
commit93f4729cdfc856d2a3b155bcf3e97f85b47ce760 (patch)
tree791870de5a0cfcd1072d953b17e4ba4c95f57dfd /tests/com
parentb774dedd7f0ab1567e790610b70eb7f2241423fb (diff)
downloadgitblit-93f4729cdfc856d2a3b155bcf3e97f85b47ce760.tar.gz
gitblit-93f4729cdfc856d2a3b155bcf3e97f85b47ce760.zip
Implemented ConfigUserService. Fixed and deprecated FileUserService.
Diffstat (limited to 'tests/com')
-rw-r--r--tests/com/gitblit/tests/FederationTests.java2
-rw-r--r--tests/com/gitblit/tests/GitBlitSuite.java7
-rw-r--r--tests/com/gitblit/tests/GitBlitTest.java4
-rw-r--r--tests/com/gitblit/tests/GitServletTest.java2
-rw-r--r--tests/com/gitblit/tests/SyndicationUtilsTest.java2
-rw-r--r--tests/com/gitblit/tests/UserServiceTest.java100
6 files changed, 109 insertions, 8 deletions
diff --git a/tests/com/gitblit/tests/FederationTests.java b/tests/com/gitblit/tests/FederationTests.java
index 66bb949c..e81867b9 100644
--- a/tests/com/gitblit/tests/FederationTests.java
+++ b/tests/com/gitblit/tests/FederationTests.java
@@ -47,7 +47,7 @@ public class FederationTests extends TestCase {
GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
"" + shutdownPort, "--repositoriesFolder",
"\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
- "distrib/users.properties");
+ "distrib/users.conf");
}
});
diff --git a/tests/com/gitblit/tests/GitBlitSuite.java b/tests/com/gitblit/tests/GitBlitSuite.java
index ad87cb0b..a2ab3e8b 100644
--- a/tests/com/gitblit/tests/GitBlitSuite.java
+++ b/tests/com/gitblit/tests/GitBlitSuite.java
@@ -25,8 +25,8 @@ import junit.framework.TestSuite;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepository;
+import com.gitblit.ConfigUserService;
import com.gitblit.FileSettings;
-import com.gitblit.FileUserService;
import com.gitblit.GitBlit;
import com.gitblit.GitBlitException;
import com.gitblit.GitBlitServer;
@@ -57,6 +57,7 @@ public class GitBlitSuite extends TestSetup {
suite.addTestSuite(JsonUtilsTest.class);
suite.addTestSuite(ByteFormatTest.class);
suite.addTestSuite(ObjectCacheTest.class);
+ suite.addTestSuite(UserServiceTest.class);
suite.addTestSuite(MarkdownUtilsTest.class);
suite.addTestSuite(JGitUtilsTest.class);
suite.addTestSuite(SyndicationUtilsTest.class);
@@ -91,7 +92,7 @@ public class GitBlitSuite extends TestSetup {
GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
"" + shutdownPort, "--repositoriesFolder",
"\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
- "distrib/users.properties");
+ "distrib/users.conf");
}
});
@@ -111,7 +112,7 @@ public class GitBlitSuite extends TestSetup {
protected void setUp() throws Exception {
FileSettings settings = new FileSettings("distrib/gitblit.properties");
GitBlit.self().configureContext(settings, true);
- FileUserService loginService = new FileUserService(new File("distrib/users.properties"));
+ ConfigUserService loginService = new ConfigUserService(new File("distrib/users.conf"));
GitBlit.self().setUserService(loginService);
if (REPOSITORIES.exists() || REPOSITORIES.mkdirs()) {
diff --git a/tests/com/gitblit/tests/GitBlitTest.java b/tests/com/gitblit/tests/GitBlitTest.java
index 669b25ac..6d36d497 100644
--- a/tests/com/gitblit/tests/GitBlitTest.java
+++ b/tests/com/gitblit/tests/GitBlitTest.java
@@ -96,7 +96,7 @@ public class GitBlitTest extends TestCase {
assertTrue(settings.getInteger("realm.realmFile", 5) == 5);
assertTrue(settings.getBoolean("git.enableGitServlet", false));
- assertTrue(settings.getString("realm.userService", null).equals("users.properties"));
+ assertTrue(settings.getString("realm.userService", null).equals("users.conf"));
assertTrue(settings.getInteger("realm.minPasswordLength", 0) == 5);
List<String> mdExtensions = settings.getStrings("web.markdownExtensions");
assertTrue(mdExtensions.size() > 0);
@@ -117,7 +117,7 @@ public class GitBlitTest extends TestCase {
assertEquals(5, GitBlit.getInteger("realm.userService", 5));
assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));
- assertEquals("distrib/users.properties", GitBlit.getString("realm.userService", null));
+ assertEquals("distrib/users.conf", GitBlit.getString("realm.userService", null));
assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0));
List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");
assertTrue(mdExtensions.size() > 0);
diff --git a/tests/com/gitblit/tests/GitServletTest.java b/tests/com/gitblit/tests/GitServletTest.java
index 89466d7f..db8182de 100644
--- a/tests/com/gitblit/tests/GitServletTest.java
+++ b/tests/com/gitblit/tests/GitServletTest.java
@@ -34,7 +34,7 @@ public class GitServletTest {
GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
"" + shutdownPort, "--repositoriesFolder",
"\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
- "distrib/users.properties");
+ "distrib/users.conf");
}
});
diff --git a/tests/com/gitblit/tests/SyndicationUtilsTest.java b/tests/com/gitblit/tests/SyndicationUtilsTest.java
index 0a2420f6..448874f4 100644
--- a/tests/com/gitblit/tests/SyndicationUtilsTest.java
+++ b/tests/com/gitblit/tests/SyndicationUtilsTest.java
@@ -62,7 +62,7 @@ public class SyndicationUtilsTest extends TestCase {
Set<String> links = new HashSet<String>();
for (int i = 0; i < 2; i++) {
List<FeedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url,
- "ticgit.git", "master", 5, i, GitBlitSuite.account,
+ "ticgit.git", "deving", 5, i, GitBlitSuite.account,
GitBlitSuite.password.toCharArray());
assertTrue(feed != null);
assertTrue(feed.size() > 0);
diff --git a/tests/com/gitblit/tests/UserServiceTest.java b/tests/com/gitblit/tests/UserServiceTest.java
new file mode 100644
index 00000000..3dfdf7ac
--- /dev/null
+++ b/tests/com/gitblit/tests/UserServiceTest.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2011 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.File;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import com.gitblit.ConfigUserService;
+import com.gitblit.FileUserService;
+import com.gitblit.IUserService;
+import com.gitblit.models.UserModel;
+
+public class UserServiceTest extends TestCase {
+
+ public void testFileUserService() throws IOException {
+ File file = new File("us-test.properties");
+ file.delete();
+ test(new FileUserService(file));
+ file.delete();
+ }
+
+ public void testConfigUserService() throws IOException {
+ File file = new File("us-test.conf");
+ file.delete();
+ test(new ConfigUserService(file));
+ file.delete();
+ }
+
+ protected void test(IUserService service) {
+
+ UserModel admin = service.getUserModel("admin");
+ assertTrue(admin == null);
+
+ // add admin
+ admin = new UserModel("admin");
+ admin.password = "password";
+ admin.canAdmin = true;
+ admin.excludeFromFederation = true;
+ service.updateUserModel(admin);
+ admin = null;
+
+ // add new user
+ UserModel newUser = new UserModel("test");
+ newUser.password = "testPassword";
+ newUser.addRepository("repo1");
+ newUser.addRepository("repo2");
+ newUser.addRepository("sub/repo3");
+ service.updateUserModel(newUser);
+
+ // add one more new user and then test reload of first new user
+ newUser = new UserModel("garbage");
+ newUser.password = "garbage";
+ service.updateUserModel(newUser);
+
+ // confirm all added users
+ assertEquals(3, service.getAllUsernames().size());
+
+ // confirm reloaded test user
+ newUser = service.getUserModel("test");
+ assertEquals("testPassword", newUser.password);
+ assertEquals(3, newUser.repositories.size());
+ assertTrue(newUser.hasRepository("repo1"));
+ assertTrue(newUser.hasRepository("repo2"));
+ assertTrue(newUser.hasRepository("sub/repo3"));
+
+ // confirm authentication of test user
+ UserModel testUser = service.authenticate("test", "testPassword".toCharArray());
+ assertEquals("test", testUser.username);
+ assertEquals("testPassword", testUser.password);
+
+ // delete a repository role and confirm role removal from test user
+ service.deleteRepositoryRole("repo2");
+ testUser = service.getUserModel("test");
+ assertEquals(2, testUser.repositories.size());
+
+ // delete garbage user and confirm user count
+ service.deleteUser("garbage");
+ assertEquals(2, service.getAllUsernames().size());
+
+ // rename repository and confirm role change for test user
+ service.renameRepositoryRole("repo1", "newrepo1");
+ testUser = service.getUserModel("test");
+ assertTrue(testUser.hasRepository("newrepo1"));
+ }
+} \ No newline at end of file