Skip to content

Commit 1147e01

Browse files
authored
Convert symbol to string for reporting endpoints & update tests
1 parent a3321c6 commit 1147e01

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/secure_headers/headers/reporting_endpoints.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def validate_config!(config)
2424
# valid
2525
when Hash
2626
config.each_pair do |name, url|
27+
if name.is_a?(Symbol)
28+
name = name.to_s
29+
end
2730
unless name.is_a?(String) && !name.empty?
2831
raise ReportingEndpointsConfigError.new("Endpoint name must be a non-empty string, got: #{name.inspect}")
2932
end

spec/lib/secure_headers/headers/reporting_endpoints_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ module SecureHeaders
1919
expect(value).to eq('csp-endpoint="https://example.com/csp-reports"')
2020
end
2121

22+
it "formats a single endpoint with a symbol" do
23+
config = { "csp-endpoint": "https://example.com/csp-reports" }
24+
header_name, value = ReportingEndpoints.make_header(config)
25+
expect(header_name).to eq("reporting-endpoints")
26+
expect(value).to eq('csp-endpoint="https://example.com/csp-reports"')
27+
end
28+
2229
it "formats multiple endpoints" do
2330
config = {
2431
"csp-endpoint" => "https://example.com/csp-reports",
@@ -60,6 +67,14 @@ module SecureHeaders
6067
end.to_not raise_error
6168
end
6269

70+
it "accepts valid endpoint configuration with symbol keys" do
71+
expect do
72+
ReportingEndpoints.validate_config!({
73+
"csp-violations": "https://example.com/reports"
74+
})
75+
end.to_not raise_error
76+
end
77+
6378
it "rejects non-hash config" do
6479
expect do
6580
ReportingEndpoints.validate_config!("not a hash")

0 commit comments

Comments
 (0)