diff options
author | yobmod <yobmod@gmail.com> | 2021-05-03 15:59:07 +0100 |
---|---|---|
committer | yobmod <yobmod@gmail.com> | 2021-05-03 15:59:07 +0100 |
commit | 6752fad0e93d1d2747f56be30a52fea212bd15d6 (patch) | |
tree | a0618d53d06f35d7326fcacdcaf1832d7ab55b8c /test | |
parent | 2fd9f6ee5c8b4ae4e01a40dc398e2768d838210d (diff) | |
download | gitpython-6752fad0e93d1d2747f56be30a52fea212bd15d6.tar.gz |
add initial types to remote.py
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/diff_file_with_colon | bin | 0 -> 351 bytes | |||
-rw-r--r-- | test/test_clone.py | 32 | ||||
-rw-r--r-- | test/test_diff.py | 7 | ||||
-rw-r--r-- | test/test_repo.py | 15 | ||||
-rw-r--r-- | test/test_util.py | 20 |
5 files changed, 73 insertions, 1 deletions
diff --git a/test/fixtures/diff_file_with_colon b/test/fixtures/diff_file_with_colon Binary files differnew file mode 100644 index 00000000..4058b171 --- /dev/null +++ b/test/fixtures/diff_file_with_colon diff --git a/test/test_clone.py b/test/test_clone.py new file mode 100644 index 00000000..e9f6714d --- /dev/null +++ b/test/test_clone.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +from pathlib import Path +import re + +import git + +from .lib import ( + TestBase, + with_rw_directory, +) + + +class TestClone(TestBase): + @with_rw_directory + def test_checkout_in_non_empty_dir(self, rw_dir): + non_empty_dir = Path(rw_dir) + garbage_file = non_empty_dir / 'not-empty' + garbage_file.write_text('Garbage!') + + # Verify that cloning into the non-empty dir fails while complaining about + # the target directory not being empty/non-existent + try: + self.rorepo.clone(non_empty_dir) + except git.GitCommandError as exc: + self.assertTrue(exc.stderr, "GitCommandError's 'stderr' is unexpectedly empty") + expr = re.compile(r'(?is).*\bfatal:\s+destination\s+path\b.*\bexists\b.*\bnot\b.*\bempty\s+directory\b') + self.assertTrue(expr.search(exc.stderr), '"%s" does not match "%s"' % (expr.pattern, exc.stderr)) + else: + self.fail("GitCommandError not raised") diff --git a/test/test_diff.py b/test/test_diff.py index c6c9b67a..9b20893a 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -7,6 +7,7 @@ import ddt import shutil import tempfile +import unittest from git import ( Repo, GitCommandError, @@ -220,6 +221,12 @@ class TestDiff(TestBase): self.assertIsNotNone(res[0].deleted_file) self.assertIsNone(res[0].b_path,) + @unittest.skip("This currently fails and would need someone to improve diff parsing") + def test_diff_file_with_colon(self): + output = fixture('diff_file_with_colon') + res = [] + Diff._handle_diff_line(output, None, res) + def test_diff_initial_commit(self): initial_commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') diff --git a/test/test_repo.py b/test/test_repo.py index d5ea8664..8dc17833 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -238,6 +238,21 @@ class TestRepo(TestBase): except UnicodeEncodeError: self.fail('Raised UnicodeEncodeError') + @with_rw_directory + def test_leaking_password_in_clone_logs(self, rw_dir): + password = "fakepassword1234" + try: + Repo.clone_from( + url="https://fakeuser:{}@fakerepo.example.com/testrepo".format( + password), + to_path=rw_dir) + except GitCommandError as err: + assert password not in str(err), "The error message '%s' should not contain the password" % err + # Working example from a blank private project + Repo.clone_from( + url="https://gitlab+deploy-token-392045:mLWhVus7bjLsy8xj8q2V@gitlab.com/mercierm/test_git_python", + to_path=rw_dir) + @with_rw_repo('HEAD') def test_max_chunk_size(self, repo): class TestOutputStream(TestBase): diff --git a/test/test_util.py b/test/test_util.py index 5eba6c50..ddc5f628 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -30,7 +30,8 @@ from git.util import ( Actor, IterableList, cygpath, - decygpath + decygpath, + remove_password_if_present, ) @@ -322,3 +323,20 @@ class TestUtils(TestBase): t2 = pickle.loads(pickle.dumps(t1)) self.assertEqual(t1._offset, t2._offset) self.assertEqual(t1._name, t2._name) + + def test_remove_password_from_command_line(self): + password = "fakepassword1234" + url_with_pass = "https://fakeuser:{}@fakerepo.example.com/testrepo".format(password) + url_without_pass = "https://fakerepo.example.com/testrepo" + + cmd_1 = ["git", "clone", "-v", url_with_pass] + cmd_2 = ["git", "clone", "-v", url_without_pass] + cmd_3 = ["no", "url", "in", "this", "one"] + + redacted_cmd_1 = remove_password_if_present(cmd_1) + assert password not in " ".join(redacted_cmd_1) + # Check that we use a copy + assert cmd_1 is not redacted_cmd_1 + assert password in " ".join(cmd_1) + assert cmd_2 == remove_password_if_present(cmd_2) + assert cmd_3 == remove_password_if_present(cmd_3) |