2020-03-20 03:54:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe "content security policy integration" do
|
2020-03-20 03:54:42 +08:00
|
|
|
it "adds the csp headers correctly" do
|
2024-03-07 23:20:31 +08:00
|
|
|
Fabricate(:admin) # to avoid 'new installation' screen
|
|
|
|
|
2020-03-20 03:54:42 +08:00
|
|
|
SiteSetting.content_security_policy = false
|
|
|
|
get "/"
|
|
|
|
expect(response.headers["Content-Security-Policy"]).to eq(nil)
|
|
|
|
|
|
|
|
SiteSetting.content_security_policy = true
|
|
|
|
get "/"
|
|
|
|
expect(response.headers["Content-Security-Policy"]).to be_present
|
2024-03-07 23:20:31 +08:00
|
|
|
|
|
|
|
expect(response.headers["Content-Security-Policy"]).to match(
|
|
|
|
/script-src 'nonce-[^']+' 'strict-dynamic';/,
|
|
|
|
)
|
2020-03-20 03:54:42 +08:00
|
|
|
end
|
|
|
|
end
|