1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix Messages::Metadata#fresh? to handle parse_json_times = true

When `ActiveSupport.parse_json_times` is `true`,
`ActiveSupport::Messages::Medata.verify` will fail with a `TypeError` as
it does not pass a `String` to `Time.iso8601` as is expected.

This leads to hard-failure on retrieval of signed cookies with expiries.
This commit is contained in:
Christian Gregg 2019-10-18 15:14:42 +01:00 committed by Kasper Timm Hansen
parent b305f0e206
commit 6e0aa1887d
No known key found for this signature in database
GPG key ID: 191153215EDA53D8
3 changed files with 16 additions and 1 deletions

View file

@ -1,3 +1,8 @@
* Update `ActiveSupport::Messages::Metadata#fresh?` to work for cookies with expiry set when
`ActiveSupport.parse_json_times = true`.
*Christian Gregg*
* Support symbolic links for `content_path` in `ActiveSupport::EncryptedFile`.
*Takumi Shotoku*

View file

@ -64,7 +64,7 @@ module ActiveSupport
end
def fresh?
@expires_at.nil? || Time.now.utc < Time.iso8601(@expires_at)
@expires_at.nil? || Time.now.utc < @expires_at
end
end
end

View file

@ -61,6 +61,15 @@ class MessageVerifierTest < ActiveSupport::TestCase
ActiveSupport.use_standard_json_time_format = prev
end
def test_verify_with_parse_json_times
previous = [ ActiveSupport.parse_json_times, Time.zone ]
ActiveSupport.parse_json_times, Time.zone = true, "UTC"
assert_equal "hi", @verifier.verify(@verifier.generate("hi", expires_at: Time.now.utc + 10))
ensure
ActiveSupport.parse_json_times, Time.zone = previous
end
def test_raise_error_when_argument_class_is_not_loaded
# To generate the valid message below:
#
@ -92,6 +101,7 @@ class MessageVerifierTest < ActiveSupport::TestCase
assert_equal @data, @verifier.verify(signed_message)
end
def test_rotating_secret
old_message = ActiveSupport::MessageVerifier.new("old", digest: "SHA1").generate("old")