feat(lab4): implement S3 attachments and image validation

This commit is contained in:
Otto
2026-11-03 00:59:46 +03:00
parent ec540a1a72
commit fc04eb4b7c
37 changed files with 1636 additions and 40 deletions
+33
View File
@@ -0,0 +1,33 @@
"""Unit-level image checks; run in built api1 container."""
import tempfile
import unittest
from pathlib import Path
from src.main import validate_image
from src.errors import ApiError
PNG = (Path(__file__).resolve().parents[1]/'tests/fixtures/sample.png').read_bytes()
class ImageValidationTest(unittest.TestCase):
def check(self, content, content_type):
with tempfile.SpooledTemporaryFile() as stream:
stream.write(content)
validate_image(stream, content_type)
def test_fixture(self):
self.check(PNG,'image/png')
def test_corrupt(self):
with self.assertRaises(ApiError):
self.check(PNG[:70], 'image/png')
def test_spoof_mime(self):
with self.assertRaises(ApiError):
self.check(PNG,'image/jpeg')
def test_random_bytes(self):
with self.assertRaises(ApiError):
self.check(b'unrelated bytes', 'image/png')
if __name__=='__main__':
unittest.main()