test: verify level-four failures and history index

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 12:35:18 +03:00
parent d59d3f4adc
commit e50ba0f8d2
9 changed files with 258 additions and 17 deletions
+12 -6
View File
@@ -39,6 +39,16 @@ def current_user(request: Request) -> dict:
return store.authenticated(bearer_token(request.headers.get("authorization")))
def page_limit(raw: str) -> int:
digits = raw.lstrip("0")
if not raw.isdecimal() or not digits or len(digits) > 3:
raise HTTPException(400)
limit = int(digits)
if not 1 <= limit <= 100:
raise HTTPException(400)
return limit
@router.delete("/api/v1/auth/sessions/current", status_code=204)
def revoke_session(request: Request):
store.revoke_session(bearer_token(request.headers.get("authorization")))
@@ -59,9 +69,7 @@ def create_chat(body: CreateChat, actor: dict = Depends(current_user)):
def list_chats(
limit: str = Query("50"), cursor: str | None = Query(None, min_length=1), actor: dict = Depends(current_user)
):
if not limit.isdecimal() or not 1 <= int(limit) <= 100:
raise HTTPException(400)
return store.list_chats(actor["id"], int(limit), cursor)
return store.list_chats(actor["id"], page_limit(limit), cursor)
@router.get("/api/v1/chats/{chat_id}")
@@ -81,6 +89,4 @@ def list_messages(
cursor: str | None = Query(None, min_length=1),
actor: dict = Depends(current_user),
):
if not limit.isdecimal() or not 1 <= int(limit) <= 100:
raise HTTPException(400)
return store.list_messages(actor["id"], str(chat_id), int(limit), cursor)
return store.list_messages(actor["id"], str(chat_id), page_limit(limit), cursor)