Исправления по ревью: 415 для не-JSON, logout атомарен с инвалидацией кэша

This commit is contained in:
2026-10-22 13:31:03 +03:00
parent dbdb66456a
commit 9e7c792e9d
6 changed files with 172 additions and 23 deletions
+14
View File
@@ -8,6 +8,7 @@
"""
import argparse
import base64
import json
import uuid
from concurrent.futures import ThreadPoolExecutor
@@ -100,6 +101,19 @@ def main():
st, _, _ = api.call("GET", f"/api/v1/chats/{other['id']}/messages?cursor={p['next_cursor']}", token=alice["token"])
r.check(st == 400, "cursor from another chat -> 400")
print("== Content-Type ==")
body = json.dumps({"username": "ct_" + uuid.uuid4().hex[:8], "display_name": "c", "password": PASSWORD}).encode()
st, _, _ = api.raw("POST", "/api/v1/users", body, {"Content-Type": "text/plain"})
r.check(st == 415, f"valid JSON with text/plain -> 415 (got {st})")
st, _, _ = api.raw("POST", mpath, json.dumps({"text": "x"}).encode(),
{"Content-Type": "text/plain", "Authorization": "Bearer " + alice["token"]})
r.check(st == 415, f"message with text/plain -> 415 (got {st})")
st, _, _ = api.raw("POST", "/api/v1/chats", b"{}", {"Content-Type": "text/plain"})
r.check(st == 401, f"text/plain without token -> 401 first (got {st})")
st, _, _ = api.raw("POST", mpath, json.dumps({"text": "utf8"}).encode(),
{"Content-Type": "application/json; charset=utf-8", "Authorization": "Bearer " + alice["token"]})
r.check(st == 201, f"application/json; charset=utf-8 accepted (got {st})")
r.finish()