Skip to content

Commit 92d97dc

Browse files
committed
test: tighten pickle safe builtin assertions
1 parent 9e86dc9 commit 92d97dc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/scanners/test_pickle_scanner.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,30 @@ def test_safe_builtins_remain_allowlisted(self) -> None:
701701
result = self._scan_bytes(self._craft_global_reduce_pickle("builtins", safe_builtin))
702702

703703
assert result.success
704+
assert not result.has_warnings
704705
assert not result.has_errors, (
705706
f"Expected builtins.{safe_builtin} to remain non-failing, got: {[i.message for i in result.issues]}"
706707
)
708+
passed_global_checks = [
709+
check
710+
for check in result.checks
711+
if check.name == "Global Module Reference Check" and check.status == CheckStatus.PASSED
712+
]
713+
assert any(f"builtins.{safe_builtin}" in check.message for check in passed_global_checks), (
714+
f"Expected passed Global Module Reference Check for builtins.{safe_builtin}, "
715+
f"got: {[check.message for check in passed_global_checks]}"
716+
)
717+
passed_reduce_checks = [
718+
check
719+
for check in result.checks
720+
if check.name == "REDUCE Opcode Safety Check" and check.status == CheckStatus.PASSED
721+
]
722+
assert any(
723+
check.details.get("associated_global") == f"builtins.{safe_builtin}" for check in passed_reduce_checks
724+
), (
725+
f"Expected passed REDUCE check for builtins.{safe_builtin}, "
726+
f"got: {[check.details for check in passed_reduce_checks]}"
727+
)
707728

708729
def test_dangerous_builtins_still_fail(self) -> None:
709730
"""Dangerous builtins must continue to fail after allowlist tightening."""

0 commit comments

Comments
 (0)