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

Merge pull request #13229 from vipulnsward/fix-10635-tests

Fix test-error introduced by #10635.
This commit is contained in:
Rafael Mendonça França 2013-12-12 08:52:40 -08:00
commit 6e2b734f56
2 changed files with 17 additions and 2 deletions

View file

@ -39,8 +39,9 @@ module ActiveSupport
if data.present? && digest.present? && secure_compare(digest, generate_digest(data)) if data.present? && digest.present? && secure_compare(digest, generate_digest(data))
begin begin
@serializer.load(::Base64.strict_decode64(data)) @serializer.load(::Base64.strict_decode64(data))
rescue ArgumentError rescue ArgumentError => argument_error
raise InvalidSignature raise InvalidSignature if argument_error.message =~ %r{invalid base64}
raise
end end
else else
raise InvalidSignature raise InvalidSignature

View file

@ -55,6 +55,20 @@ class MessageVerifierTest < ActiveSupport::TestCase
ActiveSupport.use_standard_json_time_format = prev ActiveSupport.use_standard_json_time_format = prev
end end
def test_raise_error_when_argument_class_is_not_loaded
# To generate the valid message below:
#
# AutoloadClass = Struct.new(:foo)
# valid_message = @verifier.generate(foo: AutoloadClass.new('foo'))
#
valid_message = "BAh7BjoIZm9vbzonTWVzc2FnZVZlcmlmaWVyVGVzdDo6QXV0b2xvYWRDbGFzcwY6CUBmb29JIghmb28GOgZFVA==--f3ef39a5241c365083770566dc7a9eb5d6ace914"
exception = assert_raise(ArgumentError, NameError) do
@verifier.verify(valid_message)
end
assert_includes ["uninitialized constant MessageVerifierTest::AutoloadClass",
"undefined class/module MessageVerifierTest::AutoloadClass"], exception.message
end
def assert_not_verified(message) def assert_not_verified(message)
assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do
@verifier.verify(message) @verifier.verify(message)