]> source.dussan.org Git - gitblit.git/commitdiff
Update unit tests for refactored architecture
authorJames Moger <james.moger@gitblit.com>
Mon, 25 Nov 2013 02:28:27 +0000 (21:28 -0500)
committerJames Moger <james.moger@gitblit.com>
Fri, 29 Nov 2013 16:05:51 +0000 (11:05 -0500)
Change-Id: I04639db977c515e5e1090ef8f0e1ce858820cb03

12 files changed:
src/main/distrib/data/groovy/sendmail-html.groovy
src/main/java/com/gitblit/git/GitblitReceivePack.java
src/main/java/com/gitblit/servlet/RpcFilter.java
src/test/config/test-gitblit.properties
src/test/config/test-ui-users.conf
src/test/config/test-users.conf
src/test/java/com/gitblit/tests/GitBlitSuite.java
src/test/java/com/gitblit/tests/GitBlitTest.java
src/test/java/com/gitblit/tests/GitServletTest.java
src/test/java/com/gitblit/tests/GroovyScriptTest.java
src/test/java/com/gitblit/tests/LuceneExecutorTest.java
src/test/java/com/gitblit/tests/RpcTests.java

index 2912e5645698151fdadaa049ba5114dcf6100049..2692556818f8aad77644d4c21460aa92594749b1 100644 (file)
@@ -500,9 +500,9 @@ mailWriter.baseCommitDiffUrl = baseCommitDiffUrl
 mailWriter.forwardSlashChar = forwardSlashChar\r
 mailWriter.commands = commands\r
 mailWriter.url = url\r
-mailWriter.mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true)\r
-mailWriter.includeGravatar = GitBlit.getBoolean(Keys.web.allowGravatar, true)\r
-mailWriter.shortCommitIdLength = GitBlit.getInteger(Keys.web.shortCommitIdLength, 8)\r
+mailWriter.mountParameters = gitblit.getBoolean(Keys.web.mountParameters, true)\r
+mailWriter.includeGravatar = gitblit.getBoolean(Keys.web.allowGravatar, true)\r
+mailWriter.shortCommitIdLength = gitblit.getInteger(Keys.web.shortCommitIdLength, 8)\r
 \r
 def content = mailWriter.write()\r
 \r
index 11b1bda8468f6a22d1c11bc2732dfdac6303f2e3..95d17fa5a626ab1ce3d00bf2780f8a26a65956ba 100644 (file)
@@ -103,7 +103,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                this.settings = gitblit.getSettings();\r
                this.gitblit = gitblit;\r
                this.repository = repository;\r
