From f2249fefeaf0cf84620c4120f136a48c1da6aff4 Mon Sep 17 00:00:00 2001 From: Jazib Date: Fri, 16 May 2025 22:42:44 -0400 Subject: [PATCH 1/2] Add test for integrity and crossorigin attributes of CDN resources --- requirements/tests.in | 1 + tests/test_bootstrap5/test_integrity.py | 32 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/test_bootstrap5/test_integrity.py diff --git a/requirements/tests.in b/requirements/tests.in index e2b0472e..0edb7409 100644 --- a/requirements/tests.in +++ b/requirements/tests.in @@ -2,3 +2,4 @@ pytest pytest-cov flask-wtf flask-sqlalchemy +beautifulsoup4 diff --git a/tests/test_bootstrap5/test_integrity.py b/tests/test_bootstrap5/test_integrity.py new file mode 100644 index 00000000..dce9ee3d --- /dev/null +++ b/tests/test_bootstrap5/test_integrity.py @@ -0,0 +1,32 @@ +import pytest +from bs4 import BeautifulSoup +from flask import Flask, render_template_string + + +@pytest.fixture +def app(): + app = Flask(__name__) + app.secret_key = "test" + return app + + +def test_cdn_integrity(app): + @app.route("/") + def index(): + return render_template_string( + "{{ bootstrap.load_css() }}{{ bootstrap.load_js() }}" + ) + + client = app.test_client() + response = client.get("/") + html = response.get_data(as_text=True) + soup = BeautifulSoup(html, "html.parser") + + css = soup.find("link", rel="stylesheet") + js = soup.find("script", src=lambda s: s and "bootstrap" in s) + + bootstrap = app.extensions["bootstrap"] + assert css["integrity"] == bootstrap.bootstrap_css_integrity + assert js["integrity"] == bootstrap.bootstrap_js_integrity + assert css["crossorigin"] == "anonymous" + assert js["crossorigin"] == "anonymous" From 97b1370d4c26c1b7b70b32d49c97ed7c591c0598 Mon Sep 17 00:00:00 2001 From: Jazib Date: Sat, 7 Jun 2025 17:23:40 -0400 Subject: [PATCH 2/2] Update test dependencies --- requirements/tests.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/requirements/tests.txt b/requirements/tests.txt index 28389943..b863001c 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,10 +1,12 @@ -# SHA1:2bce3613bf781b5318773bbd23ef6330092309f9 +# SHA1:34838a637a8bb69340f90a1de71e46b007e4a5d6 # # This file is autogenerated by pip-compile-multi # To update, run: # # pip-compile-multi # +beautifulsoup4==4.13.4 + # via -r requirements/tests.in blinker==1.8.2 # via flask click==8.1.8 @@ -50,12 +52,16 @@ pytest-cov==5.0.0 # via -r requirements/tests.in sqlalchemy==2.0.38 # via flask-sqlalchemy +soupsieve==2.7 + # via beautifulsoup4 tomli==2.2.1 # via # coverage # pytest typing-extensions==4.12.2 - # via sqlalchemy + # via + # beautifulsoup4 + # sqlalchemy werkzeug==3.0.6 # via flask wtforms==3.1.2