fix: исправить приоритет проверки размера и добавить Idempotency-Key в тесты
Co-authored-by: aider (deepseek/deepseek-chat) <aider@aider.chat>
This commit is contained in:
@@ -114,6 +114,8 @@ async def read_upload(stream, declared_mime: str) -> tuple[bytes, str, str]:
|
|||||||
continue
|
continue
|
||||||
buf.extend(chunk)
|
buf.extend(chunk)
|
||||||
hasher.update(chunk)
|
hasher.update(chunk)
|
||||||
|
# Лимит размера приоритетнее валидации содержимого: контракт
|
||||||
|
# требует 413 при превышении bytes, даже если заголовок битый.
|
||||||
if len(buf) > limit:
|
if len(buf) > limit:
|
||||||
raise ApiError(413, "payload_too_large", "Файл больше 10 MiB")
|
raise ApiError(413, "payload_too_large", "Файл больше 10 MiB")
|
||||||
if not header_checked and len(buf) >= _HEADER_BYTES:
|
if not header_checked and len(buf) >= _HEADER_BYTES:
|
||||||
|
|||||||
@@ -30,10 +30,12 @@ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||||||
FIXTURE = os.path.join(ROOT, "tests", "fixtures", "sample.png")
|
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"}
|
headers = {"Accept": "application/json"}
|
||||||
if token:
|
if token:
|
||||||
headers["Authorization"] = "Bearer " + token
|
headers["Authorization"] = "Bearer " + token
|
||||||
|
if extra_headers:
|
||||||
|
headers.update(extra_headers)
|
||||||
data = None
|
data = None
|
||||||
if raw is not None:
|
if raw is not None:
|
||||||
data = raw
|
data = raw
|
||||||
@@ -166,6 +168,7 @@ class AttachmentTests(unittest.TestCase):
|
|||||||
"/api/v1/chats/" + self.chat["id"] + "/messages",
|
"/api/v1/chats/" + self.chat["id"] + "/messages",
|
||||||
{"text": "", "attachment_ids": [att["id"]]},
|
{"text": "", "attachment_ids": [att["id"]]},
|
||||||
token=self.alice["token"],
|
token=self.alice["token"],
|
||||||
|
extra_headers={"Idempotency-Key": "other-chat-" + uuid.uuid4().hex},
|
||||||
)
|
)
|
||||||
self.assertEqual(status, 404)
|
self.assertEqual(status, 404)
|
||||||
self.assertEqual(body["error"]["code"], "not_found")
|
self.assertEqual(body["error"]["code"], "not_found")
|
||||||
@@ -178,6 +181,7 @@ class AttachmentTests(unittest.TestCase):
|
|||||||
"/api/v1/chats/" + self.chat["id"] + "/messages",
|
"/api/v1/chats/" + self.chat["id"] + "/messages",
|
||||||
{"text": "", "attachment_ids": [att["id"]]},
|
{"text": "", "attachment_ids": [att["id"]]},
|
||||||
token=self.alice["token"],
|
token=self.alice["token"],
|
||||||
|
extra_headers={"Idempotency-Key": "msg-att-" + uuid.uuid4().hex},
|
||||||
)
|
)
|
||||||
self.assertEqual(status, 201, msg)
|
self.assertEqual(status, 201, msg)
|
||||||
self.assertEqual(msg["attachment_ids"], [att["id"]])
|
self.assertEqual(msg["attachment_ids"], [att["id"]])
|
||||||
|
|||||||
Reference in New Issue
Block a user