fix: address attachments verify findings

- keep one upload body in memory: BytesIO + getvalue() without copy,
  fixed glibc mmap threshold in the image (no realloc copy on growth)
- stop PNG inflate at expected size + 1 byte
- reject filename that is not valid UTF-8 after percent-decoding (400)
- failure stand: env limit variables do not change attachment limits;
  history with attachment_ids while S3 is stopped
- drop dead constants; restate "old image on new schema" scenario

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 02:16:49 +03:00
co-authored by Claude Opus 5.5
parent 8dc925e8ca
commit dba40bc325
23 changed files with 398 additions and 47 deletions
+29 -2
View File
@@ -1,12 +1,14 @@
"""Проверки отказов: выполняет только `make failure_checks` (маркер `fault`).
Стенд и hook готовит `student-tests/run_failures.py`: свои Postgres,
Valkey и S3, обычный API (`BASE_URL`) и «тесный» (сроки сессии и ключа
Valkey и S3, обычный API (`BASE_URL`, с `MAX_UPLOAD_BYTES=1` и
`MAX_IMAGE_PIXELS=1` в окружении) и «тесный» (сроки сессии и ключа
идемпотентности 2 с, пул из одного соединения). На хранилища тесты действуют только через фикстуру
`stand` (hook `student-tests/fault_hook.py`) и всегда возвращают их в
рабочее состояние. Решение 4 design change `failure-checks`.
"""
import os
import statistics
import threading
import time
@@ -648,12 +650,16 @@ def test_object_storage_stopped(
"Attachment",
)
assert meta == attachment
api.send_message(
message = api.send_message(
bob,
chat["id"],
"",
attachment_ids=[attachment["id"]],
)
# история с attachment_ids — из PostgreSQL, S3 ей не нужен
history = api.all_messages(alice, chat["id"])
assert [item["id"] for item in history] == [message["id"]]
assert history[0]["attachment_ids"] == [attachment["id"]]
assert_ok(api.request("GET", "/health/ready"), 200, "Health")
assert_content(
api.attachment_content(bob, attachment["id"]),
@@ -662,6 +668,27 @@ def test_object_storage_stopped(
)
def test_environment_does_not_change_limits(
api: Api,
alice: Actor,
chat: dict[str, Any],
) -> None:
"""Спек `service-configuration`, «Окружение не меняет лимит» (вне
сверки покрытия — сценарий в докстринге): обычный API стенда
отказов запущен с `MAX_UPLOAD_BYTES=1` и `MAX_IMAGE_PIXELS=1`
(`run_failures.py`, `LIMITS_ENV`), а `sample.png` (111 817 байт,
64 000 пикселей) всё равно принимается: лимиты — константы."""
limits = dict(
item.split("=", 1)
for item in os.environ.get("FAULT_LIMITS_ENV", "").split()
)
# без этих переменных на стенде тест ничего не доказывает
assert limits == {"MAX_UPLOAD_BYTES": "1", "MAX_IMAGE_PIXELS": "1"}, (
f"stand started without limit variables: {limits}"
)
api.upload(alice, chat["id"], images.sample_png(), filename="sample.png")
@pytest.mark.spec("attachments", "S3 завис")
def test_object_storage_paused(
api: Api,