Ejemplo n.º 1
0
    def test_git_cmd_injection(self):
        repo_inject_path = TEST_GIT_REPO + '; echo "Cake";'
        with self.assertRaises(urllib2.URLError):
            # Should fail because URL will contain the parts after ; too
            urlerror_fail_repo = GitRepository(get_new_dir('injection-repo'), src_url=repo_inject_path, update_after_clone=True, create=True)

        with self.assertRaises(RepositoryError):
            # Should fail on direct clone call, which as of this writing does not happen outside of class
            clone_fail_repo = GitRepository(get_new_dir('injection-repo'), create=True)
            clone_fail_repo.clone(repo_inject_path, update_after_clone=True,)

        # Verify correct quoting of evil characters that should work on posix file systems
        tricky_path = get_new_dir("tricky-path-repo-$'\"`")
        successfully_cloned = GitRepository(tricky_path, src_url=TEST_GIT_REPO, update_after_clone=True, create=True)
        # Repo should have been created
        self.assertFalse(successfully_cloned._repo.bare)

        tricky_path_2 = get_new_dir("tricky-path-2-repo-$'\"`")
        successfully_cloned2 = GitRepository(tricky_path_2, src_url=tricky_path, bare=True, create=True)
        # Repo should have been created and thus used correct quoting for clone
        self.assertTrue(successfully_cloned2._repo.bare)

        # Should pass because URL has been properly quoted
        successfully_cloned.pull(tricky_path_2)
        successfully_cloned2.fetch(tricky_path)
Ejemplo n.º 2
0
    def test_get_changesets_on_empty_repo_raises_EmptyRepository_error(self):
        Backend = self.get_backend()
        repo_path = get_new_dir(str(time.time()))
        repo = Backend(repo_path, create=True)

        with self.assertRaises(EmptyRepositoryError):
            list(repo.get_changesets(start='foobar'))
Ejemplo n.º 3
0
 def get_new_repo_path(self):
     """
     Returns newly created repository's directory.
     """
     backend = self.get_backend()
     key = '%s-%s' % (backend.alias, str(time.time()))
     repo_path = get_new_dir(key)
     return repo_path
Ejemplo n.º 4
0
 def get_new_repo_path(self):
     """
     Returns newly created repository's directory.
     """
     backend = self.get_backend()
     key = '%s-%s' % (backend.alias, str(time.time()))
     repo_path = get_new_dir(key)
     return repo_path
Ejemplo n.º 5
0
    def test_repo_clone_with_spaces_in_path(self):
        repo_path = get_new_dir("path with spaces")
        successfully_cloned = GitRepository(repo_path, src_url=TEST_GIT_REPO, update_after_clone=True, create=True)
        # Repo should have been created
        self.assertFalse(successfully_cloned._repo.bare)

        successfully_cloned.pull(TEST_GIT_REPO)
        self.repo.fetch(repo_path)
Ejemplo n.º 6
0
    def test_repo_clone_with_spaces_in_path(self):
        repo_path = get_new_dir("path with spaces")
        successfully_cloned = GitRepository(repo_path, src_url=TEST_GIT_REPO, update_after_clone=True, create=True)
        # Repo should have been created
        assert not successfully_cloned._repo.bare

        successfully_cloned.pull(TEST_GIT_REPO)
        self.repo.fetch(repo_path)
Ejemplo n.º 7
0
    def setUp(self):
        # For each run we want a fresh repo.
        self.repo_directory = get_new_dir("githookrepo")
        self.repo = GitRepository(self.repo_directory, create=True)

        # Create a dictionary where keys are hook names, and values are paths to
        # them. Deduplicates code in tests a bit.
        self.hook_directory = self.repo.get_hook_location()
        self.kallithea_hooks = {h: os.path.join(self.hook_directory, h) for h in ("pre-receive", "post-receive")}
Ejemplo n.º 8
0
    def setUp(self):
        # For each run we want a fresh repo.
        self.repo_directory = get_new_dir("githookrepo")
        self.repo = GitRepository(self.repo_directory, create=True)

        # Create a dictionary where keys are hook names, and values are paths to
        # them. Deduplicates code in tests a bit.
        self.hook_directory = self.repo.get_hook_location()
        self.kallithea_hooks = dict((h, os.path.join(self.hook_directory, h)) for h in ("pre-receive", "post-receive"))
Ejemplo n.º 9
0
    def setup_method(self):
        # For each run we want a fresh repo.
        self.repo_directory = get_new_dir("githookrepo")
        self.repo = GitRepository(self.repo_directory, create=True)

        # Create a dictionary where keys are hook names, and values are paths to
        # them in the non-bare repo. Deduplicates code in tests a bit.
        self.kallithea_hooks = {
            "pre-receive": os.path.join(self.repo.path, '.git', 'hooks', "pre-receive"),
            "post-receive": os.path.join(self.repo.path, '.git', 'hooks', "post-receive"),
        }
Ejemplo n.º 10
0
 def setUp(self):
     Backend = self.get_backend()
     self.repo_path = get_new_dir(str(time.time()))
     self.repo = Backend(self.repo_path, create=True)
     self.imc = self.repo.in_memory_changeset
     self.nodes = [
         FileNode('foobar', content='Foo & bar'),
         FileNode('foobar2', content='Foo & bar, doubled!'),
         FileNode('foo bar with spaces', content=''),
         FileNode('foo/bar/baz', content='Inside'),
         FileNode('foo/bar/file.bin', content='\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00;\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'),
     ]
