@@ -58,7 +58,17 @@ def request_for user_agent, request_uri=nil, options={:ssl => false}
5858
5959 it "exports a policy to JSON" do
6060 policy = ContentSecurityPolicy . new ( default_opts )
61- expected = %({"default_src":["https:"],"script_src":["'unsafe-inline'","'unsafe-eval'","https:","data:"],"style_src":["'unsafe-inline'","https:","about:"],"img_src":["https:","data:"]})
61+ expected = %({"default-src":["https:"],"script-src":["'unsafe-inline'","'unsafe-eval'","https:","data:"],"style-src":["'unsafe-inline'","https:","about:"],"img-src":["https:","data:"]})
62+ expect ( policy . to_json ) . to eq ( expected )
63+ end
64+
65+ it "imports JSON to build a policy" do
66+ json1 = %({"default-src":["https:"],"script-src":["'unsafe-inline'","'unsafe-eval'","https:","data:"]})
67+ json2 = %({"style-src":["'unsafe-inline'","https:","about:"],"img-src":["https:","data:"]})
68+ config = ContentSecurityPolicy . from_json ( json1 , json2 )
69+ policy = ContentSecurityPolicy . new ( config . merge ( :disable_fill_missing => true ) )
70+
71+ expected = %({"default-src":["https:"],"script-src":["'unsafe-inline'","'unsafe-eval'","https:","data:"],"style-src":["'unsafe-inline'","https:","about:"],"img-src":["https:","data:"]})
6272 expect ( policy . to_json ) . to eq ( expected )
6373 end
6474
0 commit comments