From db5e6912daee39e54aaebe5295420dd1386e387e Mon Sep 17 00:00:00 2001 From: Assain Date: Mon, 24 Jul 2017 14:03:21 +0530 Subject: add metadata tests: verify method --- activesupport/test/message_verifier_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activesupport') diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb index d4a8ce762a..5ee4beb16a 100644 --- a/activesupport/test/message_verifier_test.rb +++ b/activesupport/test/message_verifier_test.rb @@ -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) -- cgit v1.2.3