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)
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'))
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
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)
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)
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")}
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"))
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"), }
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'), ]
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)
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' ), ]
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'])
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)
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)
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
def setup_empty_repo(cls, backend): repo_path = get_new_dir(str(time.time())) repo = backend(repo_path, create=True) return repo
def test_create_bare_repo(self): repo = GitRepository(get_new_dir('bare-repo'), create=True, bare=True) assert repo._repo.bare
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
def test_create_bare_repo(self): repo = GitRepository(get_new_dir('bare-repo'), create=True, bare=True) self.assertTrue(repo._repo.bare)