@@ -160,20 +160,40 @@ def set_security_headers(subject)
160160 end
161161
162162 describe "SecureHeaders#header_hash" do
163+ def expect_default_values ( hash )
164+ expect ( hash [ XFO_HEADER_NAME ] ) . to eq ( SecureHeaders ::XFrameOptions ::Constants ::DEFAULT_VALUE )
165+ expect ( hash [ XDO_HEADER_NAME ] ) . to eq ( SecureHeaders ::XDownloadOptions ::Constants ::DEFAULT_VALUE )
166+ expect ( hash [ HSTS_HEADER_NAME ] ) . to eq ( SecureHeaders ::StrictTransportSecurity ::Constants ::DEFAULT_VALUE )
167+ expect ( hash [ X_XSS_PROTECTION_HEADER_NAME ] ) . to eq ( SecureHeaders ::XXssProtection ::Constants ::DEFAULT_VALUE )
168+ expect ( hash [ X_CONTENT_TYPE_OPTIONS_HEADER_NAME ] ) . to eq ( SecureHeaders ::XContentTypeOptions ::Constants ::DEFAULT_VALUE )
169+ expect ( hash [ XPCDP_HEADER_NAME ] ) . to eq ( SecureHeaders ::XPermittedCrossDomainPolicies ::Constants ::DEFAULT_VALUE )
170+ end
171+
163172 it "produces a hash of headers given a hash as config" do
164173 hash = SecureHeaders ::header_hash ( :csp => { :default_src => 'none' , :img_src => "data:" , :disable_fill_missing => true } )
165174 expect ( hash [ 'Content-Security-Policy-Report-Only' ] ) . to eq ( "default-src 'none'; img-src data:;" )
175+ expect_default_values ( hash )
176+ end
177+
178+ it "produces a hash with a mix of config values, override values, and default values" do
179+ ::SecureHeaders ::Configuration . configure do |config |
180+ config . hsts = { :max_age => '123456' }
181+ end
182+
183+ hash = SecureHeaders ::header_hash ( :csp => { :default_src => 'none' , :img_src => "data:" , :disable_fill_missing => true } )
184+ ::SecureHeaders ::Configuration . configure do |config |
185+ config . hsts = nil
186+ end
187+
188+ expect ( hash [ 'Content-Security-Policy-Report-Only' ] ) . to eq ( "default-src 'none'; img-src data:;" )
189+ expect ( hash [ XFO_HEADER_NAME ] ) . to eq ( SecureHeaders ::XFrameOptions ::Constants ::DEFAULT_VALUE )
190+ expect ( hash [ HSTS_HEADER_NAME ] ) . to eq ( "max-age=123456" )
166191 end
167192
168193 it "produces a hash of headers with default config" do
169194 hash = SecureHeaders ::header_hash
170195 expect ( hash [ 'Content-Security-Policy-Report-Only' ] ) . to eq ( SecureHeaders ::ContentSecurityPolicy ::Constants ::DEFAULT_CSP_HEADER )
171- expect ( hash [ XFO_HEADER_NAME ] ) . to eq ( SecureHeaders ::XFrameOptions ::Constants ::DEFAULT_VALUE )
172- expect ( hash [ XDO_HEADER_NAME ] ) . to eq ( SecureHeaders ::XDownloadOptions ::Constants ::DEFAULT_VALUE )
173- expect ( hash [ HSTS_HEADER_NAME ] ) . to eq ( SecureHeaders ::StrictTransportSecurity ::Constants ::DEFAULT_VALUE )
174- expect ( hash [ X_XSS_PROTECTION_HEADER_NAME ] ) . to eq ( SecureHeaders ::XXssProtection ::Constants ::DEFAULT_VALUE )
175- expect ( hash [ X_CONTENT_TYPE_OPTIONS_HEADER_NAME ] ) . to eq ( SecureHeaders ::XContentTypeOptions ::Constants ::DEFAULT_VALUE )
176- expect ( hash [ XPCDP_HEADER_NAME ] ) . to eq ( SecureHeaders ::XPermittedCrossDomainPolicies ::Constants ::DEFAULT_VALUE )
196+ expect_default_values ( hash )
177197 end
178198 end
179199
0 commit comments