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:
commit
0f8bb81972
1 changed files with 15 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue