feat(thumb-backfill): _thumb_is_valid helper — JPEG/PNG magic-byte check on the on-disk thumbnail file
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Thumbnail backfill: _thumb_is_valid helper + backfill_thumbnails planner."""
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.app.tasks.thumbnail import _thumb_is_valid
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
def test_thumb_is_valid_jpeg(tmp_path):
|
||||
p = tmp_path / "good.jpg"
|
||||
p.write_bytes(b"\xff\xd8\xff\xe0" + b"\x00" * 100)
|
||||
assert _thumb_is_valid(p) is True
|
||||
|
||||
|
||||
def test_thumb_is_valid_png(tmp_path):
|
||||
p = tmp_path / "good.png"
|
||||
p.write_bytes(b"\x89PNG\r\n\x1a\n" + b"\x00" * 100)
|
||||
assert _thumb_is_valid(p) is True
|
||||
|
||||
|
||||
def test_thumb_is_valid_too_short(tmp_path):
|
||||
p = tmp_path / "tiny"
|
||||
p.write_bytes(b"\xff\xd8")
|
||||
assert _thumb_is_valid(p) is False
|
||||
|
||||
|
||||
def test_thumb_is_valid_wrong_magic(tmp_path):
|
||||
p = tmp_path / "garbage"
|
||||
p.write_bytes(b"\x00" * 12)
|
||||
assert _thumb_is_valid(p) is False
|
||||
|
||||
|
||||
def test_thumb_is_valid_missing_file(tmp_path):
|
||||
assert _thumb_is_valid(tmp_path / "nope") is False
|
||||
Reference in New Issue
Block a user