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"]])