summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/gitblit/tests/Issue0271Test.java
blob: 437c5b9e34cef930844e37c31b424804c03ceee0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright 2013 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 org.junit.Assert;
import org.junit.Test;

import com.gitblit.ConfigUserService;
import com.gitblit.Constants.AccessPermission;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;

/**
 * https://code.google.com/p/gitblit/issues/detail?id=271
 * 
 * Reported Problem:
 * Inherited team permissions are incorrect.
 * 
 * @see src/test/resources/issue0270.conf
 * 
 * @author James Moger
 *
 */
public class Issue0271Test extends Assert {

	RepositoryModel repo(String name, AccessRestrictionType restriction) {
		RepositoryModel repo = new RepositoryModel();
		repo.name = name;
		repo.accessRestriction = restriction;
		return repo;
	}
	
	/**
	 * Test the provided users.conf file for expected access permissions.
	 *  
	 * @throws Exception
	 */
	@Test
	public void testFile() throws Exception {
		File realmFile = new File("src/test/resources/issue0271.conf");
		ConfigUserService service = new ConfigUserService(realmFile);
		
		RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
		RepositoryModel teama_test = repo("teama/test.git", AccessRestrictionType.VIEW);
		
		UserModel a = service.getUserModel("a");
		UserModel b = service.getUserModel("b");
		UserModel c = service.getUserModel("c");
		
		// assert V for test.git
		assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(test).permission);
		assertEquals(AccessPermission.VIEW, b.getRepositoryPermission(test).permission);
		assertEquals(AccessPermission.VIEW, c.getRepositoryPermission(test).permission);
		
		// assert expected permissions for teama/test.git
		assertEquals(AccessPermission.VIEW, a.getRepositoryPermission(teama_test).permission);
		assertEquals(AccessPermission.PUSH, b.getRepositoryPermission(teama_test).permission);
		assertEquals(AccessPermission.CREATE, c.getRepositoryPermission(teama_test).permission);
	}
}