File tree Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Original file line number Diff line number Diff line change 9
9
import pytest
10
10
11
11
import plotly
12
+ from plotly .offline import get_plotlyjs
12
13
import plotly .io as pio
13
14
from plotly .io ._utils import plotly_cdn_url
15
+ from plotly .io ._html import _generate_sri_hash
14
16
15
17
packages_root = os .path .dirname (
16
18
os .path .dirname (os .path .dirname (os .path .dirname (os .path .realpath (plotly .__file__ ))))
37
39
<script type="text/javascript">\
38
40
window.PlotlyConfig = {MathJaxConfig: 'local'};</script>"""
39
41
40
- cdn_script = '<script charset="utf-8" src="http://github.com/%7Bcdn_url%7D"' .format (cdn_url = plotly_cdn_url ())
42
+ cdn_script = '<script charset="utf-8" src="http://github.com/%7Bcdn_url%7D" integrity="{js_hash}" crossorigin="anonymous"></script> ' .format (cdn_url = plotly_cdn_url (), js_hash = _generate_sri_hash ( get_plotlyjs () ))
41
43
42
44
directory_script = '<script charset="utf-8" src="plotly.min.js"></script>'
43
45
Original file line number Diff line number Diff line change 2
2
3
3
import pytest
4
4
import numpy as np
5
+ import re
5
6
6
7
7
8
import plotly .graph_objs as go
@@ -59,8 +60,6 @@ def test_cdn_includes_integrity_attribute(fig1):
59
60
assert 'crossorigin="anonymous"' in html_output
60
61
61
62
# Verify it's in the correct script tag
62
- import re
63
-
64
63
cdn_pattern = re .compile (
65
64
r'<script[^>]*src="'
66
65
+ re .escape (plotly_cdn_url ())
@@ -75,8 +74,6 @@ def test_cdn_integrity_hash_matches_bundled_content(fig1):
75
74
html_output = pio .to_html (fig1 , include_plotlyjs = "cdn" )
76
75
77
76
# Extract the integrity hash from the HTML output
78
- import re
79
-
80
77
integrity_pattern = re .compile (r'integrity="(sha256-[A-Za-z0-9+/=]+)"' )
81
78
match = integrity_pattern .search (html_output )
82
79
assert match is not None , "Integrity attribute not found"
You can’t perform that action at this time.
0 commit comments