Merge pull request #49669 from intrip/fix-message-metadata-non-str

Fix decoding data encoded using a non-String purpose
This commit is contained in:
Jean Boussier 2023-11-01 11:22:36 +01:00 committed by GitHub
commit 9ade3f9b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -82,7 +82,7 @@ module ActiveSupport
throw :invalid_message_content, "expired"
end
if hash["pur"] != purpose&.to_s
if hash["pur"].to_s != purpose.to_s
throw :invalid_message_content, "mismatched purpose"
end

View File

@ -92,6 +92,13 @@ module MessageMetadataTests
assert_roundtrip "a string", codec, { purpose: "x", expires_in: 1.year }, { purpose: "x" }
end
test "messages with non-string purpose are readable" do
each_scenario do |data, codec|
message = encode(data, codec, purpose: [ "x", 1 ])
assert_equal data, decode(message, codec, purpose: [ "x", 1 ])
end
end
test "messages are readable regardless of use_message_serializer_for_metadata" do
each_scenario do |data, codec|
message = encode(data, codec, purpose: "x")