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
6 changes: 4 additions & 2 deletions repoReleaseAudit/repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import argparse
import json
import re
import stat
import subprocess
import sys
from dataclasses import asdict, dataclass
Expand Down Expand Up @@ -136,9 +137,10 @@ def audit(root: Path, max_file_mb: float = 50.0, strict: bool = False) -> dict[s
github_limit = 100 * 1024 * 1024
total_bytes = 0
for relative, path in files:
is_symlink = modes.get(relative) == "120000"
try:
size = path.lstat().st_size if is_symlink else path.stat().st_size
metadata = path.lstat()
is_symlink = modes.get(relative) == "120000" or stat.S_ISLNK(metadata.st_mode)
size = metadata.st_size
except OSError:
findings.append(Finding("error", "missing-tracked-file", relative))
continue
Expand Down
42 changes: 42 additions & 0 deletions repoReleaseAudit/tests/test_repo_release_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,45 @@ def test_oversized_text_is_reported_as_not_scanned(tmp_path: Path) -> None:
git(root, "add", "large.txt")
result = audit_module.audit(root)
assert any(item["code"] == "text-too-large-to-scan" and item["path"] == "large.txt" and item["level"] == "error" for item in result["findings"])


def test_worktree_symlink_is_not_scanned_when_index_has_regular_file(tmp_path: Path, monkeypatch) -> None:
import stat
from types import SimpleNamespace

root = tmp_path / "repo"
init_repo(root)
target = root / "settings.txt"
original_lstat = Path.lstat
original_read = Path.read_text

def link_lstat(path: Path):
if path == target:
return SimpleNamespace(st_mode=stat.S_IFLNK, st_size=1)
return original_lstat(path)

def no_link_reads(path: Path, *args, **kwargs):
assert path != target
return original_read(path, *args, **kwargs)

monkeypatch.setattr(Path, "lstat", link_lstat)
monkeypatch.setattr(Path, "read_text", no_link_reads)
result = audit_module.audit(root)
assert any(item["code"] == "symlink" and item["path"] == "settings.txt" for item in result["findings"])


def test_unstaged_symlink_does_not_read_outside_target(tmp_path: Path) -> None:
root = tmp_path / "repo"
init_repo(root)
outside = tmp_path / "outside.txt"
outside.write_text("ghp_" + "b" * 24, encoding="utf-8")
target = root / "settings.txt"
target.unlink()
try:
target.symlink_to(outside)
except OSError as error:
import pytest
pytest.skip(f"symlinks unavailable: {error}")
result = audit_module.audit(root)
assert any(item["code"] == "symlink" and item["path"] == "settings.txt" for item in result["findings"])
assert not any(item["code"] == "secret-pattern" and item["path"] == "settings.txt" for item in result["findings"])
Loading