def test_singevalue_directive(): policy = ContentSecurityPolicy() policy.sandbox = "allow-forms" assert policy.text == "sandbox allow-forms" policy.sandbox = "" assert policy.text == "" with pytest.raises(TypeError): policy.sandbox = None
def test_multiple_directives(): policy = ContentSecurityPolicy() policy.default_src.add("https://example.org") policy.default_src.add("https://foobar.org") policy.sandbox = "allow-forms" policy.block_all_mixed_content = True assert policy.text == ( "block-all-mixed-content;" "default-src https://example.org https://foobar.org;" "sandbox allow-forms")