Skip to content

Commit d400a1d

Browse files
codexByron
authored andcommitted
test: exclude fixture paths from credential redaction assertions
The Ubuntu 3.14t CI job rejected correctly redacted clone output because its randomly generated `/tmp/.tmpg8ibob` fixture path contained `bob`. The credential assertions scanned the whole error and trace, so ordinary source and destination paths could masquerade as leaked credentials. Replace only the known fixture directory with `<fixture>` before checking the error and trace for credentials. Keep the exact redacted-option assertions and the credential checks outside that directory. Include `alice-bob-user-token` in the input paths so this false positive is covered deterministically, rather than depending on a random name. The Windows CLI and Gix jobs then failed all four trace subtests because `Repo._clone()` uses `Git.polish_url()` for the source path: the command and stderr contain forward slashes, while `str(directory)` contains backslashes. Copilot's review requested: "Remove both the native and POSIX spellings of the fixture directory before checking for credentials." Remove both exact spellings from the error and trace to address that feedback without weakening the credential checks elsewhere. Focused CLI and Gix runs each pass three redaction tests and four subtests. An assert-based check runs the new replacement loop against four actual Windows CLI/Gix CI failure messages: all pass, and a credential outside the fixture path remains visible. `ruff check`, `ruff format --check`, and `git diff --check` also pass. Windows execution remains for remote CI.
1 parent b03c608 commit d400a1d

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎test/test_git.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def test_it_redacts_authorization_extra_header_from_error(self):
518518
def test_clone_redacts_config_urls_from_trace_and_error(self, option, expected):
519519
for trace in (True, "full"):
520520
with self.subTest(trace=trace), writable_fixture("repo.sh", "empty") as temporary:
521-
directory = temporary.path()
521+
directory = temporary.path() / "alice-bob-user-token"
522522
with mock.patch.object(Git, "GIT_PYTHON_TRACE", trace):
523523
with self.assertLogs("git.cmd", level="INFO") as logs:
524524
with self.assertRaises(GitCommandError) as context:
@@ -532,6 +532,9 @@ def test_clone_redacts_config_urls_from_trace_and_error(self, option, expected):
532532
message = str(context.exception)
533533
assert logs is not None
534534
log_output = " ".join(logs.output)
535+
for path in (str(directory), directory.as_posix()):
536+
message = message.replace(path, "<fixture>")
537+
log_output = log_output.replace(path, "<fixture>")
535538
self.assertIn(expected, log_output)
536539
for credential in ("alice", "bob", "user", "token"):
537540
self.assertNotIn(credential, message)

0 commit comments

Comments
 (0)