-               this.user = user == null ? UserModel.ANONYMOUS : user;\r
+               this.user = user;\r
                this.groovyDir = gitblit.getHooksFolder();\r
                try {\r
                        // set Grape root\r
index 02f419ffede5579611b48487abc2966e0f4c7792..6163252d1a1939ec80e4d2c45993c4c756aa2556 100644 (file)
@@ -27,11 +27,9 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
-import com.gitblit.Constants;\r
+import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.IStoredSettings;\r
 import com.gitblit.Keys;\r
-import com.gitblit.Constants.RpcRequest;\r
-import com.gitblit.Keys.web;\r
 import com.gitblit.manager.IRuntimeManager;\r
 import com.gitblit.manager.ISessionManager;\r
 import com.gitblit.models.UserModel;\r
@@ -138,10 +136,8 @@ public class RpcFilter extends AuthenticationFilter {
                                        return;\r
                                }\r
                                // valid user, but not for requested access. send 403.\r
-                               if (runtimeManager.isDebugMode()) {\r
-                                       logger.info(MessageFormat.format("RPC: {0} forbidden to access {1}",\r
+                               logger.warn(MessageFormat.format("RPC: {0} forbidden to access {1}",\r
                                                        user.username, fullUrl));\r
-                               }\r
                                httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);\r
                                return;\r
                        }\r
index 0d797b401d1af0a4ef366070af241cdd35fafe39..e636469ef23f084093672e1a6113a13f88a16cc6 100644 (file)
@@ -6,13 +6,14 @@ git.defaultAccessRestriction = NONE
 git.repositoriesFolder = ${baseFolder}/git
 git.searchRepositoriesSubfolders = true
 git.enableGitServlet = true
+git.daemonPort = 8300
 groovy.scriptsFolder = src/main/distrib/data/groovy
 groovy.preReceiveScripts = blockpush
 groovy.postReceiveScripts = sendmail
 web.authenticateViewPages = false
 web.authenticateAdminPages = true
 web.allowCookieAuthentication = true
-realm.userService = ${baseFolder}/src/test/config/test-users.conf
+realm.userService = src/test/config/test-users.conf
 realm.passwordStorage = md5
 realm.minPasswordLength = 5
 web.siteName = Test Gitblit
index 5bf35f3be4683b42c848530fbb253474e71d5644..fb23f25d800c3a978e477d6e2f4e99433614d35b 100644 (file)
@@ -4,19 +4,19 @@
        role = "#admin"
        role = "#notfederated"
 [user "userthree"]
-       password = StoredInLDAP
+       password = "#externalAccount"
        cookie = d7d3894fc517612aa6c595555b6e1ab8e147e597
        displayName = User Three
        emailAddress = userthree@gitblit.com
        role = "#admin"
 [user "userone"]
-       password = StoredInLDAP
+       password = "#externalAccount"
        cookie = c97cd38e50858cd0b389ec61b18fb9a89b4da54c
        displayName = User One
        emailAddress = User.One@gitblit.com
        role = "#admin"
 [user "usertwo"]
-       password = StoredInLDAP
+       password = "#externalAccount"
        cookie = 498ca9bd2841d39050fa45d1d737b9f9f767858d
        displayName = User Two
        emailAddress = usertwo@gitblit.com
index 4f94787233873cc80dffcd2d4df801d065a668f2..b665fd5beead5c3a1635b9f95acb098fa02cc7b0 100644 (file)
@@ -3,6 +3,10 @@
        cookie = dd94709528bb1c83d08f3088d4043f4742891f4f
        role = "#admin"
        role = "#notfederated"
+[user "sampleuser"]
+       password = sampleuser
+       cookie = 6e07ed42149fc166206319faffdfba2e2ec82e43
+       role = "#none"
 [team "admins"]
        role = "#none"
        user = admin
index 57e94e51a56e7172b77f1c5322fdac2e970780a4..7fc6fe0e30ad0148601c8c2ad09a0e211699d8f6 100644 (file)
@@ -65,6 +65,8 @@ import com.gitblit.utils.JGitUtils;
                ModelUtilsTest.class, JnaUtilsTest.class })\r
 public class GitBlitSuite {\r
 \r
+       public static final File BASEFOLDER = new File("data");\r
+\r
        public static final File REPOSITORIES = new File("data/git");\r
 \r
        public static final File SETTINGS = new File("src/test/config/test-gitblit.properties");\r
@@ -83,30 +85,35 @@ public class GitBlitSuite {
 \r
        private static AtomicBoolean started = new AtomicBoolean(false);\r
 \r
-       public static Repository getHelloworldRepository() throws Exception {\r
+       public static Repository getHelloworldRepository() {\r
                return getRepository("helloworld.git");\r
        }\r
 \r
-       public static Repository getTicgitRepository() throws Exception {\r
+       public static Repository getTicgitRepository() {\r
                return getRepository("ticgit.git");\r
        }\r
 \r
-       public static Repository getJGitRepository() throws Exception {\r
+       public static Repository getJGitRepository() {\r
                return getRepository("test/jgit.git");\r
        }\r
 \r
-       public static Repository getAmbitionRepository() throws Exception {\r
+       public static Repository getAmbitionRepository() {\r
                return getRepository("test/ambition.git");\r
        }\r
 \r
-       public static Repository getGitectiveRepository() throws Exception {\r
+       public static Repository getGitectiveRepository() {\r
                return getRepository("test/gitective.git");\r
        }\r
 \r
-       private static Repository getRepository(String name) throws Exception {\r
-               File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);\r
-               Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();\r
-               return repository;\r
+       private static Repository getRepository(String name) {\r
+               try {\r
+                       File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);\r
+                       Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();\r
+                       return repository;\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+               return null;\r
        }\r
 \r
        public static boolean startGitblit() throws Exception {\r
index 692afb767b29a4b394455475c6da7fac462680f8..d391351326054e027c258c6fc89a06b4eaf47400 100644 (file)
@@ -156,7 +156,7 @@ public class GitBlitTest extends GitblitUnitTest {
                assertEquals(5, settings().getInteger("realm.userService", 5));\r
 \r
                assertTrue(settings().getBoolean("git.enableGitServlet", false));\r
-               assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), settings().getString("realm.userService", null));\r
+               assertEquals("src/test/config/test-users.conf", settings().getString("realm.userService", null));\r
                assertEquals(5, settings().getInteger("realm.minPasswordLength", 0));\r
                List<String> mdExtensions = settings().getStrings("web.markdownExtensions");\r
                assertTrue(mdExtensions.size() > 0);\r
index b197a915633f82bdda3cc9d98c788f1c67a076e9..bc392885437a348bbd5c3a30851e4a28ec605533 100644 (file)
@@ -624,18 +624,28 @@ public class GitServletTest extends GitblitUnitTest {
 \r
        private void testRefChange(AccessPermission permission, Status expectedCreate, Status expectedDelete, Status expectedRewind) throws Exception {\r
 \r
+               final String originName = "ticgit.git";\r
+               final String forkName = "refchecks/ticgit.git";\r
+               final String workingCopy = "refchecks/ticgit-wc";\r
+\r
+\r
+               // lower access restriction on origin repository\r
+               RepositoryModel origin = repositories().getRepositoryModel(originName);\r
+               origin.accessRestriction = AccessRestrictionType.NONE;\r
+               repositories().updateRepositoryModel(origin.name, origin, false);\r
+\r
                UserModel user = getUser();\r
                delete(user);\r
 \r
                CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password);\r
 \r
                // fork from original to a temporary bare repo\r
-               File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit.git");\r
+               File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName);\r
                if (refChecks.exists()) {\r
                        FileUtils.delete(refChecks, FileUtils.RECURSIVE);\r
                }\r
                CloneCommand clone = Git.cloneRepository();\r
-               clone.setURI(MessageFormat.format("{0}/ticgit.git", url));\r
+               clone.setURI(url + "/" + originName);\r
                clone.setDirectory(refChecks);\r
                clone.setBare(true);\r
                clone.setCloneAllBranches(true);\r
@@ -643,7 +653,7 @@ public class GitServletTest extends GitblitUnitTest {
                GitBlitSuite.close(clone.call());\r
 \r
                // elevate repository to clone permission\r
-               RepositoryModel model = repositories().getRepositoryModel("refchecks/ticgit.git");\r
+               RepositoryModel model = repositories().getRepositoryModel(forkName);\r
                switch (permission) {\r
                        case VIEW:\r
                                model.accessRestriction = AccessRestrictionType.CLONE;\r
@@ -663,7 +673,7 @@ public class GitServletTest extends GitblitUnitTest {
                repositories().updateRepositoryModel(model.name, model, false);\r
 \r
                // clone temp bare repo to working copy\r
-               File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit-wc");\r
+               File local = new File(GitBlitSuite.REPOSITORIES, workingCopy);\r
                if (local.exists()) {\r
                        FileUtils.delete(local, FileUtils.RECURSIVE);\r
                }\r
index 1b5b0f39e3b9addc9d17fd24418fcca1ac58797d..ff40972f4fd40cec6f338c5d78c81e2bffc20ecb 100644 (file)
@@ -338,6 +338,10 @@ public class GroovyScriptTest extends GitblitUnitTest {
                        return dv;\r
                }\r
 \r
+               public int getInteger(String key, int defaultValue) {\r
+                       return defaultValue;\r
+               }\r
+\r
                public void sendMail(String subject, String message, Collection<String> toAddresses) {\r
                        messages.add(new MockMail(subject, message, toAddresses));\r
                }\r
index 8ffe84697ac80236b556ef5d8713b33b9f239178..319c09c12a8761bf07fbe61166a0db414317fe5b 100644 (file)
@@ -48,8 +48,8 @@ public class LuceneExecutorTest extends GitblitUnitTest {
        private LuceneService newLuceneExecutor() {\r
                MemorySettings settings = new MemorySettings();\r
                settings.put(Keys.git.repositoriesFolder, GitBlitSuite.REPOSITORIES);\r
-               RuntimeManager runtime = new RuntimeManager(settings);\r
-               UserManager users = new UserManager(runtime);\r
+               RuntimeManager runtime = new RuntimeManager(settings, GitBlitSuite.BASEFOLDER).start();\r
+               UserManager users = new UserManager(runtime).start();\r
                RepositoryManager repos = new RepositoryManager(runtime, users);\r
                return new LuceneService(settings, repos);\r
        }\r
@@ -78,7 +78,7 @@ public class LuceneExecutorTest extends GitblitUnitTest {
        }\r
 \r
        @Test\r
-       public void testIndex() throws Exception {\r
+       public void testIndex() {\r
                // reindex helloworld\r
                Repository repository = GitBlitSuite.getHelloworldRepository();\r
                RepositoryModel model = newRepositoryModel(repository);\r
index e1ba9072c1b4b60c3661f3f7a47196549000e43c..ced1a130c57627466ff16cd43c43d2fec8e4453d 100644 (file)
@@ -32,7 +32,7 @@ import com.gitblit.Constants.AccessRestrictionType;
 import com.gitblit.Constants.AuthorizationControl;\r
 import com.gitblit.Constants.PermissionType;\r
 import com.gitblit.Constants.RegistrantType;\r
-import com.gitblit.GitBlitException.NotAllowedException;\r
+import com.gitblit.GitBlitException.ForbiddenException;\r
 import com.gitblit.GitBlitException.UnauthorizedException;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.FederationModel;\r
@@ -104,7 +104,7 @@ public class RpcTests extends GitblitUnitTest {
                UserModel user = null;\r
                try {\r
                        user = RpcUtils.getUser("admin", url, null, null);\r
-               } catch (NotAllowedException e) {\r
+               } catch (ForbiddenException e) {\r
                }\r
                assertNull("Server allows anyone to get user!", user);\r
 \r