| | |
| | |
|
| | | /**
|
| | | * Test class for Groovy scripts. Mostly this is to facilitate development.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public class GroovyScriptTest {
|
| | |
|
| | |
| | | assertEquals(5, m.toAddresses.size());
|
| | | assertTrue(m.message.contains("BIT"));
|
| | | }
|
| | | |
| | |
|
| | | @Test
|
| | | public void testProtectRefsCreateBranch() throws Exception {
|
| | | MockGitblit gitblit = new MockGitblit();
|
| | |
| | | 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();
|
| | |
| | | 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();
|
| | |
| | | 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();
|
| | |
| | | .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();
|
| | |
| | | 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();
|
| | |
| | | .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();
|
| | |
| | | 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);
|
| | |
| | | assertTrue(e.getMessage().contains("failed"));
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | @Test
|
| | | public void testClientLogging() throws Exception {
|
| | | MockGitblit gitblit = new MockGitblit();
|
| | |
| | | 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();
|
| | |
| | | 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)) {
|