Skip to content

Commit bda2b58

Browse files
committed
add test ensuring that appending/overriding config dups a global policy once, and modifies a local policy on subsequent modifications
1 parent 79e1eb1 commit bda2b58

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

spec/lib/secure_headers_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ module SecureHeaders
109109
expect(hash[CSP::HEADER_NAME]).to eq("default-src 'self'; script-src mycdn.com 'unsafe-inline' anothercdn.com")
110110
end
111111

112+
it "dups global configuration just once when overriding n times" do
113+
Configuration.default do |config|
114+
config.csp = {
115+
default_src: %w('self')
116+
}
117+
end
118+
119+
SecureHeaders.append_content_security_policy_directives(@request, script_src: %w(anothercdn.com))
120+
new_config = SecureHeaders.config_for(@request)
121+
expect(new_config).to_not be(SecureHeaders::Configuration.get)
122+
123+
SecureHeaders.override_content_security_policy_directives(@request, script_src: %w(yet.anothercdn.com))
124+
current_config = SecureHeaders.config_for(@request)
125+
expect(current_config).to be(new_config)
126+
end
127+
112128
it "overrides individual directives" do
113129
Configuration.default do |config|
114130
config.csp = {

0 commit comments

Comments
 (0)