debian-mirror-gitlab/spec/support/helpers/content_security_policy_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
685 B
Ruby
Raw Permalink Normal View History

2022-05-07 20:08:51 +05:30
# frozen_string_literal: true
module ContentSecurityPolicyHelpers
2023-01-13 00:05:48 +05:30
# Expecting 2 calls to current_content_security_policy by default:
# 1. call that's being tested
# 2. call in ApplicationController
2023-03-04 22:38:38 +05:30
def setup_csp_for_controller(
controller_class, csp = ActionDispatch::ContentSecurityPolicy.new, times: 2,
any_time: false)
2022-05-07 20:08:51 +05:30
expect_next_instance_of(controller_class) do |controller|
2023-03-04 22:38:38 +05:30
if any_time
expect(controller).to receive(:current_content_security_policy).at_least(:once).and_return(csp)
else
expect(controller)
2023-01-13 00:05:48 +05:30
.to receive(:current_content_security_policy).exactly(times).times
.and_return(csp)
2023-03-04 22:38:38 +05:30
end
2022-05-07 20:08:51 +05:30
end
end
end