Skip to content

Instantly share code, notes, and snippets.

View myme5261314's full-sized avatar

Peng Liu myme5261314

  • Pingan Tech (Shenzhen)
  • Shenzhen, China
View GitHub Profile
@singingwolfboy
singingwolfboy / flask_csrf_test_client.py
Last active September 21, 2024 23:28
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