From 6c5511020457c39961d069071ac60f7140ec724f Mon Sep 17 00:00:00 2001 From: Lukasz Jader <ljaderdev@gmail.com> Date: Wed, 19 Sep 2012 16:24:10 -0400 Subject: [PATCH] Update polish translation of EmptyRepositoryPage --- tests/com/gitblit/tests/GitServletTest.java | 65 +++++++++++++++++++++++++++++++- 1 files changed, 62 insertions(+), 3 deletions(-) diff --git a/tests/com/gitblit/tests/GitServletTest.java b/tests/com/gitblit/tests/GitServletTest.java index 2f9a9c4..bdbb2a5 100644 --- a/tests/com/gitblit/tests/GitServletTest.java +++ b/tests/com/gitblit/tests/GitServletTest.java @@ -21,8 +21,10 @@ import org.junit.Test; import com.gitblit.Constants.AccessRestrictionType; +import com.gitblit.Constants.AuthorizationControl; import com.gitblit.GitBlit; import com.gitblit.models.RepositoryModel; +import com.gitblit.models.UserModel; public class GitServletTest { @@ -42,7 +44,6 @@ @BeforeClass public static void startGitblit() throws Exception { - deleteWorkingFolders(); started.set(GitBlitSuite.startGitblit()); } @@ -50,11 +51,11 @@ public static void stopGitblit() throws Exception { if (started.get()) { GitBlitSuite.stopGitblit(); + deleteWorkingFolders(); } - deleteWorkingFolders(); } - private static void deleteWorkingFolders() throws Exception { + public static void deleteWorkingFolders() throws Exception { if (ticgitFolder.exists()) { FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE); } @@ -109,6 +110,64 @@ assertFalse("Bogus login cloned a repository?!", cloned); } + + @Test + public void testUnauthorizedLoginClone() throws Exception { + // restrict repository access + RepositoryModel model = GitBlit.self().getRepositoryModel("ticgit.git"); + model.accessRestriction = AccessRestrictionType.CLONE; + model.authorizationControl = AuthorizationControl.NAMED; + UserModel user = new UserModel("james"); + user.password = "james"; + GitBlit.self().updateUserModel(user.username, user, true); + GitBlit.self().updateRepositoryModel(model.name, model, false); + + FileUtils.delete(ticgit2Folder, FileUtils.RECURSIVE); + + // delete any existing working folder + boolean cloned = false; + try { + CloneCommand clone = Git.cloneRepository(); + clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url)); + clone.setDirectory(ticgit2Folder); + clone.setBare(false); + clone.setCloneAllBranches(true); + clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user.username, user.password)); + close(clone.call()); + cloned = true; + } catch (Exception e) { + // swallow the exception which we expect + } + + 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(); + clone.setURI(MessageFormat.format("{0}/git/ticgit.git", url)); + clone.setDirectory(ticgit2Folder); + clone.setBare(false); + clone.setCloneAllBranches(true); + clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user.username, user.password)); + close(clone.call()); + 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); + GitBlit.self().deleteUser(user.username); + } @Test public void testAnonymousPush() throws Exception { -- Gitblit v1.9.1