Change-Id: I172bd4d493eee1013ec542ab97f1be29040f816dtags/v1.4.0
@@ -27,7 +27,7 @@ import com.gitblit.utils.ActivityUtils; | |||
public class ActivityTest { | |||
@Test | |||
public void testGravatarProfile() throws IOException { | |||
public void testGravatarProfile() throws IOException { | |||
GravatarProfile profile = ActivityUtils.getGravatarProfile("beau@dentedreality.com.au"); | |||
assertEquals("beau", profile.preferredUsername); | |||
} |
@@ -37,10 +37,10 @@ public class ArrayUtilsTest { | |||
Object [] emptyArray = new Object[0]; | |||
assertTrue(ArrayUtils.isEmpty(emptyArray)); | |||
assertFalse(ArrayUtils.isEmpty(new String [] { "" })); | |||
} | |||
@Test | |||
public void testLists() { | |||
List<?> nullList = null; | |||
@@ -48,11 +48,11 @@ public class ArrayUtilsTest { | |||
List<?> emptyList = new ArrayList<Object>(); | |||
assertTrue(ArrayUtils.isEmpty(emptyList)); | |||
List<?> list = Arrays.asList(""); | |||
assertFalse(ArrayUtils.isEmpty(list)); | |||
} | |||
@Test | |||
public void testSets() { | |||
Set<?> nullSet = null; | |||
@@ -60,7 +60,7 @@ public class ArrayUtilsTest { | |||
Set<?> emptySet = new HashSet<Object>(); | |||
assertTrue(ArrayUtils.isEmpty(emptySet)); | |||
Set<?> set = new HashSet<Object>(Arrays.asList("")); | |||
assertFalse(ArrayUtils.isEmpty(set)); | |||
} |
@@ -32,9 +32,9 @@ import com.gitblit.fanout.FanoutService; | |||
import com.gitblit.fanout.FanoutSocketService; | |||
public class FanoutServiceTest { | |||
int fanoutPort = FanoutService.DEFAULT_PORT; | |||
@Test | |||
public void testNioPubSub() throws Exception { | |||
testPubSub(new FanoutNioService(fanoutPort)); | |||
@@ -44,7 +44,7 @@ public class FanoutServiceTest { | |||
public void testSocketPubSub() throws Exception { | |||
testPubSub(new FanoutSocketService(fanoutPort)); | |||
} | |||
@Test | |||
public void testNioDisruptionAndRecovery() throws Exception { | |||
testDisruption(new FanoutNioService(fanoutPort)); | |||
@@ -54,21 +54,21 @@ public class FanoutServiceTest { | |||
public void testSocketDisruptionAndRecovery() throws Exception { | |||
testDisruption(new FanoutSocketService(fanoutPort)); | |||
} | |||
protected void testPubSub(FanoutService service) throws Exception { | |||
System.out.println(MessageFormat.format("\n\n========================================\nPUBSUB TEST {0}\n========================================\n\n", service.toString())); | |||
service.startSynchronously(); | |||
final Map<String, String> announcementsA = new ConcurrentHashMap<String, String>(); | |||
FanoutClient clientA = new FanoutClient("localhost", fanoutPort); | |||
clientA.addListener(new FanoutAdapter() { | |||
@Override | |||
public void announcement(String channel, String message) { | |||
announcementsA.put(channel, message); | |||
} | |||
}); | |||
clientA.startSynchronously(); | |||
final Map<String, String> announcementsB = new ConcurrentHashMap<String, String>(); | |||
@@ -81,23 +81,23 @@ public class FanoutServiceTest { | |||
}); | |||
clientB.startSynchronously(); | |||
// subscribe clients A and B to the channels | |||
clientA.subscribe("a"); | |||
clientA.subscribe("b"); | |||
clientA.subscribe("c"); | |||
clientB.subscribe("a"); | |||
clientB.subscribe("b"); | |||
clientB.subscribe("c"); | |||
// give async messages a chance to be delivered | |||
Thread.sleep(1000); | |||
clientA.announce("a", "apple"); | |||
clientA.announce("b", "banana"); | |||
clientA.announce("c", "cantelope"); | |||
clientB.announce("a", "avocado"); | |||
clientB.announce("b", "beet"); | |||
clientB.announce("c", "carrot"); | |||
@@ -114,16 +114,16 @@ public class FanoutServiceTest { | |||
assertEquals("avocado", announcementsA.get("a")); | |||
assertEquals("beet", announcementsA.get("b")); | |||
assertEquals("carrot", announcementsA.get("c")); | |||
clientA.stop(); | |||
clientB.stop(); | |||
service.stop(); | |||
service.stop(); | |||
} | |||
protected void testDisruption(FanoutService service) throws Exception { | |||
System.out.println(MessageFormat.format("\n\n========================================\nDISRUPTION TEST {0}\n========================================\n\n", service.toString())); | |||
service.startSynchronously(); | |||
final AtomicInteger pongCount = new AtomicInteger(0); | |||
FanoutClient client = new FanoutClient("localhost", fanoutPort); | |||
client.addListener(new FanoutAdapter() { | |||
@@ -133,27 +133,27 @@ public class FanoutServiceTest { | |||
} | |||
}); | |||
client.startSynchronously(); | |||
// ping and wait for pong | |||
client.ping(); | |||
client.ping(); | |||
Thread.sleep(500); | |||
// restart client | |||
client.stop(); | |||
Thread.sleep(1000); | |||
client.startSynchronously(); | |||
client.startSynchronously(); | |||
// ping and wait for pong | |||
client.ping(); | |||
client.ping(); | |||
Thread.sleep(500); | |||
assertEquals(2, pongCount.get()); | |||
// now disrupt service | |||
service.stop(); | |||
service.stop(); | |||
Thread.sleep(2000); | |||
service.startSynchronously(); | |||
// wait for reconnect | |||
Thread.sleep(2000); | |||
@@ -164,7 +164,7 @@ public class FanoutServiceTest { | |||
// kill all | |||
client.stop(); | |||
service.stop(); | |||
// confirm expected pong count | |||
assertEquals(3, pongCount.get()); | |||
} |
@@ -129,23 +129,23 @@ public class FederationTests { | |||
assertNotNull(users); | |||
// admin is excluded | |||
assertEquals(0, users.size()); | |||
UserModel newUser = new UserModel("test"); | |||
newUser.password = "whocares"; | |||
assertTrue(RpcUtils.createUser(newUser, url, account, password.toCharArray())); | |||
TeamModel team = new TeamModel("testteam"); | |||
team.addUser("test"); | |||
team.addRepositoryPermission("helloworld.git"); | |||
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray())); | |||
users = FederationUtils.getUsers(getRegistration()); | |||
assertNotNull(users); | |||
assertEquals(1, users.size()); | |||
newUser = users.get(0); | |||
assertTrue(newUser.isTeamMember("testteam")); | |||
assertTrue(newUser.isTeamMember("testteam")); | |||
assertTrue(RpcUtils.deleteUser(newUser, url, account, password.toCharArray())); | |||
assertTrue(RpcUtils.deleteTeam(team, url, account, password.toCharArray())); | |||
} | |||
@@ -156,14 +156,14 @@ public class FederationTests { | |||
team.addUser("test"); | |||
team.addRepositoryPermission("helloworld.git"); | |||
assertTrue(RpcUtils.createTeam(team, url, account, password.toCharArray())); | |||
List<TeamModel> teams = FederationUtils.getTeams(getRegistration()); | |||
assertNotNull(teams); | |||
assertTrue(teams.size() > 0); | |||
assertTrue(RpcUtils.deleteTeam(team, url, account, password.toCharArray())); | |||
} | |||
@Test | |||
public void testPullScripts() throws Exception { | |||
Map<String, String> scripts = FederationUtils.getScripts(getRegistration()); |
@@ -55,7 +55,7 @@ public class FileUtilsTest { | |||
size = FileUtils.folderSize(file); | |||
assertEquals("size is actually " + size, 11556L, size); | |||
} | |||
@Test | |||
public void testStringSizes() throws Exception { | |||
assertEquals(50 * FileUtils.KB, FileUtils.convertSizeToInt("50k", 0)); | |||
@@ -73,7 +73,7 @@ public class FileUtilsTest { | |||
assertEquals(50L * FileUtils.KB, FileUtils.convertSizeToLong("50kb", 0)); | |||
assertEquals(50L * FileUtils.MB, FileUtils.convertSizeToLong("50mb", 0)); | |||
assertEquals(50L * FileUtils.GB, FileUtils.convertSizeToLong("50gb", 0)); | |||
assertEquals(50 * FileUtils.KB, FileUtils.convertSizeToInt("50 k", 0)); | |||
assertEquals(50 * FileUtils.MB, FileUtils.convertSizeToInt("50 m", 0)); | |||
assertEquals(2 * FileUtils.GB, FileUtils.convertSizeToInt("2 g", 0)); |
@@ -70,20 +70,20 @@ public class GitBlitTest { | |||
assertNotNull(GitBlit.self().getRepositoryModel(user, repository)); | |||
assertTrue(GitBlit.self().getRepositoryModels(user).size() > 0); | |||
} | |||
@Test | |||
public void testUserModelVerification() throws Exception { | |||
UserModel user = new UserModel("james"); | |||
user.displayName = "James Moger"; | |||
assertTrue(user.is("James", null)); | |||
assertTrue(user.is("James", "")); | |||
assertTrue(user.is("JaMeS", "anything")); | |||
assertTrue(user.is("james moger", null)); | |||
assertTrue(user.is("james moger", "")); | |||
assertTrue(user.is("james moger", "anything")); | |||
assertFalse(user.is("joe", null)); | |||
assertFalse(user.is("joe", "")); | |||
assertFalse(user.is("joe", "anything")); | |||
@@ -94,7 +94,7 @@ public class GitBlitTest { | |||
assertFalse(user.is("James", null)); | |||
assertFalse(user.is("James", "")); | |||
assertFalse(user.is("JaMeS", "anything")); | |||
assertFalse(user.is("james moger", null)); | |||
assertFalse(user.is("james moger", "")); | |||
assertFalse(user.is("james moger", "anything")); |
@@ -43,11 +43,11 @@ import com.gitblit.models.RepositoryModel; | |||
public class GitDaemonTest extends Assert { | |||
static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit"); | |||
static File ticgit2Folder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit2"); | |||
static File jgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/jgit"); | |||
static File jgit2Folder = new File(GitBlitSuite.REPOSITORIES, "working/jgit2"); | |||
String url = GitBlitSuite.gitDaemonUrl; | |||
@@ -98,21 +98,21 @@ public class GitDaemonTest extends Assert { | |||
model.accessRestriction = AccessRestrictionType.PUSH; | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
CloneCommand clone = Git.cloneRepository(); | |||
clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); | |||
clone.setDirectory(ticgitFolder); | |||
clone.setBare(false); | |||
clone.setCloneAllBranches(true); | |||
GitBlitSuite.close(clone.call()); | |||
GitBlitSuite.close(clone.call()); | |||
assertTrue(true); | |||
// restore anonymous repository access | |||
model.accessRestriction = AccessRestrictionType.NONE; | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
} | |||
@Test | |||
public void testCloneRestrictedRepo() throws Exception { | |||
GitBlitSuite.close(ticgit2Folder); | |||
@@ -125,8 +125,8 @@ public class GitDaemonTest extends Assert { | |||
model.accessRestriction = AccessRestrictionType.CLONE; | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
// delete any existing working folder | |||
// delete any existing working folder | |||
boolean cloned = false; | |||
try { | |||
CloneCommand clone = Git.cloneRepository(); | |||
@@ -143,7 +143,7 @@ public class GitDaemonTest extends Assert { | |||
assertFalse("Anonymous was able to clone the repository?!", cloned); | |||
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE); | |||
// restore anonymous repository access | |||
model.accessRestriction = AccessRestrictionType.NONE; | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
@@ -168,9 +168,9 @@ public class GitDaemonTest extends Assert { | |||
clone.setDirectory(ticgitFolder); | |||
clone.setBare(false); | |||
clone.setCloneAllBranches(true); | |||
GitBlitSuite.close(clone.call()); | |||
GitBlitSuite.close(clone.call()); | |||
assertTrue(true); | |||
Git git = Git.open(ticgitFolder); | |||
File file = new File(ticgitFolder, "TODO"); | |||
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET); | |||
@@ -206,9 +206,9 @@ public class GitDaemonTest extends Assert { | |||
clone.setDirectory(ticgitFolder); | |||
clone.setBare(false); | |||
clone.setCloneAllBranches(true); | |||
GitBlitSuite.close(clone.call()); | |||
GitBlitSuite.close(clone.call()); | |||
assertTrue(true); | |||
Git git = Git.open(ticgitFolder); | |||
File file = new File(ticgitFolder, "TODO"); | |||
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET); | |||
@@ -232,7 +232,7 @@ public class GitDaemonTest extends Assert { | |||
if (jgitFolder.exists()) { | |||
FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY); | |||
} | |||
CloneCommand clone = Git.cloneRepository(); | |||
clone.setURI(MessageFormat.format("{0}/test/jgit.git", url)); | |||
clone.setDirectory(jgitFolder); | |||
@@ -240,7 +240,7 @@ public class GitDaemonTest extends Assert { | |||
clone.setCloneAllBranches(true); | |||
GitBlitSuite.close(clone.call()); | |||
assertTrue(true); | |||
// freeze repo | |||
RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git"); | |||
model.isFrozen = true; | |||
@@ -254,14 +254,14 @@ public class GitDaemonTest extends Assert { | |||
w.close(); | |||
git.add().addFilepattern(file.getName()).call(); | |||
git.commit().setMessage("test commit").call(); | |||
Iterable<PushResult> results = git.push().call(); | |||
for (PushResult result : results) { | |||
for (RemoteRefUpdate update : result.getRemoteUpdates()) { | |||
assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus()); | |||
} | |||
} | |||
// unfreeze repo | |||
model.isFrozen = false; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
@@ -274,14 +274,14 @@ public class GitDaemonTest extends Assert { | |||
} | |||
} | |||
} | |||
@Test | |||
public void testPushToNonBareRepository() throws Exception { | |||
GitBlitSuite.close(jgit2Folder); | |||
if (jgit2Folder.exists()) { | |||
FileUtils.delete(jgit2Folder, FileUtils.RECURSIVE | FileUtils.RETRY); | |||
} | |||
CloneCommand clone = Git.cloneRepository(); | |||
clone.setURI(MessageFormat.format("{0}/working/jgit", url)); | |||
clone.setDirectory(jgit2Folder); | |||
@@ -301,7 +301,7 @@ public class GitDaemonTest extends Assert { | |||
Iterable<PushResult> results = git.push().setPushAll().call(); | |||
GitBlitSuite.close(git); | |||
for (PushResult result : results) { | |||
for (RemoteRefUpdate update : result.getRemoteUpdates()) { | |||
assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus()); |
@@ -1,3 +1,18 @@ | |||
/* | |||
* Copyright 2011 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 static org.junit.Assert.assertEquals; | |||
@@ -50,11 +65,11 @@ import com.gitblit.utils.RefLogUtils; | |||
public class GitServletTest { | |||
static File ticgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit"); | |||
static File ticgit2Folder = new File(GitBlitSuite.REPOSITORIES, "working/ticgit2"); | |||
static File jgitFolder = new File(GitBlitSuite.REPOSITORIES, "working/jgit"); | |||
static File jgit2Folder = new File(GitBlitSuite.REPOSITORIES, "working/jgit2"); | |||
String url = GitBlitSuite.gitServletUrl; | |||
@@ -62,7 +77,7 @@ public class GitServletTest { | |||
String password = GitBlitSuite.password; | |||
private static final AtomicBoolean started = new AtomicBoolean(false); | |||
private static UserModel getUser() { | |||
UserModel user = new UserModel("james"); | |||
user.displayName = "James Moger"; | |||
@@ -70,7 +85,7 @@ public class GitServletTest { | |||
user.password = "james"; | |||
return user; | |||
} | |||
private static void delete(UserModel user) { | |||
if (GitBlit.self().getUserModel(user.username) != null) { | |||
GitBlit.self().deleteUser(user.username); | |||
@@ -90,10 +105,10 @@ public class GitServletTest { | |||
GitBlitSuite.stopGitblit(); | |||
deleteWorkingFolders(); | |||
} | |||
delete(getUser()); | |||
} | |||
public static void deleteWorkingFolders() throws Exception { | |||
if (ticgitFolder.exists()) { | |||
GitBlitSuite.close(ticgitFolder); | |||
@@ -119,14 +134,14 @@ public class GitServletTest { | |||
if (ticgitFolder.exists()) { | |||
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY); | |||
} | |||
CloneCommand clone = Git.cloneRepository(); | |||
clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); | |||
clone.setDirectory(ticgitFolder); | |||
clone.setBare(false); | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)); | |||
GitBlitSuite.close(clone.call()); | |||
GitBlitSuite.close(clone.call()); | |||
assertTrue(true); | |||
} | |||
@@ -137,7 +152,7 @@ public class GitServletTest { | |||
model.accessRestriction = AccessRestrictionType.CLONE; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
// delete any existing working folder | |||
// delete any existing working folder | |||
boolean cloned = false; | |||
try { | |||
CloneCommand clone = Git.cloneRepository(); | |||
@@ -158,7 +173,7 @@ public class GitServletTest { | |||
assertFalse("Bogus login cloned a repository?!", cloned); | |||
} | |||
@Test | |||
public void testUnauthorizedLoginClone() throws Exception { | |||
// restrict repository access | |||
@@ -171,8 +186,8 @@ public class GitServletTest { | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE); | |||
// delete any existing working folder | |||
// delete any existing working folder | |||
boolean cloned = false; | |||
try { | |||
CloneCommand clone = Git.cloneRepository(); | |||
@@ -190,11 +205,11 @@ public class GitServletTest { | |||
assertFalse("Unauthorized login cloned a repository?!", cloned); | |||
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE); | |||
// switch to authenticated | |||
model.authorizationControl = AuthorizationControl.AUTHENTICATED; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
// try clone again | |||
cloned = false; | |||
CloneCommand clone = Git.cloneRepository(); | |||
@@ -207,15 +222,15 @@ public class GitServletTest { | |||
cloned = true; | |||
assertTrue("Authenticated login could not clone!", cloned); | |||
FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE); | |||
// restore anonymous repository access | |||
model.accessRestriction = AccessRestrictionType.NONE; | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
delete(user); | |||
delete(user); | |||
} | |||
@Test | |||
@@ -235,9 +250,9 @@ public class GitServletTest { | |||
clone.setBare(false); | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)); | |||
GitBlitSuite.close(clone.call()); | |||
GitBlitSuite.close(clone.call()); | |||
assertTrue(true); | |||
Git git = Git.open(ticgitFolder); | |||
File file = new File(ticgitFolder, "TODO"); | |||
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET); | |||
@@ -261,7 +276,7 @@ public class GitServletTest { | |||
if (jgitFolder.exists()) { | |||
FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY); | |||
} | |||
CloneCommand clone = Git.cloneRepository(); | |||
clone.setURI(MessageFormat.format("{0}/test/jgit.git", url)); | |||
clone.setDirectory(jgitFolder); | |||
@@ -287,14 +302,14 @@ public class GitServletTest { | |||
} | |||
} | |||
} | |||
@Test | |||
public void testPushToFrozenRepo() throws Exception { | |||
GitBlitSuite.close(jgitFolder); | |||
if (jgitFolder.exists()) { | |||
FileUtils.delete(jgitFolder, FileUtils.RECURSIVE | FileUtils.RETRY); | |||
} | |||
CloneCommand clone = Git.cloneRepository(); | |||
clone.setURI(MessageFormat.format("{0}/test/jgit.git", url)); | |||
clone.setDirectory(jgitFolder); | |||
@@ -303,7 +318,7 @@ public class GitServletTest { | |||
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)); | |||
GitBlitSuite.close(clone.call()); | |||
assertTrue(true); | |||
// freeze repo | |||
RepositoryModel model = GitBlit.self().getRepositoryModel("test/jgit.git"); | |||
model.isFrozen = true; | |||
@@ -317,14 +332,14 @@ public class GitServletTest { | |||
w.close(); | |||
git.add().addFilepattern(file.getName()).call(); | |||
git.commit().setMessage("test commit").call(); | |||
Iterable<PushResult> results = git.push().setPushAll().setCredentialsProvider(new UsernamePasswordCredentialsProvider(account, password)).call(); | |||
for (PushResult result : results) { | |||
for (RemoteRefUpdate update : result.getRemoteUpdates()) { | |||
assertEquals(Status.REJECTED_OTHER_REASON, update.getStatus()); | |||
} | |||
} | |||
// unfreeze repo | |||
model.isFrozen = false; | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
@@ -337,7 +352,7 @@ public class GitServletTest { | |||
} | |||
} | |||
} | |||
@Test | |||
public void testPushToNonBareRepository() throws Exception { | |||
CloneCommand clone = Git.cloneRepository(); | |||
@@ -382,23 +397,23 @@ public class GitServletTest { | |||
testCommitterVerification(user, user.displayName, null, true); | |||
testCommitterVerification(user, user.displayName, "something", true); | |||
testCommitterVerification(user, "joe", null, false); | |||
// test email address verification | |||
user.emailAddress = "something"; | |||
testCommitterVerification(user, user.displayName, null, false); | |||
testCommitterVerification(user, user.displayName, "somethingelse", false); | |||
testCommitterVerification(user, user.displayName, user.emailAddress, true); | |||
// use same email address but with different committer | |||
testCommitterVerification(user, "joe", "somethingelse", false); | |||
} | |||
private void testCommitterVerification(UserModel user, String displayName, String emailAddress, boolean expectedSuccess) throws Exception { | |||
delete(user); | |||
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password); | |||
// fork from original to a temporary bare repo | |||
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git"); | |||
if (verification.exists()) { | |||
@@ -411,16 +426,16 @@ public class GitServletTest { | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(cp); | |||
GitBlitSuite.close(clone.call()); | |||
// require push permissions and committer verification | |||
RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git"); | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
model.accessRestriction = AccessRestrictionType.PUSH; | |||
model.verifyCommitter = true; | |||
// grant user push permission | |||
user.setRepositoryPermission(model.name, AccessPermission.PUSH); | |||
GitBlit.self().updateUserModel(user.username, user, true); | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
@@ -436,14 +451,14 @@ public class GitServletTest { | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(cp); | |||
GitBlitSuite.close(clone.call()); | |||
Git git = Git.open(local); | |||
// force an identity which may or may not match the account's identity | |||
git.getRepository().getConfig().setString("user", null, "name", displayName); | |||
git.getRepository().getConfig().setString("user", null, "email", emailAddress); | |||
git.getRepository().getConfig().save(); | |||
// commit a file and push it | |||
File file = new File(local, "PUSHCHK"); | |||
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET); | |||
@@ -453,7 +468,7 @@ public class GitServletTest { | |||
git.add().addFilepattern(file.getName()).call(); | |||
git.commit().setMessage("push test").call(); | |||
Iterable<PushResult> results = git.push().setCredentialsProvider(cp).setRemote("origin").call(); | |||
for (PushResult result : results) { | |||
RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master"); | |||
Status status = ref.getStatus(); | |||
@@ -463,27 +478,27 @@ public class GitServletTest { | |||
assertTrue("Verification failed! User was able to push commit! " + status.name(), Status.REJECTED_OTHER_REASON.equals(status)); | |||
} | |||
} | |||
GitBlitSuite.close(git); | |||
// close serving repository | |||
GitBlitSuite.close(verification); | |||
} | |||
@Test | |||
public void testMergeCommitterVerification() throws Exception { | |||
testMergeCommitterVerification(false); | |||
testMergeCommitterVerification(true); | |||
} | |||
private void testMergeCommitterVerification(boolean expectedSuccess) throws Exception { | |||
UserModel user = getUser(); | |||
delete(user); | |||
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password); | |||
// fork from original to a temporary bare repo | |||
File verification = new File(GitBlitSuite.REPOSITORIES, "refchecks/verify-committer.git"); | |||
if (verification.exists()) { | |||
@@ -496,16 +511,16 @@ public class GitServletTest { | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(cp); | |||
GitBlitSuite.close(clone.call()); | |||
// require push permissions and committer verification | |||
RepositoryModel model = GitBlit.self().getRepositoryModel("refchecks/verify-committer.git"); | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
model.accessRestriction = AccessRestrictionType.PUSH; | |||
model.verifyCommitter = true; | |||
// grant user push permission | |||
user.setRepositoryPermission(model.name, AccessPermission.PUSH); | |||
GitBlit.self().updateUserModel(user.username, user, true); | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
@@ -521,17 +536,17 @@ public class GitServletTest { | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(cp); | |||
GitBlitSuite.close(clone.call()); | |||
Git git = Git.open(local); | |||
// checkout a mergetest branch | |||
git.checkout().setCreateBranch(true).setName("mergetest").call(); | |||
// change identity | |||
git.getRepository().getConfig().setString("user", null, "name", "mergetest"); | |||
git.getRepository().getConfig().setString("user", null, "email", "mergetest@merge.com"); | |||
git.getRepository().getConfig().save(); | |||
// commit a file | |||
File file = new File(local, "MERGECHK2"); | |||
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET); | |||
@@ -540,7 +555,7 @@ public class GitServletTest { | |||
w.close(); | |||
git.add().addFilepattern(file.getName()).call(); | |||
RevCommit mergeTip = git.commit().setMessage(file.getName() + " test").call(); | |||
// return to master | |||
git.checkout().setName("master").call(); | |||
@@ -559,14 +574,14 @@ public class GitServletTest { | |||
w.close(); | |||
git.add().addFilepattern(file.getName()).call(); | |||
git.commit().setMessage(file.getName() + " test").call(); | |||
// merge the tip of the mergetest branch into master with --no-ff | |||
MergeResult mergeResult = git.merge().setFastForward(FastForwardMode.NO_FF).include(mergeTip.getId()).call(); | |||
assertEquals(MergeResult.MergeStatus.MERGED, mergeResult.getMergeStatus()); | |||
// push the merged master to the origin | |||
Iterable<PushResult> results = git.push().setCredentialsProvider(cp).setRemote("origin").call(); | |||
for (PushResult result : results) { | |||
RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master"); | |||
Status status = ref.getStatus(); | |||
@@ -576,7 +591,7 @@ public class GitServletTest { | |||
assertTrue("Verification failed! User was able to push commit! " + status.name(), Status.REJECTED_OTHER_REASON.equals(status)); | |||
} | |||
} | |||
GitBlitSuite.close(git); | |||
// close serving repository | |||
GitBlitSuite.close(verification); | |||
@@ -601,14 +616,14 @@ public class GitServletTest { | |||
public void testBlockBranchDeletion() throws Exception { | |||
testRefChange(AccessPermission.CREATE, Status.OK, Status.REJECTED_OTHER_REASON, null); | |||
} | |||
@Test | |||
public void testBlockBranchRewind() throws Exception { | |||
testRefChange(AccessPermission.DELETE, Status.OK, Status.OK, Status.REJECTED_OTHER_REASON); | |||
} | |||
@Test | |||
public void testBranchRewind() throws Exception { | |||
public void testBranchRewind() throws Exception { | |||
testRefChange(AccessPermission.REWIND, Status.OK, Status.OK, Status.OK); | |||
} | |||
@@ -616,9 +631,9 @@ public class GitServletTest { | |||
UserModel user = getUser(); | |||
delete(user); | |||
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password); | |||
// fork from original to a temporary bare repo | |||
File refChecks = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit.git"); | |||
if (refChecks.exists()) { | |||
@@ -645,7 +660,7 @@ public class GitServletTest { | |||
model.accessRestriction = AccessRestrictionType.PUSH; | |||
} | |||
model.authorizationControl = AuthorizationControl.NAMED; | |||
// grant user specified | |||
user.setRepositoryPermission(model.name, permission); | |||
@@ -663,7 +678,7 @@ public class GitServletTest { | |||
clone.setBare(false); | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(cp); | |||
try { | |||
GitBlitSuite.close(clone.call()); | |||
} catch (GitAPIException e) { | |||
@@ -672,15 +687,15 @@ public class GitServletTest { | |||
} else { | |||
// close serving repository | |||
GitBlitSuite.close(refChecks); | |||
// user does not have clone permission | |||
assertTrue(e.getMessage(), e.getMessage().contains("not permitted")); | |||
assertTrue(e.getMessage(), e.getMessage().contains("not permitted")); | |||
return; | |||
} | |||
} | |||
Git git = Git.open(local); | |||
// commit a file and push it | |||
File file = new File(local, "PUSHCHK"); | |||
OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET); | |||
@@ -698,14 +713,14 @@ public class GitServletTest { | |||
} else { | |||
// close serving repository | |||
GitBlitSuite.close(refChecks); | |||
// user does not have push permission | |||
assertTrue(e.getMessage(), e.getMessage().contains("not permitted")); | |||
GitBlitSuite.close(git); | |||
return; | |||
} | |||
} | |||
for (PushResult result : results) { | |||
RemoteRefUpdate ref = result.getRemoteUpdate("refs/heads/master"); | |||
Status status = ref.getStatus(); | |||
@@ -721,8 +736,8 @@ public class GitServletTest { | |||
return; | |||
} | |||
} | |||
// create a local branch and push the new branch back to the origin | |||
// create a local branch and push the new branch back to the origin | |||
git.branchCreate().setName("protectme").call(); | |||
RefSpec refSpec = new RefSpec("refs/heads/protectme:refs/heads/protectme"); | |||
results = git.push().setCredentialsProvider(cp).setRefSpecs(refSpec).setRemote("origin").call(); | |||
@@ -741,10 +756,10 @@ public class GitServletTest { | |||
return; | |||
} | |||
} | |||
// delete the branch locally | |||
git.branchDelete().setBranchNames("protectme").call(); | |||
// push a delete ref command | |||
refSpec = new RefSpec(":refs/heads/protectme"); | |||
results = git.push().setCredentialsProvider(cp).setRefSpecs(refSpec).setRemote("origin").call(); | |||
@@ -763,10 +778,10 @@ public class GitServletTest { | |||
return; | |||
} | |||
} | |||
// rewind master by two commits | |||
git.reset().setRef("HEAD~2").setMode(ResetType.HARD).call(); | |||
// commit a change on this detached HEAD | |||
file = new File(local, "REWINDCHK"); | |||
os = new OutputStreamWriter(new FileOutputStream(file, true), Constants.CHARSET); | |||
@@ -775,11 +790,11 @@ public class GitServletTest { | |||
w.close(); | |||
git.add().addFilepattern(file.getName()).call(); | |||
RevCommit commit = git.commit().setMessage("rewind master and new commit").call(); | |||
// Reset master to our new commit now we our local branch tip is no longer | |||
// upstream of the remote branch tip. It is an alternate tip of the branch. | |||
JGitUtils.setBranchRef(git.getRepository(), "refs/heads/master", commit.getName()); | |||
// Try pushing our new tip to the origin. | |||
// This requires the server to "rewind" it's master branch and update it | |||
// to point to our alternate tip. This leaves the original master tip | |||
@@ -795,41 +810,41 @@ public class GitServletTest { | |||
} | |||
} | |||
GitBlitSuite.close(git); | |||
// close serving repository | |||
GitBlitSuite.close(refChecks); | |||
delete(user); | |||
} | |||
@Test | |||
public void testCreateOnPush() throws Exception { | |||
testCreateOnPush(false, false); | |||
testCreateOnPush(true, false); | |||
testCreateOnPush(false, true); | |||
} | |||
private void testCreateOnPush(boolean canCreate, boolean canAdmin) throws Exception { | |||
UserModel user = new UserModel("sampleuser"); | |||
user.password = user.username; | |||
delete(user); | |||
user.canCreate = canCreate; | |||
user.canAdmin = canAdmin; | |||
GitBlit.self().updateUserModel(user.username, user, true); | |||
CredentialsProvider cp = new UsernamePasswordCredentialsProvider(user.username, user.password); | |||
// fork from original to a temporary bare repo | |||
File tmpFolder = File.createTempFile("gitblit", "").getParentFile(); | |||
File createCheck = new File(tmpFolder, "ticgit.git"); | |||
if (createCheck.exists()) { | |||
FileUtils.delete(createCheck, FileUtils.RECURSIVE); | |||
} | |||
File personalRepo = new File(GitBlitSuite.REPOSITORIES, MessageFormat.format("~{0}/ticgit.git", user.username)); | |||
GitBlitSuite.close(personalRepo); | |||
if (personalRepo.exists()) { | |||
@@ -849,9 +864,9 @@ public class GitServletTest { | |||
clone.setCloneAllBranches(true); | |||
clone.setCredentialsProvider(cp); | |||
Git git = clone.call(); | |||
GitBlitSuite.close(personalRepo); | |||
// add a personal repository remote and a project remote | |||
git.getRepository().getConfig().setString("remote", "user", "url", MessageFormat.format("{0}/~{1}/ticgit.git", url, user.username)); | |||
git.getRepository().getConfig().setString("remote", "project", "url", MessageFormat.format("{0}/project/ticgit.git", url)); | |||
@@ -868,18 +883,18 @@ public class GitServletTest { | |||
} | |||
assertTrue("User canAdmin:" + user.canAdmin + " canCreate:" + user.canCreate, user.canAdmin || user.canCreate); | |||
// confirm default personal repository permissions | |||
RepositoryModel model = GitBlit.self().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username)); | |||
assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners)); | |||
assertEquals("Unexpected authorization control", AuthorizationControl.NAMED, model.authorizationControl); | |||
assertEquals("Unexpected access restriction", AccessRestrictionType.VIEW, model.accessRestriction); | |||
} catch (GitAPIException e) { | |||
assertTrue(e.getMessage(), e.getMessage().contains("git-receive-pack not found")); | |||
assertFalse("User canAdmin:" + user.canAdmin + " canCreate:" + user.canCreate, user.canAdmin || user.canCreate); | |||
} | |||
// push to non-existent project repository | |||
try { | |||
Iterable<PushResult> results = git.push().setRemote("project").setPushAll().setCredentialsProvider(cp).call(); | |||
@@ -890,9 +905,9 @@ public class GitServletTest { | |||
Status status = ref.getStatus(); | |||
assertTrue("User failed to create repository?! " + status.name(), Status.OK.equals(status)); | |||
} | |||
assertTrue("User canAdmin:" + user.canAdmin, user.canAdmin); | |||
// confirm default project repository permissions | |||
RepositoryModel model = GitBlit.self().getRepositoryModel("project/ticgit.git"); | |||
assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners)); | |||
@@ -907,7 +922,7 @@ public class GitServletTest { | |||
GitBlitSuite.close(git); | |||
delete(user); | |||
} | |||
@Test | |||
public void testPushLog() throws IOException { | |||
String name = "refchecks/ticgit.git"; |
@@ -50,9 +50,9 @@ import com.gitblit.utils.StringUtils; | |||
/** | |||
* Test class for Groovy scripts. Mostly this is to facilitate development. | |||
* | |||
* | |||
* @author James Moger | |||
* | |||
* | |||
*/ | |||
public class GroovyScriptTest { | |||
@@ -140,7 +140,7 @@ public class GroovyScriptTest { | |||
assertEquals(5, m.toAddresses.size()); | |||
assertTrue(m.message.contains("BIT")); | |||
} | |||
@Test | |||
public void testProtectRefsCreateBranch() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -149,12 +149,12 @@ public class GroovyScriptTest { | |||
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); | |||
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository); | |||
} | |||
@Test | |||
public void testProtectRefsCreateTag() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -163,13 +163,13 @@ public class GroovyScriptTest { | |||
List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>(); | |||
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0")); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository); | |||
assertEquals(0, logger.messages.size()); | |||
} | |||
@Test | |||
public void testProtectRefsFastForward() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -179,13 +179,13 @@ public class GroovyScriptTest { | |||
commands.add(new ReceiveCommand(ObjectId | |||
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository); | |||
assertEquals(0, logger.messages.size()); | |||
} | |||
@Test | |||
public void testProtectRefsDeleteMasterBranch() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -196,14 +196,14 @@ public class GroovyScriptTest { | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), | |||
"refs/heads/master"); | |||
commands.add(command); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository); | |||
assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult()); | |||
assertEquals(0, logger.messages.size()); | |||
} | |||
@Test | |||
public void testProtectRefsDeleteOtherBranch() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -213,13 +213,13 @@ public class GroovyScriptTest { | |||
commands.add(new ReceiveCommand(ObjectId | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), | |||
"refs/heads/other")); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository); | |||
assertEquals(0, logger.messages.size()); | |||
} | |||
@Test | |||
public void testProtectRefsDeleteTag() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -230,14 +230,14 @@ public class GroovyScriptTest { | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), | |||
"refs/tags/v1.0"); | |||
commands.add(command); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository); | |||
assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult()); | |||
assertEquals(0, logger.messages.size()); | |||
} | |||
@Test | |||
public void testBlockPush() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -247,8 +247,8 @@ public class GroovyScriptTest { | |||
commands.add(new ReceiveCommand(ObjectId | |||
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
try { | |||
test("blockpush.groovy", gitblit, logger, clientLogger, commands, repository); | |||
@@ -257,7 +257,7 @@ public class GroovyScriptTest { | |||
assertTrue(e.getMessage().contains("failed")); | |||
} | |||
} | |||
@Test | |||
public void testClientLogging() throws Exception { | |||
MockGitblit gitblit = new MockGitblit(); | |||
@@ -267,15 +267,15 @@ public class GroovyScriptTest { | |||
commands.add(new ReceiveCommand(ObjectId | |||
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId | |||
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); | |||
RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); | |||
File groovyDir = GitBlit.getGroovyScriptsFolder(); | |||
File tempScript = File.createTempFile("testClientLogging", "groovy", groovyDir); | |||
tempScript.deleteOnExit(); | |||
BufferedWriter writer = new BufferedWriter(new FileWriter(tempScript)); | |||
writer.write("clientLogger.info('this is a test message')\n"); | |||
writer.flush(); | |||
writer.close(); | |||
@@ -356,18 +356,18 @@ public class GroovyScriptTest { | |||
messages.add(message); | |||
} | |||
} | |||
class MockClientLogger { | |||
List<String> messages = new ArrayList<String>(); | |||
public void info(String message) { | |||
messages.add(message); | |||
} | |||
public void error(String message) { | |||
messages.add(message); | |||
} | |||
public void error(String message, Throwable t) { | |||
PrintWriter writer = new PrintWriter(new StringWriter()); | |||
if (!StringUtils.isEmpty(message)) { |
@@ -1,3 +1,18 @@ | |||
/* | |||
* 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 static org.junit.Assert.assertEquals; | |||
@@ -77,7 +92,8 @@ public class HtpasswdUserServiceTest { | |||
{ | |||
File dir = new File(RESOURCE_DIR); | |||
FilenameFilter filter = new FilenameFilter() { | |||
public boolean accept(File dir, String file) { | |||
@Override | |||
public boolean accept(File dir, String file) { | |||
return file.endsWith(".in"); | |||
} | |||
}; | |||
@@ -92,7 +108,8 @@ public class HtpasswdUserServiceTest { | |||
{ | |||
File dir = new File(RESOURCE_DIR); | |||
FilenameFilter filter = new FilenameFilter() { | |||
public boolean accept(File dir, String file) { | |||
@Override | |||
public boolean accept(File dir, String file) { | |||
return !(file.endsWith(".in")); | |||
} | |||
}; |
@@ -29,14 +29,14 @@ import com.gitblit.models.UserModel; | |||
/** | |||
* https://code.google.com/p/gitblit/issues/detail?id=259 | |||
* | |||
* | |||
* Reported Problem: | |||
* We have an user with RWD access rights, but he can’t push. | |||
* | |||
* | |||
* @see src/test/resources/issue0259.conf | |||
* | |||
* | |||
* At the next day he try again and he can push to the project. | |||
* | |||
* | |||
* @author James Moger | |||
* | |||
*/ | |||
@@ -48,29 +48,29 @@ public class Issue0259Test extends Assert { | |||
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/issue0259.conf"); | |||
ConfigUserService service = new ConfigUserService(realmFile); | |||
RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW); | |||
RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW); | |||
UserModel a = service.getUserModel("a"); | |||
UserModel b = service.getUserModel("b"); | |||
UserModel c = service.getUserModel("c"); | |||
// assert RWD or RW+ for projects/test.git | |||
assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission); | |||
assertEquals(AccessPermission.DELETE, b.getRepositoryPermission(projects_test).permission); | |||
assertEquals(AccessPermission.REWIND, c.getRepositoryPermission(projects_test).permission); | |||
assertTrue(a.canPush(projects_test)); | |||
assertTrue(b.canPush(projects_test)); | |||
assertTrue(c.canPush(projects_test)); | |||
@@ -82,7 +82,7 @@ public class Issue0259Test extends Assert { | |||
assertFalse(a.canRewindRef(projects_test)); | |||
assertFalse(b.canRewindRef(projects_test)); | |||
assertTrue(c.canRewindRef(projects_test)); | |||
// assert R for test.git | |||
assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission); | |||
assertEquals(AccessPermission.CLONE, b.getRepositoryPermission(test).permission); | |||
@@ -95,7 +95,7 @@ public class Issue0259Test extends Assert { | |||
assertFalse(b.canPush(test)); | |||
assertTrue(c.canPush(test)); | |||
} | |||
@Test | |||
public void testTeamsOrder() throws Exception { | |||
testTeams(false); | |||
@@ -109,20 +109,20 @@ public class Issue0259Test extends Assert { | |||
/** | |||
* Tests multiple teams each with a regex permisson that will match. The | |||
* highest matching permission should be used. Order should be irrelevant. | |||
* | |||
* | |||
* @param reverseOrder | |||
* @throws Exception | |||
*/ | |||
private void testTeams(boolean reverseOrder) throws Exception { | |||
RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW); | |||
RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW); | |||
TeamModel t1 = new TeamModel("t1"); | |||
t1.setRepositoryPermission(".*", AccessPermission.CLONE); | |||
TeamModel t2 = new TeamModel("t2"); | |||
t2.setRepositoryPermission("projects/.*", AccessPermission.DELETE); | |||
t2.setRepositoryPermission("projects/.*", AccessPermission.DELETE); | |||
UserModel a = new UserModel("a"); | |||
if (reverseOrder) { | |||
a.teams.add(t2); | |||
@@ -131,7 +131,7 @@ public class Issue0259Test extends Assert { | |||
a.teams.add(t1); | |||
a.teams.add(t2); | |||
} | |||
// simulate a repository rename | |||
a.setRepositoryPermission("projects/renamed.git", null); | |||
t1.setRepositoryPermission("projects/renamed.git", null); | |||
@@ -139,47 +139,47 @@ public class Issue0259Test extends Assert { | |||
assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission); | |||
assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission); | |||
assertTrue(a.canClone(test)); | |||
assertTrue(a.canClone(projects_test)); | |||
assertFalse(a.canDeleteRef(test)); | |||
assertTrue(a.canDeleteRef(projects_test)); | |||
} | |||
@Test | |||
public void testTeam() throws Exception { | |||
testTeam(false); | |||
testTeam(false); | |||
} | |||
@Test | |||
public void testTeamReverseOrder() throws Exception { | |||
testTeam(true); | |||
} | |||
/** | |||
* Test a single team that has multiple repository permissions that all match. | |||
* Here defined order IS important. The first permission match wins so it is | |||
* important to define permissions from most-specific match to least-specific | |||
* match. | |||
* | |||
* | |||
* If the defined permissions are: | |||
* R:.* | |||
* RWD:projects/.* | |||
* then the expected result is R for all repositories because it is first. | |||
* | |||
* | |||
* But if the defined permissions are: | |||
* RWD:projects/.* | |||
* R:.* | |||
* then the expected result is RWD for projects/test.git and R for test.git | |||
* | |||
* | |||
* @param reverseOrder | |||
* @throws Exception | |||
*/ | |||
private void testTeam(boolean reverseOrder) throws Exception { | |||
RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW); | |||
RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW); | |||
TeamModel t1 = new TeamModel("t1"); | |||
if (reverseOrder) { | |||
t1.setRepositoryPermission("projects/.*", AccessPermission.DELETE); | |||
@@ -194,7 +194,7 @@ public class Issue0259Test extends Assert { | |||
// simulate a repository rename | |||
a.setRepositoryPermission("projects/renamed.git", null); | |||
t1.setRepositoryPermission("projects/renamed.git", null); | |||
assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission); | |||
assertTrue(a.canClone(test)); | |||
assertFalse(a.canDeleteRef(test)); | |||
@@ -208,6 +208,6 @@ public class Issue0259Test extends Assert { | |||
// R permission is found first | |||
assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(projects_test).permission); | |||
assertFalse(a.canDeleteRef(projects_test)); | |||
} | |||
} | |||
} | |||
} |
@@ -28,12 +28,12 @@ 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 | |||
* | |||
*/ | |||
@@ -45,29 +45,29 @@ public class Issue0271Test extends Assert { | |||
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); |
@@ -228,7 +228,7 @@ public class JGitUtilsTest { | |||
String repositoryAll = "NewTestRepositoryAll.git"; | |||
String repositoryUmask = "NewTestRepositoryUmask.git"; | |||
String sgidParent = "sgid"; | |||
File parent = new File(GitBlitSuite.REPOSITORIES, sgidParent); | |||
File folder = null; | |||
boolean parentExisted = parent.exists(); | |||
@@ -243,21 +243,21 @@ public class JGitUtilsTest { | |||
Repository repository = JGitUtils.createRepository(parent, repositoryAll, "all"); | |||
folder = FileKey.resolve(new File(parent, repositoryAll), FS.DETECTED); | |||
assertNotNull(repository); | |||
assertEquals("2", repository.getConfig().getString("core", null, "sharedRepository")); | |||
assertTrue(folder.exists()); | |||
mode = JnaUtils.getFilemode(folder); | |||
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID); | |||
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD"); | |||
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG); | |||
assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO); | |||
mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config"); | |||
assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG); | |||
assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO); | |||
repository.close(); | |||
RepositoryCache.close(repository); | |||
@@ -266,13 +266,13 @@ public class JGitUtilsTest { | |||
repository = JGitUtils.createRepository(parent, repositoryUmask, "umask"); | |||
folder = FileKey.resolve(new File(parent, repositoryUmask), FS.DETECTED); | |||
assertNotNull(repository); | |||
assertEquals(null, repository.getConfig().getString("core", null, "sharedRepository")); | |||
assertTrue(folder.exists()); | |||
mode = JnaUtils.getFilemode(folder); | |||
assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID); | |||
repository.close(); | |||
RepositoryCache.close(repository); | |||
} | |||
@@ -372,7 +372,7 @@ public class JGitUtilsTest { | |||
assertEquals("183474d554e6f68478a02d9d7888b67a9338cdff", list.get(0).notesRef | |||
.getReferencedObjectId().getName()); | |||
} | |||
@Test | |||
public void testRelinkHEAD() throws Exception { | |||
Repository repository = GitBlitSuite.getJGitRepository(); | |||
@@ -381,7 +381,7 @@ public class JGitUtilsTest { | |||
assertEquals("refs/heads/master", currentRef); | |||
List<String> availableHeads = JGitUtils.getAvailableHeadTargets(repository); | |||
assertTrue(availableHeads.size() > 0); | |||
// set HEAD to stable-1.2 | |||
JGitUtils.setHEADtoRef(repository, "refs/heads/stable-1.2"); | |||
currentRef = JGitUtils.getHEADRef(repository); | |||
@@ -391,19 +391,19 @@ public class JGitUtilsTest { | |||
JGitUtils.setHEADtoRef(repository, "refs/heads/master"); | |||
currentRef = JGitUtils.getHEADRef(repository); | |||
assertEquals("refs/heads/master", currentRef); | |||
repository.close(); | |||
} | |||
@Test | |||
public void testRelinkBranch() throws Exception { | |||
Repository repository = GitBlitSuite.getJGitRepository(); | |||
// create/set the branch | |||
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "3b358ce514ec655d3ff67de1430994d8428cdb04"); | |||
assertEquals(1, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04")).size()); | |||
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("755dfdb40948f5c1ec79e06bde3b0a78c352f27f"))); | |||
// reset the branch | |||
JGitUtils.setBranchRef(repository, "refs/heads/reftest", "755dfdb40948f5c1ec79e06bde3b0a78c352f27f"); | |||
assertEquals(null, JGitUtils.getAllRefs(repository).get(ObjectId.fromString("3b358ce514ec655d3ff67de1430994d8428cdb04"))); | |||
@@ -606,7 +606,7 @@ public class JGitUtilsTest { | |||
assertTrue(zipFileB.length() > 0); | |||
zipFileB.delete(); | |||
} | |||
@Test | |||
public void testPlots() throws Exception { | |||
Repository repository = GitBlitSuite.getTicgitRepository(); |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2011 gitblit.com. | |||
* 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. |
@@ -40,34 +40,34 @@ import com.unboundid.ldif.LDIFReader; | |||
/** | |||
* An Integration test for LDAP that tests going against an in-memory UnboundID | |||
* LDAP server. | |||
* | |||
* | |||
* @author jcrygier | |||
* | |||
*/ | |||
public class LdapUserServiceTest { | |||
private LdapUserService ldapUserService; | |||
static int ldapPort = 1389; | |||
@BeforeClass | |||
public static void createInMemoryLdapServer() throws Exception { | |||
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=MyDomain"); | |||
config.addAdditionalBindCredentials("cn=Directory Manager", "password"); | |||
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("default", ldapPort)); | |||
config.setSchema(null); | |||
InMemoryDirectoryServer ds = new InMemoryDirectoryServer(config); | |||
ds.importFromLDIF(true, new LDIFReader(LdapUserServiceTest.class.getResourceAsStream("resources/ldapUserServiceSampleData.ldif"))); | |||
ds.startListening(); | |||
} | |||
@Before | |||
public void createLdapUserService() { | |||
ldapUserService = new LdapUserService(); | |||
ldapUserService.setup(getSettings()); | |||
} | |||
private MemorySettings getSettings() { | |||
Map<String, Object> backingMap = new HashMap<String, Object>(); | |||
backingMap.put("realm.ldap.server", "ldap://localhost:" + ldapPort); | |||
@@ -83,79 +83,79 @@ public class LdapUserServiceTest { | |||
backingMap.put("realm.ldap.admins", "UserThree @Git_Admins \"@Git Admins\""); | |||
backingMap.put("realm.ldap.displayName", "displayName"); | |||
backingMap.put("realm.ldap.email", "email"); | |||
MemorySettings ms = new MemorySettings(backingMap); | |||
return ms; | |||
} | |||
@Test | |||
public void testAuthenticate() { | |||
public void testAuthenticate() { | |||
UserModel userOneModel = ldapUserService.authenticate("UserOne", "userOnePassword".toCharArray()); | |||
assertNotNull(userOneModel); | |||
assertNotNull(userOneModel.getTeam("git_admins")); | |||
assertNotNull(userOneModel.getTeam("git_users")); | |||
assertTrue(userOneModel.canAdmin); | |||
UserModel userOneModelFailedAuth = ldapUserService.authenticate("UserOne", "userTwoPassword".toCharArray()); | |||
assertNull(userOneModelFailedAuth); | |||
UserModel userTwoModel = ldapUserService.authenticate("UserTwo", "userTwoPassword".toCharArray()); | |||
assertNotNull(userTwoModel); | |||
assertNotNull(userTwoModel.getTeam("git_users")); | |||
assertNull(userTwoModel.getTeam("git_admins")); | |||
assertNotNull(userTwoModel.getTeam("git admins")); | |||
assertTrue(userTwoModel.canAdmin); | |||
UserModel userThreeModel = ldapUserService.authenticate("UserThree", "userThreePassword".toCharArray()); | |||
assertNotNull(userThreeModel); | |||
assertNotNull(userThreeModel.getTeam("git_users")); | |||
assertNull(userThreeModel.getTeam("git_admins")); | |||
assertTrue(userThreeModel.canAdmin); | |||
} | |||
@Test | |||
public void testDisplayName() { | |||
UserModel userOneModel = ldapUserService.authenticate("UserOne", "userOnePassword".toCharArray()); | |||
assertNotNull(userOneModel); | |||
assertEquals("User One", userOneModel.displayName); | |||
// Test more complicated scenarios - concat | |||
MemorySettings ms = getSettings(); | |||
ms.put("realm.ldap.displayName", "${personalTitle}. ${givenName} ${surname}"); | |||
ldapUserService = new LdapUserService(); | |||
ldapUserService.setup(ms); | |||
userOneModel = ldapUserService.authenticate("UserOne", "userOnePassword".toCharArray()); | |||
assertNotNull(userOneModel); | |||
assertEquals("Mr. User One", userOneModel.displayName); | |||
} | |||
@Test | |||
public void testEmail() { | |||
UserModel userOneModel = ldapUserService.authenticate("UserOne", "userOnePassword".toCharArray()); | |||
assertNotNull(userOneModel); | |||
assertEquals("userone@gitblit.com", userOneModel.emailAddress); | |||
// Test more complicated scenarios - concat | |||
MemorySettings ms = getSettings(); | |||
ms.put("realm.ldap.email", "${givenName}.${surname}@gitblit.com"); | |||
ldapUserService = new LdapUserService(); | |||
ldapUserService.setup(ms); | |||
userOneModel = ldapUserService.authenticate("UserOne", "userOnePassword".toCharArray()); | |||
assertNotNull(userOneModel); | |||
assertEquals("User.One@gitblit.com", userOneModel.emailAddress); | |||
} | |||
@Test | |||
public void testLdapInjection() { | |||
// Inject so "(&(objectClass=person)(sAMAccountName=${username}))" becomes "(&(objectClass=person)(sAMAccountName=*)(userPassword=userOnePassword))" | |||
// Thus searching by password | |||
UserModel userOneModel = ldapUserService.authenticate("*)(userPassword=userOnePassword", "userOnePassword".toCharArray()); | |||
assertNull(userOneModel); | |||
} | |||
@Test | |||
public void testLocalAccount() { | |||
UserModel localAccount = new UserModel("bruce"); | |||
@@ -164,8 +164,8 @@ public class LdapUserServiceTest { | |||
ldapUserService.deleteUser(localAccount.username); | |||
assertTrue("Failed to add local account", | |||
ldapUserService.updateUserModel(localAccount)); | |||
assertEquals("Accounts are not equal!", | |||
localAccount, | |||
assertEquals("Accounts are not equal!", | |||
localAccount, | |||
ldapUserService.authenticate(localAccount.username, "gimmesomesugar".toCharArray())); | |||
assertTrue("Failed to delete local account!", | |||
ldapUserService.deleteUser(localAccount.username)); |
@@ -39,25 +39,25 @@ import com.gitblit.utils.JGitUtils; | |||
/** | |||
* Tests Lucene indexing and querying. | |||
* | |||
* | |||
* @author James Moger | |||
* | |||
* | |||
*/ | |||
public class LuceneExecutorTest { | |||
LuceneExecutor lucene; | |||
private LuceneExecutor newLuceneExecutor() { | |||
Map<String, Object> map = new HashMap<String, Object>(); | |||
MemorySettings settings = new MemorySettings(map); | |||
MemorySettings settings = new MemorySettings(map); | |||
return new LuceneExecutor(settings, GitBlitSuite.REPOSITORIES); | |||
} | |||
private RepositoryModel newRepositoryModel(Repository repository) { | |||
private RepositoryModel newRepositoryModel(Repository repository) { | |||
RepositoryModel model = new RepositoryModel(); | |||
model.name = FileUtils.getRelativePath(GitBlitSuite.REPOSITORIES, repository.getDirectory()); | |||
model.hasCommits = JGitUtils.hasCommits(repository); | |||
// index all local branches | |||
model.indexedBranches = new ArrayList<String>(); | |||
for (RefModel ref : JGitUtils.getLocalBranches(repository, true, -1)) { | |||
@@ -65,17 +65,17 @@ public class LuceneExecutorTest { | |||
} | |||
return model; | |||
} | |||
@Before | |||
public void setup() { | |||
lucene = newLuceneExecutor(); | |||
} | |||
@After | |||
public void tearDown() { | |||
lucene.close(); | |||
} | |||
@Test | |||
public void testIndex() throws Exception { | |||
// reindex helloworld | |||
@@ -83,11 +83,11 @@ public class LuceneExecutorTest { | |||
RepositoryModel model = newRepositoryModel(repository); | |||
lucene.reindex(model, repository); | |||
repository.close(); | |||
SearchResult result = lucene.search("type:blob AND path:bit.bit", 1, 1, model.name).get(0); | |||
SearchResult result = lucene.search("type:blob AND path:bit.bit", 1, 1, model.name).get(0); | |||
assertEquals("Mike Donaghy", result.author); | |||
result = lucene.search("type:blob AND path:clipper.prg", 1, 1, model.name).get(0); | |||
assertEquals("tinogomes", result.author); | |||
result = lucene.search("type:blob AND path:clipper.prg", 1, 1, model.name).get(0); | |||
assertEquals("tinogomes", result.author); | |||
// reindex JGit | |||
repository = GitBlitSuite.getJGitRepository(); | |||
@@ -99,10 +99,10 @@ public class LuceneExecutorTest { | |||
@Test | |||
public void testQuery() throws Exception { | |||
// 2 occurrences on the master branch | |||
Repository repository = GitBlitSuite.getHelloworldRepository(); | |||
Repository repository = GitBlitSuite.getHelloworldRepository(); | |||
RepositoryModel model = newRepositoryModel(repository); | |||
repository.close(); | |||
List<SearchResult> results = lucene.search("ada", 1, 10, model.name); | |||
assertEquals(2, results.size()); | |||
for (SearchResult res : results) { | |||
@@ -112,37 +112,37 @@ public class LuceneExecutorTest { | |||
// author test | |||
results = lucene.search("author: tinogomes AND type:commit", 1, 10, model.name); | |||
assertEquals(2, results.size()); | |||
// blob test | |||
results = lucene.search("type: blob AND \"import std.stdio\"", 1, 10, model.name); | |||
assertEquals(1, results.size()); | |||
assertEquals("d.D", results.get(0).path); | |||
// commit test | |||
repository = GitBlitSuite.getJGitRepository(); | |||
model = newRepositoryModel(repository); | |||
repository.close(); | |||
results = lucene.search("\"initial jgit contribution to eclipse.org\"", 1, 10, model.name); | |||
assertEquals(1, results.size()); | |||
assertEquals("Git Development Community", results.get(0).author); | |||
assertEquals("1a6964c8274c50f0253db75f010d78ef0e739343", results.get(0).commitId); | |||
assertEquals("refs/heads/master", results.get(0).branch); | |||
// hash id tests | |||
results = lucene.search("type:commit AND commit:1a6964c8274c50f0253db75f010d78ef0e739343", 1, 10, model.name); | |||
assertEquals(1, results.size()); | |||
results = lucene.search("type:commit AND commit:1a6964c8274*", 1, 10, model.name); | |||
assertEquals("Shawn O. Pearce", results.get(0).committer); | |||
assertEquals(1, results.size()); | |||
assertEquals(1, results.size()); | |||
// annotated tag test | |||
results = lucene.search("I663208919f297836a9c16bf458e4a43ffaca4c12", 1, 10, model.name); | |||
assertEquals(1, results.size()); | |||
assertEquals("[v1.3.0.201202151440-r]", results.get(0).tags.toString()); | |||
assertEquals("[v1.3.0.201202151440-r]", results.get(0).tags.toString()); | |||
} | |||
@Test | |||
public void testMultiSearch() throws Exception { | |||
List<String> list = new ArrayList<String>(); | |||
@@ -157,14 +157,14 @@ public class LuceneExecutorTest { | |||
List<SearchResult> results = lucene.search("test", 1, 10, list); | |||
assertEquals(10, results.size()); | |||
} | |||
@Test | |||
public void testDeleteBlobFromIndex() throws Exception { | |||
// start with a fresh reindex of entire repository | |||
Repository repository = GitBlitSuite.getHelloworldRepository(); | |||
RepositoryModel model = newRepositoryModel(repository); | |||
lucene.reindex(model, repository); | |||
// now delete a blob | |||
assertTrue(lucene.deleteBlob(model.name, "refs/heads/master", "java.java")); | |||
assertFalse(lucene.deleteBlob(model.name, "refs/heads/master", "java.java")); |
@@ -60,10 +60,10 @@ public class ModelUtilsTest { | |||
username = "James"; | |||
assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username)); | |||
ModelUtils.setUserRepoPrefix("usr/"); | |||
username = "noMan"; | |||
assertEquals("usr/"+username.toLowerCase(), ModelUtils.getPersonalPath(username)); | |||
assertEquals("usr/"+username.toLowerCase(), ModelUtils.getPersonalPath(username)); | |||
} | |||
@@ -50,7 +50,7 @@ public class RedmineUserServiceTest { | |||
assertNotNull(userModel.cookie); | |||
assertThat(userModel.canAdmin, is(false)); | |||
} | |||
@Test | |||
public void testLocalAccount() { | |||
RedmineUserService redmineUserService = new RedmineUserService(); | |||
@@ -62,8 +62,8 @@ public class RedmineUserServiceTest { | |||
redmineUserService.deleteUser(localAccount.username); | |||
assertTrue("Failed to add local account", | |||
redmineUserService.updateUserModel(localAccount)); | |||
assertEquals("Accounts are not equal!", | |||
localAccount, | |||
assertEquals("Accounts are not equal!", | |||
localAccount, | |||
redmineUserService.authenticate(localAccount.username, "gimmesomesugar".toCharArray())); | |||
assertTrue("Failed to delete local account!", | |||
redmineUserService.deleteUser(localAccount.username)); |
@@ -31,37 +31,37 @@ import com.gitblit.GitBlit; | |||
import com.gitblit.models.RepositoryModel; | |||
public class RepositoryModelTest { | |||
private static boolean wasStarted = false; | |||
@BeforeClass | |||
public static void startGitBlit() throws Exception { | |||
wasStarted = GitBlitSuite.startGitblit() == false; | |||
} | |||
@AfterClass | |||
public static void stopGitBlit() throws Exception { | |||
if (wasStarted == false) | |||
GitBlitSuite.stopGitblit(); | |||
} | |||
@Before | |||
public void initializeConfiguration() throws Exception{ | |||
Repository r = GitBlitSuite.getHelloworldRepository(); | |||
StoredConfig config = r.getConfig(); | |||
config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); | |||
config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "commitMessageRegEx", "\\d"); | |||
config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "anotherProperty", "Hello"); | |||
config.save(); | |||
} | |||
@After | |||
public void teardownConfiguration() throws Exception { | |||
Repository r = GitBlitSuite.getHelloworldRepository(); | |||
StoredConfig config = r.getConfig(); | |||
config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); | |||
config.save(); | |||
} | |||
@@ -70,25 +70,25 @@ public class RepositoryModelTest { | |||
public void testGetCustomProperty() throws Exception { | |||
RepositoryModel model = GitBlit.self().getRepositoryModel( | |||
GitBlitSuite.getHelloworldRepository().getDirectory().getName()); | |||
assertEquals("\\d", model.customFields.get("commitMessageRegEx")); | |||
assertEquals("Hello", model.customFields.get("anotherProperty")); | |||
} | |||
@Test | |||
public void testSetCustomProperty() throws Exception { | |||
RepositoryModel model = GitBlit.self().getRepositoryModel( | |||
GitBlitSuite.getHelloworldRepository().getDirectory().getName()); | |||
assertEquals("\\d", model.customFields.get("commitMessageRegEx")); | |||
assertEquals("Hello", model.customFields.get("anotherProperty")); | |||
assertEquals("Hello", model.customFields.put("anotherProperty", "GoodBye")); | |||
GitBlit.self().updateRepositoryModel(model.name, model, false); | |||
model = GitBlit.self().getRepositoryModel( | |||
GitBlitSuite.getHelloworldRepository().getDirectory().getName()); | |||
assertEquals("\\d", model.customFields.get("commitMessageRegEx")); | |||
assertEquals("GoodBye", model.customFields.get("anotherProperty")); | |||
} |
@@ -54,9 +54,9 @@ import com.gitblit.utils.RpcUtils; | |||
/** | |||
* Tests all the rpc client utility methods, the rpc filter and rpc servlet. | |||
* | |||
* | |||
* @author James Moger | |||
* | |||
* | |||
*/ | |||
public class RpcTests { | |||
@@ -103,7 +103,7 @@ public class RpcTests { | |||
list = RpcUtils.getUsers(url, "admin", "admin".toCharArray()); | |||
assertTrue("User list is empty!", list.size() > 0); | |||
} | |||
@Test | |||
public void testGetUser() throws IOException { | |||
UserModel user = null; | |||
@@ -215,7 +215,7 @@ public class RpcTests { | |||
assertTrue("Failed to update repository!", RpcUtils.updateRepository(retrievedRepository.name, retrievedRepository, | |||
url, account, password.toCharArray())); | |||
retrievedRepository = findRepository(retrievedRepository.name); | |||
// memberships | |||
UserModel testMember = new UserModel("justadded"); | |||
assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray())); | |||
@@ -272,7 +272,7 @@ public class RpcTests { | |||
public void testTeamAdministration() throws IOException { | |||
List<TeamModel> teams = RpcUtils.getTeams(url, account, password.toCharArray()); | |||
assertEquals(1, teams.size()); | |||
// Create the A-Team | |||
TeamModel aTeam = new TeamModel("A-Team"); | |||
aTeam.users.add("admin"); | |||
@@ -302,7 +302,7 @@ public class RpcTests { | |||
} | |||
} | |||
assertNotNull(helloworld); | |||
// Confirm that we have added the team | |||
List<String> helloworldTeams = RpcUtils.getRepositoryTeams(helloworld, url, account, | |||
password.toCharArray()); | |||
@@ -319,7 +319,7 @@ public class RpcTests { | |||
helloworldTeams = RpcUtils.getRepositoryTeams(helloworld, url, account, | |||
password.toCharArray()); | |||
assertEquals(0, helloworldTeams.size()); | |||
// delete the A-Team | |||
assertTrue(RpcUtils.deleteTeam(aTeam, url, account, password.toCharArray())); | |||
@@ -150,7 +150,7 @@ public class StringUtilsTest { | |||
assertFalse(StringUtils.fuzzyMatch("123", "12345")); | |||
assertFalse(StringUtils.fuzzyMatch("AbCdEfHIJ", "abc*hhh")); | |||
} | |||
@Test | |||
public void testGetRepositoryPath() throws Exception { | |||
assertEquals("gitblit/gitblit.git", StringUtils.extractRepositoryPath("git://github.com/gitblit/gitblit.git", new String [] { ".*?://github.com/(.*)" })); |
@@ -54,7 +54,7 @@ public class SyndicationUtilsTest { | |||
entries.add(entry); | |||
} | |||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |||
SyndicationUtils.toRSS("http://localhost", "", "Title", "Description", | |||
SyndicationUtils.toRSS("http://localhost", "", "Title", "Description", | |||
entries, os); | |||
String feed = os.toString(); | |||
os.close(); |
@@ -39,18 +39,19 @@ import com.gitblit.utils.X509Utils.X509Metadata; | |||
/** | |||
* Unit tests for X509 certificate generation. | |||
* | |||
* | |||
* @author James Moger | |||
* | |||
* | |||
*/ | |||
public class X509UtilsTest extends Assert { | |||
// passwords are case-sensitive and may be length-limited | |||
// based on the JCE policy files | |||
String caPassword = "aBcDeFg"; | |||
File folder = new File(System.getProperty("user.dir"), "x509test"); | |||
X509Log log = new X509Log() { | |||
@Override | |||
public void log(String message) { | |||
System.out.println(message); | |||
} | |||
@@ -62,69 +63,69 @@ public class X509UtilsTest extends Assert { | |||
X509Metadata goMetadata = new X509Metadata("localhost", caPassword); | |||
X509Utils.prepareX509Infrastructure(goMetadata, folder, log); | |||
} | |||
@After | |||
public void cleanUp() throws Exception { | |||
if (folder.exists()) { | |||
FileUtils.delete(folder, FileUtils.RECURSIVE); | |||
} | |||
} | |||
@Test | |||
public void testNewCA() throws Exception { | |||
public void testNewCA() throws Exception { | |||
File storeFile = new File(folder, X509Utils.CA_KEY_STORE); | |||
X509Utils.getPrivateKey(X509Utils.CA_ALIAS, storeFile, caPassword); | |||
X509Certificate cert = X509Utils.getCertificate(X509Utils.CA_ALIAS, storeFile, caPassword); | |||
assertEquals("O=Gitblit,OU=Gitblit,CN=Gitblit Certificate Authority", cert.getIssuerDN().getName()); | |||
} | |||
} | |||
@Test | |||
public void testCertificateUserMapping() throws Exception { | |||
public void testCertificateUserMapping() throws Exception { | |||
File storeFile = new File(folder, X509Utils.CA_KEY_STORE); | |||
PrivateKey caPrivateKey = X509Utils.getPrivateKey(X509Utils.CA_ALIAS, storeFile, caPassword); | |||
X509Certificate caCert = X509Utils.getCertificate(X509Utils.CA_ALIAS, storeFile, caPassword); | |||
X509Metadata userMetadata = new X509Metadata("james", "james"); | |||
userMetadata.serverHostname = "www.myserver.com"; | |||
userMetadata.userDisplayname = "James Moger"; | |||
userMetadata.passwordHint = "your name"; | |||
userMetadata.oids.put("C", "US"); | |||
X509Certificate cert1 = X509Utils.newClientCertificate(userMetadata, caPrivateKey, caCert, storeFile.getParentFile()); | |||
UserModel userModel1 = HttpUtils.getUserModelFromCertificate(cert1); | |||
assertEquals(userMetadata.commonName, userModel1.username); | |||
assertEquals(userMetadata.emailAddress, userModel1.emailAddress); | |||
assertEquals("C=US,O=Gitblit,OU=Gitblit,CN=james", cert1.getSubjectDN().getName()); | |||
X509Certificate cert2 = X509Utils.newClientCertificate(userMetadata, caPrivateKey, caCert, storeFile.getParentFile()); | |||
UserModel userModel2 = HttpUtils.getUserModelFromCertificate(cert2); | |||
assertEquals(userMetadata.commonName, userModel2.username); | |||
assertEquals(userMetadata.emailAddress, userModel2.emailAddress); | |||
assertEquals("C=US,O=Gitblit,OU=Gitblit,CN=james", cert2.getSubjectDN().getName()); | |||
assertNotSame("Serial numbers are the same!", cert1.getSerialNumber().longValue(), cert2.getSerialNumber().longValue()); | |||
} | |||
@Test | |||
public void testUserBundle() throws Exception { | |||
File storeFile = new File(folder, X509Utils.CA_KEY_STORE); | |||
X509Metadata userMetadata = new X509Metadata("james", "james"); | |||
userMetadata.serverHostname = "www.myserver.com"; | |||
userMetadata.serverHostname = "www.myserver.com"; | |||
userMetadata.userDisplayname = "James Moger"; | |||
userMetadata.passwordHint = "your name"; | |||
File zip = X509Utils.newClientBundle(userMetadata, storeFile, caPassword, log); | |||
assertTrue(zip.exists()); | |||
List<String> expected = Arrays.asList( | |||
userMetadata.commonName + ".pem", | |||
userMetadata.commonName + ".p12", | |||
userMetadata.commonName + ".cer", | |||
"ca.cer", | |||
"README.TXT"); | |||
ZipInputStream zis = new ZipInputStream(new FileInputStream(zip)); | |||
ZipEntry entry = null; | |||
while ((entry = zis.getNextEntry()) != null) { | |||
@@ -132,49 +133,49 @@ public class X509UtilsTest extends Assert { | |||
} | |||
zis.close(); | |||
} | |||
@Test | |||
public void testCertificateRevocation() throws Exception { | |||
public void testCertificateRevocation() throws Exception { | |||
File storeFile = new File(folder, X509Utils.CA_KEY_STORE); | |||
PrivateKey caPrivateKey = X509Utils.getPrivateKey(X509Utils.CA_ALIAS, storeFile, caPassword); | |||
X509Certificate caCert = X509Utils.getCertificate(X509Utils.CA_ALIAS, storeFile, caPassword); | |||
X509Metadata userMetadata = new X509Metadata("james", "james"); | |||
userMetadata.serverHostname = "www.myserver.com"; | |||
userMetadata.userDisplayname = "James Moger"; | |||
userMetadata.passwordHint = "your name"; | |||
// generate a new client certificate | |||
X509Certificate cert1 = X509Utils.newClientCertificate(userMetadata, caPrivateKey, caCert, storeFile.getParentFile()); | |||
// confirm this certificate IS NOT revoked | |||
File caRevocationList = new File(folder, X509Utils.CA_REVOCATION_LIST); | |||
assertFalse(X509Utils.isRevoked(cert1, caRevocationList)); | |||
// revoke certificate and then confirm it IS revoked | |||
X509Utils.revoke(cert1, RevocationReason.ACompromise, caRevocationList, storeFile, caPassword, log); | |||
assertTrue(X509Utils.isRevoked(cert1, caRevocationList)); | |||
// generate a second certificate | |||
X509Certificate cert2 = X509Utils.newClientCertificate(userMetadata, caPrivateKey, caCert, storeFile.getParentFile()); | |||
// confirm second certificate IS NOT revoked | |||
assertTrue(X509Utils.isRevoked(cert1, caRevocationList)); | |||
assertFalse(X509Utils.isRevoked(cert2, caRevocationList)); | |||
// revoke second certificate and then confirm it IS revoked | |||
X509Utils.revoke(cert2, RevocationReason.ACompromise, caRevocationList, caPrivateKey, log); | |||
assertTrue(X509Utils.isRevoked(cert1, caRevocationList)); | |||
assertTrue(X509Utils.isRevoked(cert2, caRevocationList)); | |||
// generate a third certificate | |||
X509Certificate cert3 = X509Utils.newClientCertificate(userMetadata, caPrivateKey, caCert, storeFile.getParentFile()); | |||
// confirm third certificate IS NOT revoked | |||
assertTrue(X509Utils.isRevoked(cert1, caRevocationList)); | |||
assertTrue(X509Utils.isRevoked(cert2, caRevocationList)); | |||
assertFalse(X509Utils.isRevoked(cert3, caRevocationList)); | |||
// revoke third certificate and then confirm it IS revoked | |||
X509Utils.revoke(cert3, RevocationReason.ACompromise, caRevocationList, caPrivateKey, log); | |||
assertTrue(X509Utils.isRevoked(cert1, caRevocationList)); |
@@ -22,9 +22,9 @@ import java.util.Properties; | |||
import com.gitblit.IStoredSettings; | |||
public class MemorySettings extends IStoredSettings { | |||
private Map<String, Object> backingMap; | |||
public MemorySettings(Map<String, Object> backingMap) { | |||
super(MemorySettings.class); | |||
this.backingMap = backingMap; | |||
@@ -34,10 +34,10 @@ public class MemorySettings extends IStoredSettings { | |||
protected Properties read() { | |||
Properties props = new Properties(); | |||
props.putAll(backingMap); | |||
return props; | |||
} | |||
public void put(Object key, Object value) { | |||
backingMap.put(key.toString(), value); | |||
} |