Harden Telegram login, callback spinner and Mini App escaping
- skin: tg_login rejects cross-site Origin; hash compared as bytes; tg_* cookies Secure - bot: answer callback on fast handler failure; cap MENU_OWNER; image retries stop on terminal errors; upstream error texts sent without HTML parse mode - Mini App: escape ids in action buttons and task rows; refresh in Neurolab empty state - tests for spinner and tg login hardening
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""Spinner middleware must answer the callback when the handler fails fast."""
|
||||
import ast
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
SRC = Path(__file__).resolve().parents[1] / "bot" / "grok_bot.py"
|
||||
|
||||
|
||||
def _load_mw():
|
||||
tree = ast.parse(SRC.read_text(encoding="utf-8"))
|
||||
fn = next(n for n in tree.body if isinstance(n, ast.AsyncFunctionDef) and n.name == "_cb_spinner_mw")
|
||||
fn.decorator_list = []
|
||||
ns = {"asyncio": asyncio}
|
||||
exec(compile(ast.Module(body=[fn], type_ignores=[]), str(SRC), "exec"), ns)
|
||||
return ns["_cb_spinner_mw"]
|
||||
|
||||
|
||||
class _Ev:
|
||||
def __init__(self):
|
||||
self.answered = 0
|
||||
|
||||
async def answer(self):
|
||||
self.answered += 1
|
||||
|
||||
|
||||
def test_fast_failure_answers_and_reraises():
|
||||
mw, ev = _load_mw(), _Ev()
|
||||
|
||||
async def handler(e, d):
|
||||
raise ValueError("boom")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
asyncio.run(mw(handler, ev, {}))
|
||||
assert ev.answered == 1
|
||||
|
||||
|
||||
def test_success_does_not_double_answer():
|
||||
mw, ev = _load_mw(), _Ev()
|
||||
|
||||
async def handler(e, d):
|
||||
return "ok"
|
||||
|
||||
assert asyncio.run(mw(handler, ev, {})) == "ok"
|
||||
assert ev.answered == 0
|
||||
Reference in New Issue
Block a user