You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Issue0271Test.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2013 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.tests;
  17. import java.io.File;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import com.gitblit.ConfigUserService;
  21. import com.gitblit.Constants.AccessPermission;
  22. import com.gitblit.Constants.AccessRestrictionType;
  23. import com.gitblit.models.RepositoryModel;
  24. import com.gitblit.models.UserModel;
  25. /**
  26. * https://code.google.com/p/gitblit/issues/detail?id=271
  27. *
  28. * Reported Problem:
  29. * Inherited team permissions are incorrect.
  30. *
  31. * @see src/test/resources/issue0270.conf
  32. *
  33. * @author James Moger
  34. *
  35. */
  36. public class Issue0271Test extends Assert {
  37. RepositoryModel repo(String name, AccessRestrictionType restriction) {
  38. RepositoryModel repo = new RepositoryModel();
  39. repo.name = name;
  40. repo.accessRestriction = restriction;
  41. return repo;
  42. }
  43. /**
  44. * Test the provided users.conf file for expected access permissions.
  45. *
  46. * @throws Exception
  47. */
  48. @Test
  49. public void testFile() throws Exception {
  50. File realmFile = new File("src/test/resources/issue0271.conf");
  51. ConfigUserService service = new ConfigUserService(realmFile);
  52. RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
  53. RepositoryModel teama_test = repo("teama/test.git", AccessRestrictionType.VIEW);
  54. UserModel a = service.getUserModel("a");
  55. UserModel b = service.getUserModel("b");
  56. UserModel c = service.getUserModel("c");
  57. // assert V for test.git
  58. assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(test).permission);
  59. assertEquals(AccessPermission.VIEW, b.getRepositoryPermission(test).permission);
  60. assertEquals(AccessPermission.VIEW, c.getRepositoryPermission(test).permission);
  61. // assert expected permissions for teama/test.git
  62. assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(teama_test).permission);
  63. assertEquals(AccessPermission.PUSH, b.getRepositoryPermission(teama_test).permission);
  64. assertEquals(AccessPermission.CREATE, c.getRepositoryPermission(teama_test).permission);
  65. }
  66. }