Files
monlet/server/tests/test_body_limit.py
2026-05-27 10:01:59 +04:00

31 lines
987 B
Python

import json
import uuid
import pytest
from ._helpers import make_event, make_heartbeat
@pytest.mark.asyncio
async def test_body_too_large_413(app_client, auth_headers):
big_event = make_event(output="x" * 8000)
payload = {"agent_id": "agent-1", "events": [big_event] * 200}
raw = json.dumps(payload) + " " * (1_048_577 - len(json.dumps(payload)))
rid_in = str(uuid.uuid4())
r = await app_client.post(
"/api/v1/events",
content=raw,
headers={**auth_headers, "Content-Type": "application/json", "X-Request-Id": rid_in},
)
assert r.status_code == 413
body = r.json()
assert body["error"]["code"] == "payload_too_large"
assert body["error"]["request_id"] == rid_in
assert r.headers.get("X-Request-Id") == rid_in
@pytest.mark.asyncio
async def test_small_body_ok(app_client, auth_headers):
r = await app_client.post("/api/v1/heartbeat", json=make_heartbeat(), headers=auth_headers)
assert r.status_code == 202