Files
2026-12-02 16:58:44 +01:00

25 lines
809 B
Python

from pathlib import Path
import pytest
from appsec import PathTraversalError, redact_secrets, safe_join
def test_safe_join_allows_nested_and_blocks_traversal(tmp_path: Path) -> None:
ok = safe_join(tmp_path, "configs/app.yaml")
assert ok == (tmp_path / "configs" / "app.yaml").resolve()
with pytest.raises(PathTraversalError):
safe_join(tmp_path, "../../etc/passwd")
with pytest.raises(PathTraversalError):
safe_join(tmp_path, "/etc/passwd")
def test_redact_secrets_masks_credentials() -> None:
line = "auth failed header=Bearer s3cr3tTok3n user=admin password=hunter2 token=abc_123"
cleaned = redact_secrets(line)
assert "s3cr3tTok3n" not in cleaned
assert "hunter2" not in cleaned
assert "abc_123" not in cleaned
assert "user=admin" in cleaned