"""P4.5c: CLI-сброс 2FA только с --yes и с отзывом сессий.""" import importlib import os import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent def test_cli_reset_requires_yes(tmp_path): env = {**os.environ, "DB_PATH": str(tmp_path / "t.db"), "SESSION_SECRET": "s"} sys.path.insert(0, str(ROOT)) import auth import db for m in (auth, db): importlib.reload(m) db.DB_PATH = Path(env["DB_PATH"]) db.init_db() db.create_user("boss42@x", auth.hash_password("p"), role="admin") db.admin_verify_user("boss42@x") secret = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" db.set_totp_secret("boss42@x", secret) db.enable_totp("boss42@x", "[]") r = subprocess.run([sys.executable, str(ROOT / "scripts/admin_2fa_reset.py"), "boss42@x"], env=env, capture_output=True, text=True) assert r.returncode == 1 and "--yes" in r.stdout assert db.get_user_by_email("boss42@x")["totp_enabled"] == 1 r = subprocess.run([sys.executable, str(ROOT / "scripts/admin_2fa_reset.py"), "boss42@x", "--yes"], env=env, capture_output=True, text=True) assert r.returncode == 0, r.stderr assert db.get_user_by_email("boss42@x")["totp_enabled"] == 0