]> source.dussan.org Git - gitblit.git/commitdiff
Added unit test for reported issue (issue-271)
authorJames Moger <james.moger@gitblit.com>
Wed, 17 Jul 2013 13:45:35 +0000 (09:45 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 17 Jul 2013 13:45:35 +0000 (09:45 -0400)
src/test/java/com/gitblit/tests/GitBlitSuite.java
src/test/java/com/gitblit/tests/Issue0271Test.java [new file with mode: 0644]
src/test/resources/issue0271.conf [new file with mode: 0644]

index a226329837c8cc0d43e578a23d4b7099674961fa..6fff241c3f022a41be368ff7bce7b311d8915d7a 100644 (file)
@@ -60,7 +60,7 @@ import com.gitblit.utils.JGitUtils;
                DiffUtilsTest.class, MetricUtilsTest.class, TicgitUtilsTest.class, X509UtilsTest.class,\r
                GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class, GitDaemonTest.class,\r
                GroovyScriptTest.class, LuceneExecutorTest.class, IssuesTest.class, RepositoryModelTest.class,\r
-               FanoutServiceTest.class, Issue0259Test.class })\r
+               FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class })\r
 public class GitBlitSuite {\r
 \r
        public static final File REPOSITORIES = new File("data/git");\r
diff --git a/src/test/java/com/gitblit/tests/Issue0271Test.java b/src/test/java/com/gitblit/tests/Issue0271Test.java
new file mode 100644 (file)
index 0000000..437c5b9
--- /dev/null
@@ -0,0 +1,76 @@
+/*\r
+ * Copyright 2013 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import java.io.File;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+import com.gitblit.ConfigUserService;\r
+import com.gitblit.Constants.AccessPermission;\r
+import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.UserModel;\r
+\r
+/**\r
+ * https://code.google.com/p/gitblit/issues/detail?id=271\r
+ * \r
+ * Reported Problem:\r
+ * Inherited team permissions are incorrect.\r
+ * \r
+ * @see src/test/resources/issue0270.conf\r
+ * \r
+ * @author James Moger\r
+ *\r
+ */\r
+public class Issue0271Test extends Assert {\r
+\r
+       RepositoryModel repo(String name, AccessRestrictionType restriction) {\r
+               RepositoryModel repo = new RepositoryModel();\r
+               repo.name = name;\r
+               repo.accessRestriction = restriction;\r
+               return repo;\r
+       }\r
+       \r
+       /**\r
+        * Test the provided users.conf file for expected access permissions.\r
+        *  \r
+        * @throws Exception\r
+        */\r
+       @Test\r
+       public void testFile() throws Exception {\r
+               File realmFile = new File("src/test/resources/issue0271.conf");\r
+               ConfigUserService service = new ConfigUserService(realmFile);\r
+               \r
+               RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);\r
+               RepositoryModel teama_test = repo("teama/test.git", AccessRestrictionType.VIEW);\r
+               \r
+               UserModel a = service.getUserModel("a");\r
+               UserModel b = service.getUserModel("b");\r
+               UserModel c = service.getUserModel("c");\r
+               \r
+               // assert V for test.git\r
+               assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(test).permission);\r
+               assertEquals(AccessPermission.VIEW, b.getRepositoryPermission(test).permission);\r
+               assertEquals(AccessPermission.VIEW, c.getRepositoryPermission(test).permission);\r
+               \r
+               // assert expected permissions for teama/test.git\r
+               assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(teama_test).permission);\r
+               assertEquals(AccessPermission.PUSH, b.getRepositoryPermission(teama_test).permission);\r
+               assertEquals(AccessPermission.CREATE, c.getRepositoryPermission(teama_test).permission);\r
+       }\r
+}
\ No newline at end of file
diff --git a/src/test/resources/issue0271.conf b/src/test/resources/issue0271.conf
new file mode 100644 (file)
index 0000000..c77ca92
--- /dev/null
@@ -0,0 +1,20 @@
+[user "A"]
+       password = apassword
+       role = "#none"
+[user "B"]
+       password = apassword
+       role = "#none"
+[user "C"]
+       password = apassword
+       role = "#none"
+       repository = RWC:teama/.*
+[team "developers"]
+       role = "#none"
+       repository = V:.*
+       user = A
+       user = B
+       user = C
+[team "teama"]
+       repository = RW:teama/.*
+       user = B
+       user = C