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

Merge pull request #29906 from assain/add_more_tests_to_message_verifier

Add tests to MessageVerifier
This commit is contained in:
Kasper Timm Hansen 2017-07-24 12:38:59 +02:00 committed by GitHub
commit 0f8bb81972

View file

@ -99,6 +99,21 @@ class MessageVerifierMetadataTest < ActiveSupport::TestCase
@verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!", verifier_options)
end
def test_verify_raises_when_purpose_differs
assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do
@verifier.verify(@verifier.generate(@message, purpose: "payment"), purpose: "shipping")
end
end
def test_verify_raises_when_expired
signed_message = @verifier.generate(@message, expires_in: 1.month)
travel 2.months
assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do
@verifier.verify(signed_message)
end
end
private
def generate(message, **options)
@verifier.generate(message, options)