Ejemplo n.º 11
0
    def test_git_cmd_injection(self):
        repo_inject_path = 'file:/%s; echo "Cake";' % TEST_GIT_REPO
        with pytest.raises(RepositoryError):
            # Should fail because URL will contain the parts after ; too
            GitRepository(get_new_dir('injection-repo'), src_url=repo_inject_path, update_after_clone=True, create=True)

        with pytest.raises(RepositoryError):
            # Should fail on direct clone call, which as of this writing does not happen outside of class
            clone_fail_repo = GitRepository(get_new_dir('injection-repo'), create=True)
            clone_fail_repo.clone(repo_inject_path, update_after_clone=True,)

        # Verify correct quoting of evil characters that should work on posix file systems
        if sys.platform == 'win32':
            # windows does not allow '"' in dir names
            # and some versions of the git client don't like ` and '
            tricky_path = get_new_dir("tricky-path-repo-$")
        else:
            tricky_path = get_new_dir("tricky-path-repo-$'\"`")
        successfully_cloned = GitRepository(tricky_path, src_url=TEST_GIT_REPO, update_after_clone=True, create=True)
        # Repo should have been created
        assert not successfully_cloned._repo.bare

        if sys.platform == 'win32':
            # windows does not allow '"' in dir names
            # and some versions of the git client don't like ` and '
            tricky_path_2 = get_new_dir("tricky-path-2-repo-$")
        else:
            tricky_path_2 = get_new_dir("tricky-path-2-repo-$'\"`")
        successfully_cloned2 = GitRepository(tricky_path_2, src_url=tricky_path, bare=True, create=True)
        # Repo should have been created and thus used correct quoting for clone
        assert successfully_cloned2._repo.bare

        # Should pass because URL has been properly quoted
        successfully_cloned.pull(tricky_path_2)
        successfully_cloned2.fetch(tricky_path)
Ejemplo n.º 12
0
 def setUp(self):
     Backend = self.get_backend()
     self.repo_path = get_new_dir(str(time.time()))
     self.repo = Backend(self.repo_path, create=True)
     self.imc = self.repo.in_memory_changeset
     self.nodes = [
         FileNode('foobar', content='Foo & bar'),
         FileNode('foobar2', content='Foo & bar, doubled!'),
         FileNode('foo bar with spaces', content=''),
         FileNode('foo/bar/baz', content='Inside'),
         FileNode(
             'foo/bar/file.bin',
             content=
             '\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00;\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1a\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'
         ),
     ]
Ejemplo n.º 13
0
    def setUpClass(cls):
        Backend = cls.get_backend()
        cls.backend_class = Backend
        cls.repo_path = get_new_dir(str(time.time()))
        cls.repo = Backend(cls.repo_path, create=True)
        cls.imc = cls.repo.in_memory_changeset
        cls.default_branch = cls.repo.DEFAULT_BRANCH_NAME

        for commit in cls._get_commits():
            for node in commit.get('added', []):
                cls.imc.add(FileNode(node.path, content=node.content))
            for node in commit.get('changed', []):
                cls.imc.change(FileNode(node.path, content=node.content))
            for node in commit.get('removed', []):
                cls.imc.remove(FileNode(node.path))

            cls.tip = cls.imc.commit(message=unicode(commit['message']),
                                     author=unicode(commit['author']),
                                     date=commit['date'])
Ejemplo n.º 14
0
    def setUpClass(cls):
        Backend = cls.get_backend()
        cls.backend_class = Backend
        cls.repo_path = get_new_dir(str(time.time()))
        cls.repo = Backend(cls.repo_path, create=True)
        cls.imc = cls.repo.in_memory_changeset
        cls.default_branch = cls.repo.DEFAULT_BRANCH_NAME

        for commit in cls._get_commits():
            for node in commit.get('added', []):
                cls.imc.add(FileNode(node.path, content=node.content))
            for node in commit.get('changed', []):
                cls.imc.change(FileNode(node.path, content=node.content))
            for node in commit.get('removed', []):
                cls.imc.remove(FileNode(node.path))

            cls.tip = cls.imc.commit(message=unicode(commit['message']),
                                     author=unicode(commit['author']),
                                     date=commit['date'])
Ejemplo n.º 15
0
 def test_create_repo_is_not_bare_by_default(self):
     repo = GitRepository(get_new_dir('not-bare-by-default'), create=True)
     self.assertFalse(repo._repo.bare)
Ejemplo n.º 16
0
 def test_repo_create_with_spaces_in_path(self):
     repo_path = get_new_dir("path with spaces")
     repo = GitRepository(repo_path, src_url=None, bare=True, create=True)
     # Repo should have been created
     self.assertTrue(repo._repo.bare)
Ejemplo n.º 17
0
 def test_repo_create_with_spaces_in_path(self):
     repo_path = get_new_dir("path with spaces")
     repo = GitRepository(repo_path, src_url=None, bare=True, create=True)
     # Repo should have been created
     assert repo._repo.bare
Ejemplo n.º 18
0
 def setup_empty_repo(cls, backend):
     repo_path = get_new_dir(str(time.time()))
     repo = backend(repo_path, create=True)
     return repo
Ejemplo n.º 19
0
 def test_create_bare_repo(self):
     repo = GitRepository(get_new_dir('bare-repo'), create=True, bare=True)
     assert repo._repo.bare
Ejemplo n.º 20
0
 def test_create_repo_is_not_bare_by_default(self):
     repo = GitRepository(get_new_dir('not-bare-by-default'), create=True)
     assert not repo._repo.bare
Ejemplo n.º 21
0
 def test_create_bare_repo(self):
     repo = GitRepository(get_new_dir('bare-repo'), create=True, bare=True)
     self.assertTrue(repo._repo.bare)