@@ -53,32 +53,40 @@ def test_html_deterministic(fig1):
53
53
def test_cdn_includes_integrity_attribute (fig1 ):
54
54
"""Test that the CDN script tag includes an integrity attribute with SHA256 hash"""
55
55
html_output = pio .to_html (fig1 , include_plotlyjs = "cdn" )
56
-
56
+
57
57
# Check that the script tag includes integrity attribute
58
58
assert 'integrity="sha256-' in html_output
59
59
assert 'crossorigin="anonymous"' in html_output
60
-
60
+
61
61
# Verify it's in the correct script tag
62
62
import re
63
- cdn_pattern = re .compile (r'<script[^>]*src="' + re .escape (plotly_cdn_url ()) + r'"[^>]*integrity="sha256-[A-Za-z0-9+/=]+"[^>]*>' )
63
+
64
+ cdn_pattern = re .compile (
65
+ r'<script[^>]*src="'
66
+ + re .escape (plotly_cdn_url ())
67
+ + r'"[^>]*integrity="sha256-[A-Za-z0-9+/=]+"[^>]*>'
68
+ )
64
69
match = cdn_pattern .search (html_output )
65
70
assert match is not None , "CDN script tag with integrity attribute not found"
66
71
67
72
68
73
def test_cdn_integrity_hash_matches_bundled_content (fig1 ):
69
74
"""Test that the SRI hash in CDN script tag matches the bundled plotly.js content"""
70
75
html_output = pio .to_html (fig1 , include_plotlyjs = "cdn" )
71
-
76
+
72
77
# Extract the integrity hash from the HTML output
73
78
import re
79
+
74
80
integrity_pattern = re .compile (r'integrity="(sha256-[A-Za-z0-9+/=]+)"' )
75
81
match = integrity_pattern .search (html_output )
76
82
assert match is not None , "Integrity attribute not found"
77
83
extracted_hash = match .group (1 )
78
-
84
+
79
85
# Generate expected hash from bundled content
80
86
plotlyjs_content = get_plotlyjs ()
81
87
expected_hash = _generate_sri_hash (plotlyjs_content )
82
-
88
+
83
89
# Verify they match
84
- assert extracted_hash == expected_hash , f"Hash mismatch: expected { expected_hash } , got { extracted_hash } "
90
+ assert (
91
+ extracted_hash == expected_hash
92
+ ), f"Hash mismatch: expected { expected_hash } , got { extracted_hash } "
0 commit comments