Redact Authorization extra headers from command errors by pick7 · Pull Request #2188 · gitpython-developers/GitPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions git/util.py
18 changes: 18 additions & 0 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,24 @@ def test_it_raises_proper_exception_with_output_stream(self):
with self.assertRaises(GitCommandError):
self.git.checkout("non-existent-branch", output_stream=tmp_file)

def test_it_redacts_authorization_extra_header_from_error(self):
token = "fake-token-1234"
command = [
"git",
"-c",
"http.extraHeader=Authorization: Bearer %s" % token,
"rev-parse",
"--verify",
"refs/does-not-exist",
]

with self.assertRaises(GitCommandError) as context:
self.git.execute(command)

message = str(context.exception)
self.assertNotIn(token, message)
self.assertIn("http.extraHeader=Authorization: *****", message)

def test_it_accepts_environment_variables(self):
filename = fixture_path("ls_tree_empty")
with open(filename, "r") as fh:
Expand Down
6 changes: 6 additions & 0 deletions test/test_util.py
Loading