From 51f98e526e1945d8451ae43041e768a564dbd23e Mon Sep 17 00:00:00 2001 From: Evgeny Bushkov Date: Fri, 6 Nov 2026 16:59:00 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BF=D1=80=D0=B8=D0=BE=D1=80=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D0=B0=20=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20Idempotency-Key=20?= =?UTF-8?q?=D0=B2=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (deepseek/deepseek-chat) --- app/s3.py | 2 ++ tests/test_attachments.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/s3.py b/app/s3.py index bbba20f3..49c10ad3 100644 --- a/app/s3.py +++ b/app/s3.py @@ -114,6 +114,8 @@ async def read_upload(stream, declared_mime: str) -> tuple[bytes, str, str]: continue buf.extend(chunk) hasher.update(chunk) + # Лимит размера приоритетнее валидации содержимого: контракт + # требует 413 при превышении bytes, даже если заголовок битый. if len(buf) > limit: raise ApiError(413, "payload_too_large", "Файл больше 10 MiB") if not header_checked and len(buf) >= _HEADER_BYTES: diff --git a/tests/test_attachments.py b/tests/test_attachments.py index 2b54a208..da850f9d 100644 --- a/tests/test_attachments.py +++ b/tests/test_attachments.py @@ -30,10 +30,12 @@ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) FIXTURE = os.path.join(ROOT, "tests", "fixtures", "sample.png") -def request(method, path, body=None, token=None, raw=None, content_type=None): +def request(method, path, body=None, token=None, raw=None, content_type=None, extra_headers=None): headers = {"Accept": "application/json"} if token: headers["Authorization"] = "Bearer " + token + if extra_headers: + headers.update(extra_headers) data = None if raw is not None: data = raw @@ -166,6 +168,7 @@ class AttachmentTests(unittest.TestCase): "/api/v1/chats/" + self.chat["id"] + "/messages", {"text": "", "attachment_ids": [att["id"]]}, token=self.alice["token"], + extra_headers={"Idempotency-Key": "other-chat-" + uuid.uuid4().hex}, ) self.assertEqual(status, 404) self.assertEqual(body["error"]["code"], "not_found") @@ -178,6 +181,7 @@ class AttachmentTests(unittest.TestCase): "/api/v1/chats/" + self.chat["id"] + "/messages", {"text": "", "attachment_ids": [att["id"]]}, token=self.alice["token"], + extra_headers={"Idempotency-Key": "msg-att-" + uuid.uuid4().hex}, ) self.assertEqual(status, 201, msg) self.assertEqual(msg["attachment_ids"], [att["id"]])