Merge pull request #2188 from pick7/codex/redact-http-extraheader · gitpython-developers/GitPython@951cc44 · GitHub
Skip to content

Commit 951cc44

Browse files
authored
Merge pull request #2188 from pick7/codex/redact-http-extraheader
Redact Authorization extra headers from command errors
2 parents 2e5b13f + 5a53ae6 commit 951cc44

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

git/util.py

Lines changed: 11 additions & 2 deletions

test/test_git.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,24 @@ def test_it_raises_proper_exception_with_output_stream(self):
419419
with self.assertRaises(GitCommandError):
420420
self.git.checkout("non-existent-branch", output_stream=tmp_file)
421421

422+
def test_it_redacts_authorization_extra_header_from_error(self):
423+
token = "fake-token-1234"
424+
command = [
425+
"git",
426+
"-c",
427+
"http.extraHeader=Authorization: Bearer %s" % token,
428+
"rev-parse",
429+
"--verify",
430+
"refs/does-not-exist",
431+
]
432+
433+
with self.assertRaises(GitCommandError) as context:
434+
self.git.execute(command)
435+
436+
message = str(context.exception)
437+
self.assertNotIn(token, message)
438+
self.assertIn("http.extraHeader=Authorization: *****", message)
439+
422440
def test_it_accepts_environment_variables(self):
423441
filename = fixture_path("ls_tree_empty")
424442
with open(filename, "r") as fh:

test/test_util.py

Lines changed: 6 additions & 0 deletions

0 commit comments

Comments
 (0)