"""Réglages xAPI (bolt-on, voir db/games/get_xapi_settings.py, routes/game/publish/xapi_settings.py) — le mot de passe ne doit JAMAIS ressortir en clair (seulement un booléen `password_set`), et un POST sans mot de passe ne doit pas écraser celui déjà enregistré.""" from flask.testing import FlaskClient from tests.test_auth import anon_client # noqa: F401 def test_xapi_settings_get_defaults_to_empty(client: FlaskClient, game: str) -> None: resp = client.get(f"/game/{game}/xapi-settings") assert resp.status_code == 200 body = resp.get_json() assert body == {"endpoint": "", "login": "", "password_set": False} def test_xapi_settings_post_then_get_round_trip(client: FlaskClient, game: str) -> None: resp = client.post( f"/game/{game}/xapi-settings", json={ "endpoint": "https://lrs.example.com/xapi/", "login": "monlogin", "password": "monmotdepasse", }, ) assert resp.status_code == 200 assert resp.get_json() == {"ok": True} resp = client.get(f"/game/{game}/xapi-settings") body = resp.get_json() assert body["endpoint"] == "https://lrs.example.com/xapi/" assert body["login"] == "monlogin" assert body["password_set"] is True assert "password" not in body def test_xapi_settings_post_with_blank_password_keeps_the_existing_one(client: FlaskClient, game: str) -> None: client.post( f"/game/{game}/xapi-settings", json={ "endpoint": "https://lrs.example.com/xapi/", "login": "monlogin", "password": "monmotdepasse", }, ) resp = client.post( f"/game/{game}/xapi-settings", json={ "endpoint": "https://lrs.example.com/xapi/v2/", "login": "monlogin", "password": "", }, ) assert resp.status_code == 200 import db settings = db.get_xapi_settings(game) assert settings["endpoint"] == "https://lrs.example.com/xapi/v2/" assert settings["password"] == "monmotdepasse" # nosec B105 # noqa: S105 - identifiants factices d'un LRS de test (lrs.example.com), jamais un vrai compte def test_xapi_settings_route_is_isolated_like_other_game_routes(anon_client: FlaskClient) -> None: # noqa: F811 - anon_client est un fixture pytest (voir tests.test_auth), pas une vraie redefinition - pyflakes ne comprend pas l'injection de fixture par parametre """Même garde d'accès que /game//publish (core/auth_guard.py) — aucune vérification supplémentaire écrite pour cette route.""" from tests.test_auth import _cleanup_project, _complete_onboarding, _confirm_2fa, _register _register(anon_client, "xapisettingsisolation@example.com") _confirm_2fa(anon_client) _complete_onboarding(anon_client) try: resp = anon_client.get("/game/un-projet-qui-nest-pas-le-sien/xapi-settings") assert resp.status_code == 403 resp = anon_client.post("/game/un-projet-qui-nest-pas-le-sien/xapi-settings", json={}) assert resp.status_code == 403 finally: _cleanup_project("xapisettingsisolation@example.com")