File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ def build_value
5353 directives . map do |directive_name |
5454 case DIRECTIVE_VALUE_TYPES [ directive_name ]
5555 when :boolean
56- symbol_to_hyphen_case ( directive_name )
56+ symbol_to_hyphen_case ( directive_name ) if @config [ directive_name ]
5757 when :string
5858 [ symbol_to_hyphen_case ( directive_name ) , @config [ directive_name ] ] . join ( " " )
5959 else
Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ module SecureHeaders
7171 expect ( csp . value ) . to eq ( "default-src example.org" )
7272 end
7373
74+ it "does add a boolean directive if the value is true" do
75+ csp = ContentSecurityPolicy . new ( default_src : [ "https://example.org" ] , block_all_mixed_content : true , upgrade_insecure_requests : true )
76+ expect ( csp . value ) . to eq ( "default-src example.org; block-all-mixed-content; upgrade-insecure-requests" )
77+ end
78+
79+ it "does not add a boolean directive if the value is false" do
80+ csp = ContentSecurityPolicy . new ( default_src : [ "https://example.org" ] , block_all_mixed_content : true , upgrade_insecure_requests : false )
81+ expect ( csp . value ) . to eq ( "default-src example.org; block-all-mixed-content" )
82+ end
83+
7484 it "deduplicates any source expressions" do
7585 csp = ContentSecurityPolicy . new ( default_src : %w( example.org example.org example.org ) )
7686 expect ( csp . value ) . to eq ( "default-src example.org" )
You can’t perform that action at this time.
0 commit comments