Skip to content

Commit f2249fe

Browse files
committed
Add test for integrity and crossorigin attributes of CDN resources
1 parent b210008 commit f2249fe

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
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
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)