commit | author | age
|
ec97f7
|
1 |
/*
|
JM |
2 |
* Copyright 2011 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 |
*/
|
28d6b2
|
16 |
package com.gitblit.tests;
|
JM |
17 |
|
18c6ba
|
18 |
import java.io.File;
|
28d6b2
|
19 |
import java.util.List;
|
JM |
20 |
|
005a65
|
21 |
import org.eclipse.jgit.lib.Repository;
|
7e8873
|
22 |
import org.junit.Test;
|
28d6b2
|
23 |
|
f339f5
|
24 |
import com.gitblit.Constants.AccessRestrictionType;
|
JM |
25 |
import com.gitblit.FileSettings;
|
28d6b2
|
26 |
import com.gitblit.models.RepositoryModel;
|
JM |
27 |
import com.gitblit.models.UserModel;
|
18c6ba
|
28 |
import com.gitblit.utils.FileUtils;
|
28d6b2
|
29 |
|
db4f6b
|
30 |
public class GitBlitTest extends GitblitUnitTest {
|
28d6b2
|
31 |
|
7e8873
|
32 |
@Test
|
28d6b2
|
33 |
public void testRepositoryModel() throws Exception {
|
db4f6b
|
34 |
List<String> repositories = repositories().getRepositoryList();
|
28d6b2
|
35 |
assertTrue("Repository list is empty!", repositories.size() > 0);
|
db653a
|
36 |
assertTrue(
|
JM |
37 |
"Missing Helloworld repository!",
|
|
38 |
repositories.contains(GitBlitSuite.getHelloworldRepository().getDirectory()
|
|
39 |
.getName()));
|
005a65
|
40 |
Repository r = GitBlitSuite.getHelloworldRepository();
|
db4f6b
|
41 |
RepositoryModel model = repositories().getRepositoryModel(r.getDirectory().getName());
|
28d6b2
|
42 |
assertTrue("Helloworld model is null!", model != null);
|
ee0b1f
|
43 |
assertEquals(GitBlitSuite.getHelloworldRepository().getDirectory().getName(), model.name);
|
db4f6b
|
44 |
assertTrue(repositories().updateLastChangeFields(r, model) > 22000L);
|
005a65
|
45 |
r.close();
|
28d6b2
|
46 |
}
|
db653a
|
47 |
|
7e8873
|
48 |
@Test
|
28d6b2
|
49 |
public void testUserModel() throws Exception {
|
db4f6b
|
50 |
List<String> users = users().getAllUsernames();
|
28d6b2
|
51 |
assertTrue("No users found!", users.size() > 0);
|
JM |
52 |
assertTrue("Admin not found", users.contains("admin"));
|
db4f6b
|
53 |
UserModel user = users().getUserModel("admin");
|
20714a
|
54 |
assertEquals("admin", user.toString());
|
JM |
55 |
assertTrue("Admin missing #admin role!", user.canAdmin);
|
|
56 |
user.canAdmin = false;
|
|
57 |
assertFalse("Admin should not have #admin!", user.canAdmin);
|
28d6b2
|
58 |
String repository = GitBlitSuite.getHelloworldRepository().getDirectory().getName();
|
db4f6b
|
59 |
RepositoryModel repositoryModel = repositories().getRepositoryModel(repository);
|
20714a
|
60 |
repositoryModel.accessRestriction = AccessRestrictionType.VIEW;
|
7e8873
|
61 |
assertFalse("Admin can still access repository!",
|
20714a
|
62 |
user.canView(repositoryModel));
|
JM |
63 |
user.addRepositoryPermission(repository);
|
|
64 |
assertTrue("Admin can't access repository!", user.canView(repositoryModel));
|
db4f6b
|
65 |
assertEquals(repositories().getRepositoryModel(user, "pretend"), null);
|
JM |
66 |
assertNotNull(repositories().getRepositoryModel(user, repository));
|
|
67 |
assertTrue(repositories().getRepositoryModels(user).size() > 0);
|
28d6b2
|
68 |
}
|
c00577
|
69 |
|
15640f
|
70 |
@Test
|
JM |
71 |
public void testUserModelVerification() throws Exception {
|
|
72 |
UserModel user = new UserModel("james");
|
|
73 |
user.displayName = "James Moger";
|
c00577
|
74 |
|
f19b78
|
75 |
assertFalse(user.is("James", null));
|
JM |
76 |
assertFalse(user.is("James", ""));
|
|
77 |
assertFalse(user.is("JaMeS", "anything"));
|
c00577
|
78 |
|
f19b78
|
79 |
assertFalse(user.is("james moger", null));
|
JM |
80 |
assertFalse(user.is("james moger", ""));
|
|
81 |
assertFalse(user.is("james moger", "anything"));
|
c00577
|
82 |
|
15640f
|
83 |
assertFalse(user.is("joe", null));
|
JM |
84 |
assertFalse(user.is("joe", ""));
|
|
85 |
assertFalse(user.is("joe", "anything"));
|
|
86 |
|
|
87 |
// specify email address which results in address verification
|
|
88 |
user.emailAddress = "something";
|
|
89 |
|
|
90 |
assertFalse(user.is("James", null));
|
|
91 |
assertFalse(user.is("James", ""));
|
|
92 |
assertFalse(user.is("JaMeS", "anything"));
|
c00577
|
93 |
|
15640f
|
94 |
assertFalse(user.is("james moger", null));
|
JM |
95 |
assertFalse(user.is("james moger", ""));
|
|
96 |
assertFalse(user.is("james moger", "anything"));
|
|
97 |
|
|
98 |
assertTrue(user.is("JaMeS", user.emailAddress));
|
|
99 |
assertTrue(user.is("JaMeS mOgEr", user.emailAddress));
|
|
100 |
}
|
85c2e6
|
101 |
|
7e8873
|
102 |
@Test
|
f339f5
|
103 |
public void testAccessRestrictionTypes() throws Exception {
|
JM |
104 |
assertTrue(AccessRestrictionType.PUSH.exceeds(AccessRestrictionType.NONE));
|
|
105 |
assertTrue(AccessRestrictionType.CLONE.exceeds(AccessRestrictionType.PUSH));
|
|
106 |
assertTrue(AccessRestrictionType.VIEW.exceeds(AccessRestrictionType.CLONE));
|
|
107 |
|
|
108 |
assertFalse(AccessRestrictionType.NONE.exceeds(AccessRestrictionType.PUSH));
|
|
109 |
assertFalse(AccessRestrictionType.PUSH.exceeds(AccessRestrictionType.CLONE));
|
|
110 |
assertFalse(AccessRestrictionType.CLONE.exceeds(AccessRestrictionType.VIEW));
|
|
111 |
|
|
112 |
assertTrue(AccessRestrictionType.PUSH.atLeast(AccessRestrictionType.NONE));
|
|
113 |
assertTrue(AccessRestrictionType.CLONE.atLeast(AccessRestrictionType.PUSH));
|
|
114 |
assertTrue(AccessRestrictionType.VIEW.atLeast(AccessRestrictionType.CLONE));
|
|
115 |
|
|
116 |
assertFalse(AccessRestrictionType.NONE.atLeast(AccessRestrictionType.PUSH));
|
|
117 |
assertFalse(AccessRestrictionType.PUSH.atLeast(AccessRestrictionType.CLONE));
|
|
118 |
assertFalse(AccessRestrictionType.CLONE.atLeast(AccessRestrictionType.VIEW));
|
85c2e6
|
119 |
|
f339f5
|
120 |
assertTrue(AccessRestrictionType.PUSH.toString().equals("PUSH"));
|
JM |
121 |
assertTrue(AccessRestrictionType.CLONE.toString().equals("CLONE"));
|
|
122 |
assertTrue(AccessRestrictionType.VIEW.toString().equals("VIEW"));
|
|
123 |
|
7e8873
|
124 |
assertEquals(AccessRestrictionType.NONE, AccessRestrictionType.fromName("none"));
|
JM |
125 |
assertEquals(AccessRestrictionType.PUSH, AccessRestrictionType.fromName("push"));
|
|
126 |
assertEquals(AccessRestrictionType.CLONE, AccessRestrictionType.fromName("clone"));
|
|
127 |
assertEquals(AccessRestrictionType.VIEW, AccessRestrictionType.fromName("view"));
|
f339f5
|
128 |
}
|
85c2e6
|
129 |
|
7e8873
|
130 |
@Test
|
f339f5
|
131 |
public void testFileSettings() throws Exception {
|
06fa4b
|
132 |
FileSettings settings = new FileSettings("src/main/distrib/data/gitblit.properties");
|
7e8873
|
133 |
assertEquals(true, settings.getBoolean("missing", true));
|
JM |
134 |
assertEquals("default", settings.getString("missing", "default"));
|
|
135 |
assertEquals(10, settings.getInteger("missing", 10));
|
|
136 |
assertEquals(5, settings.getInteger("realm.realmFile", 5));
|
85c2e6
|
137 |
|
88598b
|
138 |
assertTrue(settings.getBoolean("git.enableGitServlet", false));
|
93d506
|
139 |
assertEquals("${baseFolder}/users.conf", settings.getString("realm.userService", null));
|
7e8873
|
140 |
assertEquals(5, settings.getInteger("realm.minPasswordLength", 0));
|
f339f5
|
141 |
List<String> mdExtensions = settings.getStrings("web.markdownExtensions");
|
JM |
142 |
assertTrue(mdExtensions.size() > 0);
|
|
143 |
assertTrue(mdExtensions.contains("md"));
|
85c2e6
|
144 |
|
f339f5
|
145 |
List<String> keys = settings.getAllKeys("server");
|
JM |
146 |
assertTrue(keys.size() > 0);
|
|
147 |
assertTrue(keys.contains("server.httpsPort"));
|
88598b
|
148 |
|
JM |
149 |
assertTrue(settings.getChar("web.forwardSlashCharacter", ' ') == '/');
|
f339f5
|
150 |
}
|
85c2e6
|
151 |
|
7e8873
|
152 |
@Test
|
f339f5
|
153 |
public void testGitblitSettings() throws Exception {
|
JM |
154 |
// These are already tested by above test method.
|
db4f6b
|
155 |
assertTrue(settings().getBoolean("missing", true));
|
JM |
156 |
assertEquals("default", settings().getString("missing", "default"));
|
|
157 |
assertEquals(10, settings().getInteger("missing", 10));
|
|
158 |
assertEquals(5, settings().getInteger("realm.userService", 5));
|
85c2e6
|
159 |
|
db4f6b
|
160 |
assertTrue(settings().getBoolean("git.enableGitServlet", false));
|
18c6ba
|
161 |
File userDir = new File(System.getProperty("user.dir"));
|
JM |
162 |
File userService = new File(settings().getString("realm.userService", null));
|
|
163 |
assertEquals("src/test/config/test-users.conf", FileUtils.getRelativePath(userDir, userService));
|
db4f6b
|
164 |
assertEquals(5, settings().getInteger("realm.minPasswordLength", 0));
|
JM |
165 |
List<String> mdExtensions = settings().getStrings("web.markdownExtensions");
|
f339f5
|
166 |
assertTrue(mdExtensions.size() > 0);
|
JM |
167 |
assertTrue(mdExtensions.contains("md"));
|
85c2e6
|
168 |
|
db4f6b
|
169 |
List<String> keys = settings().getAllKeys("server");
|
f339f5
|
170 |
assertTrue(keys.size() > 0);
|
JM |
171 |
assertTrue(keys.contains("server.httpsPort"));
|
88598b
|
172 |
|
db4f6b
|
173 |
assertTrue(settings().getChar("web.forwardSlashCharacter", ' ') == '/');
|
JM |
174 |
assertFalse(runtime().isDebugMode());
|
f339f5
|
175 |
}
|
85c2e6
|
176 |
|
7e8873
|
177 |
@Test
|
85c2e6
|
178 |
public void testAuthentication() throws Exception {
|
0d7c65
|
179 |
assertTrue(authentication().authenticate("admin", "admin".toCharArray(), null) != null);
|
f339f5
|
180 |
}
|
85c2e6
|
181 |
|
7e8873
|
182 |
@Test
|
85c2e6
|
183 |
public void testRepositories() throws Exception {
|
db4f6b
|
184 |
assertTrue(repositories().getRepository("missing") == null);
|
JM |
185 |
assertTrue(repositories().getRepositoryModel("missing") == null);
|
f339f5
|
186 |
}
|
28d6b2
|
187 |
}
|