diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-12 13:57:30 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-12 13:57:30 -0300 |
commit | 87de0731e56aee661c525167c07c5db54db2a7d3 (patch) | |
tree | f01d2da382f0c6064b5d20c73a7d1aa2df8bc4fc | |
parent | fb0bd54def85e7e1637ed3401b3a64d026e7f1b6 (diff) | |
parent | 1ac20c59f305b9375add46f81b233f93a94ae70d (diff) | |
download | rails-87de0731e56aee661c525167c07c5db54db2a7d3.tar.gz rails-87de0731e56aee661c525167c07c5db54db2a7d3.tar.bz2 rails-87de0731e56aee661c525167c07c5db54db2a7d3.zip |
Merge pull request #16897 from kostia/message-varifier-raises-exception-on-nil-secret
MessageVerifier.new raises an appropriate exception if the secret is nil
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/message_verifier.rb | 1 | ||||
-rw-r--r-- | activesupport/test/message_verifier_test.rb | 7 |
3 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 0e5a28e3fc..8b76fa97d1 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* `MessageVerifier.new` raises an appropriate exception if the secret is `nil`. + This prevents `MessageVerifier#generate` from raising a cryptic error later on. + + *Kostiantyn Kahanskyi* + * Introduced new configuration option `active_support.test_order` for specifying the order test cases are executed. This option currently defaults to `:sorted` but will be changed to `:random` in Rails 5.0. diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 8e6e1dcfeb..6cb2884fb7 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -27,6 +27,7 @@ module ActiveSupport class InvalidSignature < StandardError; end def initialize(secret, options = {}) + raise ArgumentError, 'Secret should not be nil.' unless secret @secret = secret @digest = options[:digest] || 'SHA1' @serializer = options[:serializer] || Marshal diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb index a5748d28ba..28035bc428 100644 --- a/activesupport/test/message_verifier_test.rb +++ b/activesupport/test/message_verifier_test.rb @@ -69,6 +69,13 @@ class MessageVerifierTest < ActiveSupport::TestCase "undefined class/module MessageVerifierTest::AutoloadClass"], exception.message end + def test_raise_error_when_secret_is_nil + exception = assert_raise(ArgumentError) do + ActiveSupport::MessageVerifier.new(nil) + end + assert_equal exception.message, 'Secret should not be nil.' + end + def assert_not_verified(message) assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do @verifier.verify(message) |