@@ -699,7 +699,7 @@ def test_iso_timestamp(iso_timestamp, should_be_valid)
699
699
700
700
describe ".parse_structured_header" do
701
701
it "parses valid structured header with timestamp and signature" do
702
- config = { signature_key : "v1" , timestamp_key : "t" }
702
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : "=" , structured_header_separator : "," }
703
703
header_value = "t=1663781880,v1=0123456789abcdef"
704
704
705
705
result = described_class . send ( :parse_structured_header , header_value , config )
@@ -710,8 +710,20 @@ def test_iso_timestamp(iso_timestamp, should_be_valid)
710
710
} )
711
711
end
712
712
713
+ it "parses valid structured header with timestamp and signature using different separators" do
714
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : ":" , structured_header_separator : "." }
715
+ header_value = "t:1663781880.v1:0123456789abcdef"
716
+
717
+ result = described_class . send ( :parse_structured_header , header_value , config )
718
+
719
+ expect ( result ) . to eq ( {
720
+ signature : "0123456789abcdef" ,
721
+ timestamp : "1663781880"
722
+ } )
723
+ end
724
+
713
725
it "parses structured header with only signature" do
714
- config = { signature_key : "v1" , timestamp_key : "t" }
726
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : "=" , structured_header_separator : "," }
715
727
header_value = "v1=abcdef123456"
716
728
717
729
result = described_class . send ( :parse_structured_header , header_value , config )
@@ -722,7 +734,7 @@ def test_iso_timestamp(iso_timestamp, should_be_valid)
722
734
end
723
735
724
736
it "handles extra whitespace in key-value pairs" do
725
- config = { signature_key : "v1" , timestamp_key : "t" }
737
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : "=" , structured_header_separator : "," }
726
738
header_value = "t = 1663781880 , v1 = 0123456789abcdef "
727
739
728
740
result = described_class . send ( :parse_structured_header , header_value , config )
@@ -734,7 +746,7 @@ def test_iso_timestamp(iso_timestamp, should_be_valid)
734
746
end
735
747
736
748
it "returns nil for malformed header (missing equals)" do
737
- config = { signature_key : "v1" , timestamp_key : "t" }
749
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : "=" , structured_header_separator : "," }
738
750
header_value = "t,v1=abcdef"
739
751
740
752
result = described_class . send ( :parse_structured_header , header_value , config )
@@ -743,7 +755,7 @@ def test_iso_timestamp(iso_timestamp, should_be_valid)
743
755
end
744
756
745
757
it "returns nil when signature key is missing" do
746
- config = { signature_key : "v1" , timestamp_key : "t" }
758
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : "=" , structured_header_separator : "," }
747
759
header_value = "t=1663781880,other=value"
748
760
749
761
result = described_class . send ( :parse_structured_header , header_value , config )
@@ -752,7 +764,7 @@ def test_iso_timestamp(iso_timestamp, should_be_valid)
752
764
end
753
765
754
766
it "returns nil when signature value is empty" do
755
- config = { signature_key : "v1" , timestamp_key : "t" }
767
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : "=" , structured_header_separator : "," }
756
768
header_value = "t=1663781880,v1="
757
769
758
770
result = described_class . send ( :parse_structured_header , header_value , config )
@@ -761,7 +773,7 @@ def test_iso_timestamp(iso_timestamp, should_be_valid)
761
773
end
762
774
763
775
it "ignores extra key-value pairs not in config" do
764
- config = { signature_key : "v1" , timestamp_key : "t" }
776
+ config = { signature_key : "v1" , timestamp_key : "t" , key_value_separator : "=" , structured_header_separator : "," }
765
777
header_value = "t=1663781880,v1=abcdef,extra=ignored,another=also_ignored"
766
778
767
779
result = described_class . send ( :parse_structured_header , header_value , config )
0 commit comments