(
dash_duo, add_hashes, hash_algorithm, expectation
)
| 23 | ], |
| 24 | ) |
| 25 | def test_incs001_csp_hashes_inline_scripts( |
| 26 | dash_duo, add_hashes, hash_algorithm, expectation |
| 27 | ): |
| 28 | app = Dash(__name__) |
| 29 | |
| 30 | app.layout = html.Div( |
| 31 | [dcc.Input(id="input_element", type="text"), html.Div(id="output_element")] |
| 32 | ) |
| 33 | |
| 34 | app.clientside_callback( |
| 35 | """ |
| 36 | function(input) { |
| 37 | return input; |
| 38 | } |
| 39 | """, |
| 40 | Output("output_element", "children"), |
| 41 | [Input("input_element", "value")], |
| 42 | ) |
| 43 | |
| 44 | with expectation: |
| 45 | csp = { |
| 46 | "default-src": "'self'", |
| 47 | "script-src": ["'self'"] |
| 48 | + (app.csp_hashes(hash_algorithm) if add_hashes else []), |
| 49 | } |
| 50 | |
| 51 | flask_talisman.Talisman( |
| 52 | app.server, content_security_policy=csp, force_https=False |
| 53 | ) |
| 54 | |
| 55 | dash_duo.start_server(app) |
| 56 | |
| 57 | dash_duo.find_element("#input_element").send_keys("xyz") |
| 58 | assert dash_duo.wait_for_element("#output_element").text == "xyz" |
nothing calls this directly
no test coverage detected
searching dependent graphs…