diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2018-10-23 07:35:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-23 07:35:51 +0100 |
commit | 759b3af0c6fc9fb502031a05b281736602ff8e5f (patch) | |
tree | 97962a0b7a59310e2299da20dd94c5d39a1b74d1 /actionpack/test | |
parent | c2f8df67f34e233ff3f7f058d492217c5ad3eff1 (diff) | |
parent | a150a026591b7b9dcaba5a2ef5fce02f7d990aba (diff) | |
download | rails-759b3af0c6fc9fb502031a05b281736602ff8e5f.tar.gz rails-759b3af0c6fc9fb502031a05b281736602ff8e5f.tar.bz2 rails-759b3af0c6fc9fb502031a05b281736602ff8e5f.zip |
Merge pull request #34286 from rails/fix-csp-dynamic-sources
Fix CSP dynamic sources
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/content_security_policy_test.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/actionpack/test/dispatch/content_security_policy_test.rb b/actionpack/test/dispatch/content_security_policy_test.rb index 13ad22b5c5..c8c885f35c 100644 --- a/actionpack/test/dispatch/content_security_policy_test.rb +++ b/actionpack/test/dispatch/content_security_policy_test.rb @@ -260,12 +260,13 @@ class DefaultContentSecurityPolicyIntegrationTest < ActionDispatch::IntegrationT ROUTES.draw do scope module: "default_content_security_policy_integration_test" do get "/", to: "policy#index" + get "/redirect", to: redirect("/") end end POLICY = ActionDispatch::ContentSecurityPolicy.new do |p| - p.default_src :self - p.script_src :https + p.default_src -> { :self } + p.script_src -> { :https } end class PolicyConfigMiddleware @@ -295,14 +296,19 @@ class DefaultContentSecurityPolicyIntegrationTest < ActionDispatch::IntegrationT def test_adds_nonce_to_script_src_content_security_policy_only_once get "/" get "/" + assert_response :success + assert_policy "default-src 'self'; script-src https: 'nonce-iyhD0Yc0W+c='" + end + + def test_redirect_works_with_dynamic_sources + get "/redirect" + assert_response :redirect assert_policy "default-src 'self'; script-src https: 'nonce-iyhD0Yc0W+c='" end private def assert_policy(expected, report_only: false) - assert_response :success - if report_only expected_header = "Content-Security-Policy-Report-Only" unexpected_header = "Content-Security-Policy" |