test(zip): add regression tests for upload zip validation#42
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
anvie
left a comment
There was a problem hiding this comment.
Thank you for the PR! This is a solid first-pass regression suite.
The six tests lock in the three most critical security checks: path traversal (../), absolute paths (/etc/passwd), and extension whitelisting (.exe blocked). The _write_zip helper keeps things clean, and setUp/tearDown with tempfile.mkdtemp() means no temp artifacts leak.
Good coverage for the happy path, empty zip, and non-zip file checks too. The assertions on error message substrings are pragmatic — more robust than exact matching.
Gaps worth noting (all acknowledged in your PR description):
- No corrupt-zip test (
BadZipFile) — would be easy to add with a truncated file - No Windows-style absolute path test (
\\evil\\file) — the validator explicitly handles it - Size-limit tests (50 MB upload, 500 entries, 200 MB uncompressed) are understandably out of scope
One minor nit: import shutil inside tearDown is functional but a bit unusual — moving it to module level would be cleaner.
Full review report saved at artifacts/pr42-review.md.
Best,
Richard
Robin Syihab's agent.
- _generate_pair_code(): static method, 8-char uppercase+digits - create_pending_approval(): insert record - get_pending_approvals(): list non-expired by channel - get_pending_approval_by_code(): lookup non-expired by code - approve_pending(): add user to allowed_users in config, delete record - reject_pending(): delete record - cleanup_expired_approvals(): bulk delete expired - is_user_allowed(): check allowed_users in restricted mode
Bcakground
Plugin and skill uploads go through
backend/zip_validator.validate_upload_zip()before extraction. The checks are non-trivial: compressed size limits, per-entry caps, path traversal, extension whitelist, and corrupt-archive handling. Until now that module had no dedicated unit tests, so a refactor or a well-meaning one-line change could weaken install-time defenses without anyone noticing in CI.This PR adds a focused regression suite. It does not change production code.
Cases covered
Each test builds small archives under a temp directory and calls
validate_upload_zip()directly.skill.json+.py)../in entry name/etc/passwd).exe)Together these lock in the behaviors plugin/skill routes already rely on. They are cheap to run and fail with clear assertion messages on the error string returned by the validator.
What I don't Fix
zip_validator.pyare unchanged.How to verify
python -m pytest unit_tests/test_zip_validator.py -q