From 4e7813c54c8d735a337d36d411cd7864d420b040 Mon Sep 17 00:00:00 2001 From: "Philip L. McMahon" Date: Sat, 4 Feb 2012 22:02:32 -0800 Subject: [PATCH] Add protect-refs unit tests for branch/tag creation/deletion. --- tests/com/gitblit/tests/GroovyScriptTest.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/com/gitblit/tests/GroovyScriptTest.java b/tests/com/gitblit/tests/GroovyScriptTest.java index b21c7e7d..5051100a 100644 --- a/tests/com/gitblit/tests/GroovyScriptTest.java +++ b/tests/com/gitblit/tests/GroovyScriptTest.java @@ -88,6 +88,97 @@ public class GroovyScriptTest { assertTrue(m.message.contains("BIT")); } + @Test + public void testProtectRefsCreateBranch() throws Exception { + MockGitblit gitblit = new MockGitblit(); + MockLogger logger = new MockLogger(); + List commands = new ArrayList(); + commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId + .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); + + RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); + + test("protect-refs.groovy", gitblit, logger, commands, repository); + } + + @Test + public void testProtectRefsCreateTag() throws Exception { + MockGitblit gitblit = new MockGitblit(); + MockLogger logger = new MockLogger(); + List commands = new ArrayList(); + commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId + .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0")); + + RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); + + test("protect-refs.groovy", gitblit, logger, commands, repository); + assertEquals(0, logger.messages.size()); + } + + @Test + public void testProtectRefsFastForward() throws Exception { + MockGitblit gitblit = new MockGitblit(); + MockLogger logger = new MockLogger(); + List commands = new ArrayList(); + commands.add(new ReceiveCommand(ObjectId + .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId + .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master")); + + RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); + + test("protect-refs.groovy", gitblit, logger, commands, repository); + assertEquals(0, logger.messages.size()); + } + + @Test + public void testProtectRefsDeleteMasterBranch() throws Exception { + MockGitblit gitblit = new MockGitblit(); + MockLogger logger = new MockLogger(); + List commands = new ArrayList(); + ReceiveCommand command = new ReceiveCommand(ObjectId + .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), + "refs/heads/master"); + commands.add(command); + + RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); + + test("protect-refs.groovy", gitblit, logger, commands, repository); + assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult()); + assertEquals(0, logger.messages.size()); + } + + @Test + public void testProtectRefsDeleteOtherBranch() throws Exception { + MockGitblit gitblit = new MockGitblit(); + MockLogger logger = new MockLogger(); + List commands = new ArrayList(); + commands.add(new ReceiveCommand(ObjectId + .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), + "refs/heads/other")); + + RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); + + test("protect-refs.groovy", gitblit, logger, commands, repository); + assertEquals(0, logger.messages.size()); + } + + @Test + public void testProtectRefsDeleteTag() throws Exception { + MockGitblit gitblit = new MockGitblit(); + MockLogger logger = new MockLogger(); + List commands = new ArrayList(); + ReceiveCommand command = new ReceiveCommand(ObjectId + .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), + "refs/tags/v1.0"); + commands.add(command); + + RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); + + test("protect-refs.groovy", gitblit, logger, commands, repository); + assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult()); + assertEquals(0, logger.messages.size()); + } + @Test public void testBlockPush() throws Exception { MockGitblit gitblit = new MockGitblit(); -- 2.39.5