summaryrefslogtreecommitdiff
path: root/test/test_util.py
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2021-03-19 19:09:44 +0800
committerGitHub <noreply@github.com>2021-03-19 19:09:44 +0800
commitd1297f65226e3bfdb31e224c514c362b304c904c (patch)
tree10e34ab1af6bdd7229b2a6da6436447ef4d236f3 /test/test_util.py
parentd906f31a283785e9864cb1eaf12a27faf4f72c42 (diff)
parentd283c83c43f5e52a1a14e55b35ffe85a780615d8 (diff)
downloadgitpython-d1297f65226e3bfdb31e224c514c362b304c904c.tar.gz
Merge pull request #1198 from RyaxTech/replace-password-in-uri-by-stars
Replace password in URI by stars if present to avoid leaking secrets in logs
Diffstat (limited to 'test/test_util.py')
-rw-r--r--test/test_util.py20
1 files changed, 19 insertions, 1 deletions
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)