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
53
53
directives . map do |directive_name |
54
54
case DIRECTIVE_VALUE_TYPES [ directive_name ]
55
55
when :boolean
56
- symbol_to_hyphen_case ( directive_name )
56
+ symbol_to_hyphen_case ( directive_name ) if @config [ directive_name ]
57
57
when :string
58
58
[ symbol_to_hyphen_case ( directive_name ) , @config [ directive_name ] ] . join ( " " )
59
59
else
Original file line number Diff line number Diff line change @@ -71,6 +71,16 @@ module SecureHeaders
71
71
expect ( csp . value ) . to eq ( "default-src example.org" )
72
72
end
73
73
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
+
74
84
it "deduplicates any source expressions" do
75
85
csp = ContentSecurityPolicy . new ( default_src : %w( example.org example.org example.org ) )
76
86
expect ( csp . value ) . to eq ( "default-src example.org" )
You can’t perform that action at this time.
0 commit comments