File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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" )
You can’t perform that action at this time.
0 commit comments