fix(calendar): answer 400 when a CalDAV config body is not a JSON object (#6903)

This commit is contained in:
dxrpl
2026-10-27 18:09:14 +01:00
parent 4d0610a1eb
commit 641752387b
2 changed files with 51 additions and 16 deletions
+35
View File
@@ -0,0 +1,35 @@
"""The CalDAV config routes answer 400 for a body that is JSON but not an object."""
import asyncio
import json
from types import SimpleNamespace
import pytest
from fastapi import HTTPException
from routes.calendar_routes import _json_object_body
def _request(raw: bytes):
async def _json():
return json.loads(raw)
return SimpleNamespace(json=_json)
def _parse(raw: bytes):
return asyncio.run(_json_object_body(_request(raw)))
def test_object_body_is_returned():
assert _parse(b'{"url": "https://dav.example/"}') == {"url": "https://dav.example/"}
@pytest.mark.parametrize("raw", [b"", b"not json"])
def test_unreadable_body_counts_as_empty(raw):
assert _parse(raw) == {}
@pytest.mark.parametrize("raw", [b"[]", b'"x"', b"5", b"null"])
def test_non_object_body_is_a_400(raw):
with pytest.raises(HTTPException) as exc:
_parse(raw)
assert exc.value.status_code == 400