Skip to content

Instantly share code, notes, and snippets.

View roganov's full-sized avatar

Yegor Roganov roganov

View GitHub Profile
@singingwolfboy
singingwolfboy / flask_csrf_test_client.py
Last active April 4, 2024 12:26
Want to run your Flask tests with CSRF protections turned on, to make sure that CSRF works properly in production as well? Here's an excellent way to do it!
# Want to run your Flask tests with CSRF protections turned on, to make sure
# that CSRF works properly in production as well? Here's an excellent way
# to do it!
# First some imports. I'm assuming you're using Flask-WTF for CSRF protection.
import flask
from flask.testing import FlaskClient as BaseFlaskClient
from flask_wtf.csrf import generate_csrf
# Flask's assumptions about an incoming request don't quite match up with