@@ -190,62 +190,58 @@ module SecureHeaders
190190 end
191191
192192 it "supports calling content_security_policy_nonce without parameters (Rails compatibility)" do
193- begin
194- allow ( SecureRandom ) . to receive ( :base64 ) . and_return ( "xyz789" )
193+ allow ( SecureRandom ) . to receive ( :base64 ) . and_return ( "xyz789" )
195194
196- # Create a test class that simulates what GoodJob does
197- # They call content_security_policy_nonce without any parameters
198- test_class = Class . new ( Message ) do
199- def self . template
200- <<-TEMPLATE
195+ # Create a test class that simulates what GoodJob does
196+ # They call content_security_policy_nonce without any parameters
197+ test_class = Class . new ( Message ) do
198+ def self . template
199+ <<-TEMPLATE
201200<script nonce="<%= content_security_policy_nonce %>">
202201 console.log("test")
203202</script>
204203TEMPLATE
205- end
206204 end
205+ end
207206
208- message = test_class . new ( request )
209- result = message . result
207+ message = test_class . new ( request )
208+ result = message . result
210209
211- # The nonce should be included in the rendered output
212- expect ( result ) . to include ( 'nonce="xyz789"' )
210+ # The nonce should be included in the rendered output
211+ expect ( result ) . to include ( 'nonce="xyz789"' )
213212
214- # Call middleware to generate headers
215- _ , env = middleware . call request . env
213+ # Call middleware to generate headers
214+ _ , env = middleware . call request . env
216215
217- # The nonce should be added to script-src in the CSP header (default behavior)
218- expect ( env [ ContentSecurityPolicyConfig ::HEADER_NAME ] ) . to match ( /script-src[^;]*'nonce-xyz789'/ )
219- end
216+ # The nonce should be added to script-src in the CSP header (default behavior)
217+ expect ( env [ ContentSecurityPolicyConfig ::HEADER_NAME ] ) . to match ( /script-src[^;]*'nonce-xyz789'/ )
220218 end
221219
222220 it "supports calling content_security_policy_nonce with :style parameter" do
223- begin
224- allow ( SecureRandom ) . to receive ( :base64 ) . and_return ( "style123" )
221+ allow ( SecureRandom ) . to receive ( :base64 ) . and_return ( "style123" )
225222
226- # Create a test class that calls content_security_policy_nonce with :style
227- test_class = Class . new ( Message ) do
228- def self . template
229- <<-TEMPLATE
223+ # Create a test class that calls content_security_policy_nonce with :style
224+ test_class = Class . new ( Message ) do
225+ def self . template
226+ <<-TEMPLATE
230227<style nonce="<%= content_security_policy_nonce(:style) %>">
231228 body { background: red; }
232229</style>
233230TEMPLATE
234- end
235231 end
232+ end
236233
237- message = test_class . new ( request )
238- result = message . result
234+ message = test_class . new ( request )
235+ result = message . result
239236
240- # The nonce should be included in the rendered output
241- expect ( result ) . to include ( 'nonce="style123"' )
237+ # The nonce should be included in the rendered output
238+ expect ( result ) . to include ( 'nonce="style123"' )
242239
243- # Call middleware to generate headers
244- _ , env = middleware . call request . env
240+ # Call middleware to generate headers
241+ _ , env = middleware . call request . env
245242
246- # The nonce should be added to style-src in the CSP header
247- expect ( env [ ContentSecurityPolicyConfig ::HEADER_NAME ] ) . to match ( /style-src[^;]*'nonce-style123'/ )
248- end
243+ # The nonce should be added to style-src in the CSP header
244+ expect ( env [ ContentSecurityPolicyConfig ::HEADER_NAME ] ) . to match ( /style-src[^;]*'nonce-style123'/ )
249245 end
250246 end
251247end
0 commit comments