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
1 change: 1 addition & 0 deletions repoReleaseAudit/repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def scan_text(path: Path, relative: str, findings: list[Finding]) -> None:
try:
text = path.read_text(encoding="utf-8")
except (OSError, UnicodeDecodeError):
findings.append(Finding("error", "unreadable-text", relative))
return
for line_number, line in enumerate(text.splitlines(), start=1):
for name, pattern in SECRET_PATTERNS.items():
Expand Down
26 changes: 26 additions & 0 deletions repoReleaseAudit/tests/test_repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,29 @@ def test_dangling_tracked_symlink_is_not_reported_missing(tmp_path: Path) -> Non

assert any(item["code"] == "symlink" and item["path"] == "dangling.txt" for item in findings)
assert not any(item["code"] == "missing-tracked-file" and item["path"] == "dangling.txt" for item in findings)


def test_unreadable_text_is_reported_without_exposing_content(tmp_path: Path, monkeypatch) -> None:
root = tmp_path / "repo"
init_repo(root)
target = root / "settings.txt"
original = Path.read_text

def deny_target(path: Path, *args, **kwargs):
if path == target:
raise PermissionError("private details")
return original(path, *args, **kwargs)

monkeypatch.setattr(Path, "read_text", deny_target)
result = audit_module.audit(root)
assert any(item["code"] == "unreadable-text" and item["path"] == "settings.txt" for item in result["findings"])
assert "private details" not in audit_module.render_text(result)


def test_invalid_utf8_text_is_not_silently_skipped(tmp_path: Path) -> None:
root = tmp_path / "repo"
init_repo(root)
(root / "invalid.txt").write_bytes(b"\xff\xfe")
git(root, "add", "invalid.txt")
result = audit_module.audit(root)
assert any(item["code"] == "unreadable-text" and item["path"] == "invalid.txt" for item in result["findings"])
Loading