Files
iishko-public/tests/test_bot_callback_spinner.py
T
reform a05a36aa7b
checks / pytest (push) Has been cancelled
checks / moderation (push) Has been cancelled
checks / node (push) Has been cancelled
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
2026-10-31 02:16:16 +03:00

47 lines
1.1 KiB
Python

"""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