assertTrue(m.message.contains("BIT"));\r
}\r
\r
+ @Test\r
+ public void testProtectRefsCreateBranch() throws Exception {\r
+ MockGitblit gitblit = new MockGitblit();\r
+ MockLogger logger = new MockLogger();\r
+ List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+ commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId\r
+ .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
+ \r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); \r
+\r
+ test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+ }\r
+ \r
+ @Test\r
+ public void testProtectRefsCreateTag() throws Exception {\r
+ MockGitblit gitblit = new MockGitblit();\r
+ MockLogger logger = new MockLogger();\r
+ List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+ commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId\r
+ .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0"));\r
+ \r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); \r
+\r
+ test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+ assertEquals(0, logger.messages.size());\r
+ }\r
+ \r
+ @Test\r
+ public void testProtectRefsFastForward() throws Exception {\r
+ MockGitblit gitblit = new MockGitblit();\r
+ MockLogger logger = new MockLogger();\r
+ List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+ commands.add(new ReceiveCommand(ObjectId\r
+ .fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
+ .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
+ \r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); \r
+\r
+ test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+ assertEquals(0, logger.messages.size());\r
+ }\r
+ \r
+ @Test\r
+ public void testProtectRefsDeleteMasterBranch() throws Exception {\r
+ MockGitblit gitblit = new MockGitblit();\r
+ MockLogger logger = new MockLogger();\r
+ List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+ ReceiveCommand command = new ReceiveCommand(ObjectId\r
+ .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),\r
+ "refs/heads/master");\r
+ commands.add(command);\r
+ \r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); \r
+\r
+ test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+ assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());\r
+ assertEquals(0, logger.messages.size());\r
+ }\r
+ \r
+ @Test\r
+ public void testProtectRefsDeleteOtherBranch() throws Exception {\r
+ MockGitblit gitblit = new MockGitblit();\r
+ MockLogger logger = new MockLogger();\r
+ List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+ commands.add(new ReceiveCommand(ObjectId\r
+ .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),\r
+ "refs/heads/other"));\r
+ \r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); \r
+\r
+ test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+ assertEquals(0, logger.messages.size());\r
+ }\r
+ \r
+ @Test\r
+ public void testProtectRefsDeleteTag() throws Exception {\r
+ MockGitblit gitblit = new MockGitblit();\r
+ MockLogger logger = new MockLogger();\r
+ List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();\r
+ ReceiveCommand command = new ReceiveCommand(ObjectId\r
+ .fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),\r
+ "refs/tags/v1.0");\r
+ commands.add(command);\r
+ \r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date()); \r
+\r
+ test("protect-refs.groovy", gitblit, logger, commands, repository);\r
+ assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());\r
+ assertEquals(0, logger.messages.size());\r
+ }\r
+ \r
@Test\r
public void testBlockPush() throws Exception {\r
MockGitblit gitblit = new MockGitblit();\r