mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-22 14:06:48 +09:00
Leave a request without a policy when the policy is turned off
With DISABLE_CONTENT_SECURITY_POLICY=true there's no application policy, and the hash callback started an empty one, so pages sent an empty Content-Security-Policy header. Skip the callback then.
This commit is contained in:
1 parent
9c37f41ff6
commit
2a449401ec
2 files changed
+21
-1
No files matched your search
@@ -55,6 +55,16 @@ class ContentSecurityPolicyTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
test "with the policy turned off, pages send none" do
|
||||
without_policy do
|
||||
get PAGE_PATH
|
||||
follow_redirect! while response.redirect?
|
||||
|
||||
assert_response :success
|
||||
assert_nil response.headers["Content-Security-Policy"]
|
||||
end
|
||||
end
|
||||
|
||||
test "the escape hatch boots without a policy" do
|
||||
output = IO.popen({ "DISABLE_CONTENT_SECURITY_POLICY" => "true" },
|
||||
[ "bin/rails", "runner", "print Rails.application.config.content_security_policy.inspect" ], chdir: Rails.root, err: File::NULL, &:read)
|
||||
@@ -67,6 +77,14 @@ class ContentSecurityPolicyTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
private
|
||||
# What DISABLE_CONTENT_SECURITY_POLICY=true leaves at boot: no application policy
|
||||
def without_policy
|
||||
previous = Rails.application.env_config.delete("action_dispatch.content_security_policy")
|
||||
yield
|
||||
ensure
|
||||
Rails.application.env_config["action_dispatch.content_security_policy"] = previous
|
||||
end
|
||||
|
||||
def with_asset_host(asset_host)
|
||||
previous, ApplicationController.asset_host = ApplicationController.asset_host, asset_host
|
||||
Rails.application.importmap.send(:clear_cache)
|
||||
|
||||
Reference in new issue
Block a user