aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorKostiantyn Kahanskyi <kostiantyn.kahanskyi@googlemail.com>2014-09-12 14:58:04 +0200
committerKostiantyn Kahanskyi <kostiantyn.kahanskyi@googlemail.com>2014-09-12 15:09:00 +0200
commit4bf9d1938bb144ef2a6c3d03a2d01add62e90114 (patch)
treec881ff8cf675795aa9057957dd3f6615820b4eb1 /activesupport
parentb259b06e73a44f87654d26759b0a679e1ecc069c (diff)
downloadrails-4bf9d1938bb144ef2a6c3d03a2d01add62e90114.tar.gz
rails-4bf9d1938bb144ef2a6c3d03a2d01add62e90114.tar.bz2
rails-4bf9d1938bb144ef2a6c3d03a2d01add62e90114.zip
MessageVerifier raises an appropriate exception if the secret is nil
Otherwise this will lead to another error later on when generating a signature: TypeError (no implicit conversion of nil into String).
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/message_verifier.rb1
-rw-r--r--activesupport/test/message_verifier_test.rb7
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..41e2e5a88f 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.' if secret.nil?
@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)