fix(csrf): supprimer prevent_initial_call=True sur _fill_csrf_inputs
Avec prevent_initial_call=True, le callback ne s'exécutait pas lors de la chaîne initiale (_generate_csrf_token → csrf-token), laissant le champ csrf_token vide au premier chargement direct de /connexion → erreur 400. Ajoute des tests comportementaux avec CSRF activé (comme en production) et un test architectural qui vérifie que le callback reste appelable initialement. Corrige aussi les assertions de redirection post-login (/compte/abonnement). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,34 @@ def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def csrf_app(users_db_path, monkeypatch):
|
||||
"""App Flask avec protection CSRF activée, comme en production."""
|
||||
from flask import Flask
|
||||
from flask_wtf.csrf import generate_csrf
|
||||
|
||||
from src.auth.setup import init_auth
|
||||
|
||||
monkeypatch.setenv("SECRET_KEY", "test-secret-key")
|
||||
monkeypatch.setenv("LINKEDIN_CLIENT_ID", "test-client-id")
|
||||
monkeypatch.setenv("LINKEDIN_CLIENT_SECRET", "test-client-secret")
|
||||
monkeypatch.setenv("APP_BASE_URL", "http://localhost:8050")
|
||||
|
||||
app = Flask(__name__)
|
||||
init_auth(app)
|
||||
|
||||
@app.route("/_test/csrf")
|
||||
def _test_csrf():
|
||||
return generate_csrf()
|
||||
|
||||
yield app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def csrf_client(csrf_app):
|
||||
return csrf_app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mail_outbox(app, monkeypatch):
|
||||
from src.auth import mailer
|
||||
|
||||
Reference in New Issue
Block a user