Skip to content

Commit 7438946

Browse files
authored
Merge pull request #394 from jazib/test/integrity-values
Add test for integrity and crossorigin attributes of CDN resources
2 parents b210008 + 97b1370 commit 7438946

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

requirements/tests.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pytest
22
pytest-cov
33
flask-wtf
44
flask-sqlalchemy
5+
beautifulsoup4

requirements/tests.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# SHA1:2bce3613bf781b5318773bbd23ef6330092309f9
1+
# SHA1:34838a637a8bb69340f90a1de71e46b007e4a5d6
22
#
33
# This file is autogenerated by pip-compile-multi
44
# To update, run:
55
#
66
# pip-compile-multi
77
#
8+
beautifulsoup4==4.13.4
9+
# via -r requirements/tests.in
810
blinker==1.8.2
911
# via flask
1012
click==8.1.8
@@ -50,12 +52,16 @@ pytest-cov==5.0.0
5052
# via -r requirements/tests.in
5153
sqlalchemy==2.0.38
5254
# via flask-sqlalchemy
55+
soupsieve==2.7
56+
# via beautifulsoup4
5357
tomli==2.2.1
5458
# via
5559
# coverage
5660
# pytest
5761
typing-extensions==4.12.2
58-
# via sqlalchemy
62+
# via
63+
# beautifulsoup4
64+
# sqlalchemy
5965
werkzeug==3.0.6
6066
# via flask
6167
wtforms==3.1.2
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from bs4 import BeautifulSoup
3+
from flask import Flask, render_template_string
4+
5+
6+
@pytest.fixture
7+
def app():
8+
app = Flask(__name__)
9+
app.secret_key = "test"
10+
return app
11+
12+
13+
def test_cdn_integrity(app):
14+
@app.route("/")
15+
def index():
16+
return render_template_string(
17+
"{{ bootstrap.load_css() }}{{ bootstrap.load_js() }}"
18+
)
19+
20+
client = app.test_client()
21+
response = client.get("/")
22+
html = response.get_data(as_text=True)
23+
soup = BeautifulSoup(html, "html.parser")
24+
25+
css = soup.find("link", rel="stylesheet")
26+
js = soup.find("script", src=lambda s: s and "bootstrap" in s)
27+
28+
bootstrap = app.extensions["bootstrap"]
29+
assert css["integrity"] == bootstrap.bootstrap_css_integrity
30+
assert js["integrity"] == bootstrap.bootstrap_js_integrity
31+
assert css["crossorigin"] == "anonymous"
32+
assert js["crossorigin"] == "anonymous"

0 commit comments

Comments
 (0)