feat: усилить reconciler для lab4

This commit is contained in:
2026-11-05 23:30:24 +03:00
parent a3bbdeef42
commit 1ad44408ba
11 changed files with 276 additions and 54 deletions
+9
View File
@@ -37,22 +37,26 @@ def oversized_dimensions_png(content: bytes) -> bytes:
def test_file_larger_than_10_mib_is_rejected(scenario):
"""Отклоняет файл размером больше 10 MiB."""
client, alice, _bob, _eve, chat = scenario
upload(client, alice, chat, b'x' * (10 * 1024 * 1024 + 1), expected=413)
def test_corrupted_image_is_rejected(scenario):
"""Отклоняет повреждённое изображение."""
client, alice, _bob, _eve, chat = scenario
upload(client, alice, chat, b'not-a-png', expected=415)
def test_mime_mismatch_is_rejected(scenario):
"""Отклоняет MIME, не совпадающий с содержимым."""
client, alice, _bob, _eve, chat = scenario
content = (ROOT / 'tests/fixtures/sample.png').read_bytes()
upload(client, alice, chat, content, content_type='image/jpeg', expected=415)
def test_pixel_limit_is_checked_before_decode(scenario):
"""Проверяет лимит пикселей до полной декомпрессии."""
client, alice, _bob, _eve, chat = scenario
content = oversized_dimensions_png((ROOT / 'tests/fixtures/sample.png').read_bytes())
upload(client, alice, chat, content, expected=413)
@@ -63,12 +67,14 @@ def test_pixel_limit_is_checked_before_decode(scenario):
['../escape.png', 'folder\\escape.png', 'bad\x00name.png', 'bad\x85name.png'],
)
def test_dangerous_filename_is_rejected(scenario, filename):
"""Отклоняет опасное отображаемое имя файла."""
client, alice, _bob, _eve, chat = scenario
content = (ROOT / 'tests/fixtures/sample.png').read_bytes()
upload(client, alice, chat, content, filename=filename, expected=400)
def test_outsider_cannot_read_attachment(scenario):
"""Скрывает метаданные и содержимое от постороннего пользователя."""
client, alice, _bob, eve, chat = scenario
content = (ROOT / 'tests/fixtures/sample.png').read_bytes()
attachment = upload(client, alice, chat, content)['json']
@@ -77,6 +83,7 @@ def test_outsider_cannot_read_attachment(scenario):
def test_attachment_from_another_chat_cannot_be_linked(scenario):
"""Запрещает прикреплять вложение другого чата."""
client, alice, bob, _eve, chat = scenario
other_chat = client.call(
'POST',
@@ -99,6 +106,7 @@ def test_attachment_from_another_chat_cannot_be_linked(scenario):
def test_idempotency_distinguishes_attachment_list(scenario):
"""Включает список вложений в сравнение идемпотентного запроса."""
client, alice, _bob, _eve, chat = scenario
content = (ROOT / 'tests/fixtures/sample.png').read_bytes()
attachment = upload(client, alice, chat, content)['json']
@@ -129,6 +137,7 @@ def test_idempotency_distinguishes_attachment_list(scenario):
def test_missing_attachment_ids_equals_empty_list_for_idempotency(scenario):
"""Считает отсутствие attachment_ids эквивалентным пустому списку."""
client, alice, _bob, _eve, chat = scenario
key = uuid.uuid4().hex
first = client.message(alice, chat, 'обычный текст', key=key)['json']