33
44module SecureHeaders
55 describe PolicyManagement do
6+ before ( :each ) do
7+ reset_config
8+ end
9+
610 let ( :default_opts ) do
711 {
812 default_src : %w( https: ) ,
@@ -164,7 +168,7 @@ module SecureHeaders
164168 script_src : %w( 'self' ) ,
165169 }
166170 end
167- combined_config = ContentSecurityPolicy . combine_policies ( Configuration . get . csp . to_h , style_src : %w( anothercdn.com ) )
171+ combined_config = ContentSecurityPolicy . combine_policies ( Configuration . default . csp . to_h , style_src : %w( anothercdn.com ) )
168172 csp = ContentSecurityPolicy . new ( combined_config )
169173 expect ( csp . name ) . to eq ( ContentSecurityPolicyConfig ::HEADER_NAME )
170174 expect ( csp . value ) . to eq ( "default-src https:; script-src 'self'; style-src https: anothercdn.com" )
@@ -179,7 +183,7 @@ module SecureHeaders
179183 } . freeze
180184 end
181185 report_uri = "https://report-uri.io/asdf"
182- combined_config = ContentSecurityPolicy . combine_policies ( Configuration . get . csp . to_h , report_uri : [ report_uri ] )
186+ combined_config = ContentSecurityPolicy . combine_policies ( Configuration . default . csp . to_h , report_uri : [ report_uri ] )
183187 csp = ContentSecurityPolicy . new ( combined_config , USER_AGENTS [ :firefox ] )
184188 expect ( csp . value ) . to include ( "report-uri #{ report_uri } " )
185189 end
@@ -195,7 +199,7 @@ module SecureHeaders
195199 non_default_source_additions = ContentSecurityPolicy ::NON_FETCH_SOURCES . each_with_object ( { } ) do |directive , hash |
196200 hash [ directive ] = %w( "http://example.org )
197201 end
198- combined_config = ContentSecurityPolicy . combine_policies ( Configuration . get . csp . to_h , non_default_source_additions )
202+ combined_config = ContentSecurityPolicy . combine_policies ( Configuration . default . csp . to_h , non_default_source_additions )
199203
200204 ContentSecurityPolicy ::NON_FETCH_SOURCES . each do |directive |
201205 expect ( combined_config [ directive ] ) . to eq ( %w( "http://example.org ) )
@@ -210,7 +214,7 @@ module SecureHeaders
210214 report_only : false
211215 }
212216 end
213- combined_config = ContentSecurityPolicy . combine_policies ( Configuration . get . csp . to_h , report_only : true )
217+ combined_config = ContentSecurityPolicy . combine_policies ( Configuration . default . csp . to_h , report_only : true )
214218 csp = ContentSecurityPolicy . new ( combined_config , USER_AGENTS [ :firefox ] )
215219 expect ( csp . name ) . to eq ( ContentSecurityPolicyReportOnlyConfig ::HEADER_NAME )
216220 end
@@ -223,7 +227,7 @@ module SecureHeaders
223227 block_all_mixed_content : false
224228 }
225229 end
226- combined_config = ContentSecurityPolicy . combine_policies ( Configuration . get . csp . to_h , block_all_mixed_content : true )
230+ combined_config = ContentSecurityPolicy . combine_policies ( Configuration . default . csp . to_h , block_all_mixed_content : true )
227231 csp = ContentSecurityPolicy . new ( combined_config )
228232 expect ( csp . value ) . to eq ( "default-src https:; block-all-mixed-content; script-src 'self'" )
229233 end
@@ -233,7 +237,7 @@ module SecureHeaders
233237 config . csp = OPT_OUT
234238 end
235239 expect do
236- ContentSecurityPolicy . combine_policies ( Configuration . get . csp . to_h , script_src : %w( anothercdn.com ) )
240+ ContentSecurityPolicy . combine_policies ( Configuration . default . csp . to_h , script_src : %w( anothercdn.com ) )
237241 end . to raise_error ( ContentSecurityPolicyConfigError )
238242 end
239243 end
0 commit comments