From: James Moger Date: Mon, 25 Nov 2013 02:28:27 +0000 (-0500) Subject: Update unit tests for refactored architecture X-Git-Tag: v1.4.0~173 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f8f6aa4d07cdfaaf23e24bf9eaf0a5fb9b437dda;p=gitblit.git Update unit tests for refactored architecture Change-Id: I04639db977c515e5e1090ef8f0e1ce858820cb03 --- diff --git a/src/main/distrib/data/groovy/sendmail-html.groovy b/src/main/distrib/data/groovy/sendmail-html.groovy index 2912e564..26925568 100644 --- a/src/main/distrib/data/groovy/sendmail-html.groovy +++ b/src/main/distrib/data/groovy/sendmail-html.groovy @@ -500,9 +500,9 @@ mailWriter.baseCommitDiffUrl = baseCommitDiffUrl mailWriter.forwardSlashChar = forwardSlashChar mailWriter.commands = commands mailWriter.url = url -mailWriter.mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true) -mailWriter.includeGravatar = GitBlit.getBoolean(Keys.web.allowGravatar, true) -mailWriter.shortCommitIdLength = GitBlit.getInteger(Keys.web.shortCommitIdLength, 8) +mailWriter.mountParameters = gitblit.getBoolean(Keys.web.mountParameters, true) +mailWriter.includeGravatar = gitblit.getBoolean(Keys.web.allowGravatar, true) +mailWriter.shortCommitIdLength = gitblit.getInteger(Keys.web.shortCommitIdLength, 8) def content = mailWriter.write() diff --git a/src/main/java/com/gitblit/git/GitblitReceivePack.java b/src/main/java/com/gitblit/git/GitblitReceivePack.java index 11b1bda8..95d17fa5 100644 --- a/src/main/java/com/gitblit/git/GitblitReceivePack.java +++ b/src/main/java/com/gitblit/git/GitblitReceivePack.java @@ -103,7 +103,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P this.settings = gitblit.getSettings(); this.gitblit = gitblit; this.repository = repository; - this.user = user == null ? UserModel.ANONYMOUS : user; + this.user = user; this.groovyDir = gitblit.getHooksFolder(); try { // set Grape root diff --git a/src/main/java/com/gitblit/servlet/RpcFilter.java b/src/main/java/com/gitblit/servlet/RpcFilter.java index 02f419ff..6163252d 100644 --- a/src/main/java/com/gitblit/servlet/RpcFilter.java +++ b/src/main/java/com/gitblit/servlet/RpcFilter.java @@ -27,11 +27,9 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import com.gitblit.Constants; +import com.gitblit.Constants.RpcRequest; import com.gitblit.IStoredSettings; import com.gitblit.Keys; -import com.gitblit.Constants.RpcRequest; -import com.gitblit.Keys.web; import com.gitblit.manager.IRuntimeManager; import com.gitblit.manager.ISessionManager; import com.gitblit.models.UserModel; @@ -138,10 +136,8 @@ public class RpcFilter extends AuthenticationFilter { return; } // valid user, but not for requested access. send 403. - if (runtimeManager.isDebugMode()) { - logger.info(MessageFormat.format("RPC: {0} forbidden to access {1}", + logger.warn(MessageFormat.format("RPC: {0} forbidden to access {1}", user.username, fullUrl)); - } httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN); return; } diff --git a/src/test/config/test-gitblit.properties b/src/test/config/test-gitblit.properties index 0d797b40..e636469e 100644 --- a/src/test/config/test-gitblit.properties +++ b/src/test/config/test-gitblit.properties @@ -6,13 +6,14 @@ git.defaultAccessRestriction = NONE git.repositoriesFolder = ${baseFolder}/git git.searchRepositoriesSubfolders = true git.enableGitServlet = true +git.daemonPort = 8300 groovy.scriptsFolder = src/main/distrib/data/groovy groovy.preReceiveScripts = blockpush groovy.postReceiveScripts = sendmail web.authenticateViewPages = false web.authenticateAdminPages = true web.allowCookieAuthentication = true -realm.userService = ${baseFolder}/src/test/config/test-users.conf +realm.userService = src/test/config/test-users.conf realm.passwordStorage = md5 realm.minPasswordLength = 5 web.siteName = Test Gitblit diff --git a/src/test/config/test-ui-users.conf b/src/test/config/test-ui-users.conf index 5bf35f3b..fb23f25d 100644 --- a/src/test/config/test-ui-users.conf +++ b/src/test/config/test-ui-users.conf @@ -4,19 +4,19 @@ role = "#admin" role = "#notfederated" [user "userthree"] - password = StoredInLDAP + password = "#externalAccount" cookie = d7d3894fc517612aa6c595555b6e1ab8e147e597 displayName = User Three emailAddress = userthree@gitblit.com role = "#admin" [user "userone"] - password = StoredInLDAP + password = "#externalAccount" cookie = c97cd38e50858cd0b389ec61b18fb9a89b4da54c displayName = User One emailAddress = User.One@gitblit.com role = "#admin" [user "usertwo"] - password = StoredInLDAP + password = "#externalAccount" cookie = 498ca9bd2841d39050fa45d1d737b9f9f767858d displayName = User Two emailAddress = usertwo@gitblit.com diff --git a/src/test/config/test-users.conf b/src/test/config/test-users.conf index 4f947872..b665fd5b 100644 --- a/src/test/config/test-users.conf +++ b/src/test/config/test-users.conf @@ -3,6 +3,10 @@ cookie = dd94709528bb1c83d08f3088d4043f4742891f4f role = "#admin" role = "#notfederated" +[user "sampleuser"] + password = sampleuser + cookie = 6e07ed42149fc166206319faffdfba2e2ec82e43 + role = "#none" [team "admins"] role = "#none" user = admin diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java index 57e94e51..7fc6fe0e 100644 --- a/src/test/java/com/gitblit/tests/GitBlitSuite.java +++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java @@ -65,6 +65,8 @@ import com.gitblit.utils.JGitUtils; ModelUtilsTest.class, JnaUtilsTest.class }) public class GitBlitSuite { + public static final File BASEFOLDER = new File("data"); + public static final File REPOSITORIES = new File("data/git"); public static final File SETTINGS = new File("src/test/config/test-gitblit.properties"); @@ -83,30 +85,35 @@ public class GitBlitSuite { private static AtomicBoolean started = new AtomicBoolean(false); - public static Repository getHelloworldRepository() throws Exception { + public static Repository getHelloworldRepository() { return getRepository("helloworld.git"); } - public static Repository getTicgitRepository() throws Exception { + public static Repository getTicgitRepository() { return getRepository("ticgit.git"); } - public static Repository getJGitRepository() throws Exception { + public static Repository getJGitRepository() { return getRepository("test/jgit.git"); } - public static Repository getAmbitionRepository() throws Exception { + public static Repository getAmbitionRepository() { return getRepository("test/ambition.git"); } - public static Repository getGitectiveRepository() throws Exception { + public static Repository getGitectiveRepository() { return getRepository("test/gitective.git"); } - private static Repository getRepository(String name) throws Exception { - File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED); - Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build(); - return repository; + private static Repository getRepository(String name) { + try { + File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED); + Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build(); + return repository; + } catch (Exception e) { + e.printStackTrace(); + } + return null; } public static boolean startGitblit() throws Exception { diff --git a/src/test/java/com/gitblit/tests/GitBlitTest.java b/src/test/java/com/gitblit/tests/GitBlitTest.java index 692afb76..d3913513 100644 --- a/src/test/java/com/gitblit/tests/GitBlitTest.java +++ b/src/test/java/com/gitblit/tests/GitBlitTest.java @@ -156,7 +156,7 @@ public class GitBlitTest extends GitblitUnitTest { assertEquals(5, settings().getInteger("realm.userService", 5)); assertTrue(settings().getBoolean("git.enableGitServlet", false)); - assertEquals(GitBlitSuite.USERSCONF.getAbsolutePath(), settings().getString("realm.userService", null)); + assertEquals("src/test/config/test-users.conf", settings().getString("realm.userService", null)); assertEquals(5, settings().getInteger("realm.minPasswordLength", 0)); List mdExtensions = settings().getStrings("web.markdownExtensions"); assertTrue(mdExtensions.size() > 0); diff --git a/src/test/java/com/gitblit/tests/GitServletTest.java b/src/test/java/com/gitblit/tests/GitServletTest.java index b197a915..bc392885 100644 --- a/src/test/java/com/gitblit/tests/GitServletTest.java +++ b/src/test/java/com/gitblit/tests/GitServletTest.java @@ -624,18 +624,28 @@ public class GitServletTest extends GitblitUnitTest { private void testRefChange(AccessPermission permission, Status expectedCreate, Status expectedDelete, Status expectedRewind) throws Exception { + final String originName = "ticgit.git"; + final String forkName = "refchecks/ticgit.git"; + final String workingCopy = "refchecks/ticgit-wc"; + + + // lower access restriction on origin repository + RepositoryModel origin = repositories().getRepositoryModel(originName); + origin.accessRestriction = AccessRestrictionType.NONE; + repositories().updateRepositoryModel(origin.name, origin, false); + 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"); + File refChecks = new File(GitBlitSuite.REPOSITORIES, forkName); if (refChecks.exists()) { FileUtils.delete(refChecks, FileUtils.RECURSIVE); } CloneCommand clone = Git.cloneRepository(); - clone.setURI(MessageFormat.format("{0}/ticgit.git", url)); + clone.setURI(url + "/" + originName); clone.setDirectory(refChecks); clone.setBare(true); clone.setCloneAllBranches(true); @@ -643,7 +653,7 @@ public class GitServletTest extends GitblitUnitTest { GitBlitSuite.close(clone.call()); // elevate repository to clone permission - RepositoryModel model = repositories().getRepositoryModel("refchecks/ticgit.git"); + RepositoryModel model = repositories().getRepositoryModel(forkName); switch (permission) { case VIEW: model.accessRestriction = AccessRestrictionType.CLONE; @@ -663,7 +673,7 @@ public class GitServletTest extends GitblitUnitTest { repositories().updateRepositoryModel(model.name, model, false); // clone temp bare repo to working copy - File local = new File(GitBlitSuite.REPOSITORIES, "refchecks/ticgit-wc"); + File local = new File(GitBlitSuite.REPOSITORIES, workingCopy); if (local.exists()) { FileUtils.delete(local, FileUtils.RECURSIVE); } diff --git a/src/test/java/com/gitblit/tests/GroovyScriptTest.java b/src/test/java/com/gitblit/tests/GroovyScriptTest.java index 1b5b0f39..ff40972f 100644 --- a/src/test/java/com/gitblit/tests/GroovyScriptTest.java +++ b/src/test/java/com/gitblit/tests/GroovyScriptTest.java @@ -338,6 +338,10 @@ public class GroovyScriptTest extends GitblitUnitTest { return dv; } + public int getInteger(String key, int defaultValue) { + return defaultValue; + } + public void sendMail(String subject, String message, Collection toAddresses) { messages.add(new MockMail(subject, message, toAddresses)); } diff --git a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java index 8ffe8469..319c09c1 100644 --- a/src/test/java/com/gitblit/tests/LuceneExecutorTest.java +++ b/src/test/java/com/gitblit/tests/LuceneExecutorTest.java @@ -48,8 +48,8 @@ public class LuceneExecutorTest extends GitblitUnitTest { private LuceneService newLuceneExecutor() { MemorySettings settings = new MemorySettings(); settings.put(Keys.git.repositoriesFolder, GitBlitSuite.REPOSITORIES); - RuntimeManager runtime = new RuntimeManager(settings); - UserManager users = new UserManager(runtime); + RuntimeManager runtime = new RuntimeManager(settings, GitBlitSuite.BASEFOLDER).start(); + UserManager users = new UserManager(runtime).start(); RepositoryManager repos = new RepositoryManager(runtime, users); return new LuceneService(settings, repos); } @@ -78,7 +78,7 @@ public class LuceneExecutorTest extends GitblitUnitTest { } @Test - public void testIndex() throws Exception { + public void testIndex() { // reindex helloworld Repository repository = GitBlitSuite.getHelloworldRepository(); RepositoryModel model = newRepositoryModel(repository); diff --git a/src/test/java/com/gitblit/tests/RpcTests.java b/src/test/java/com/gitblit/tests/RpcTests.java index e1ba9072..ced1a130 100644 --- a/src/test/java/com/gitblit/tests/RpcTests.java +++ b/src/test/java/com/gitblit/tests/RpcTests.java @@ -32,7 +32,7 @@ import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Constants.AuthorizationControl; import com.gitblit.Constants.PermissionType; import com.gitblit.Constants.RegistrantType; -import com.gitblit.GitBlitException.NotAllowedException; +import com.gitblit.GitBlitException.ForbiddenException; import com.gitblit.GitBlitException.UnauthorizedException; import com.gitblit.Keys; import com.gitblit.models.FederationModel; @@ -104,7 +104,7 @@ public class RpcTests extends GitblitUnitTest { UserModel user = null; try { user = RpcUtils.getUser("admin", url, null, null); - } catch (NotAllowedException e) { + } catch (ForbiddenException e) { } assertNull("Server allows anyone to get user!", user);