Permalink
Browse files

Make possible to use symbol as the verifier name

  • Loading branch information...
1 parent 61f6b47 commit bfdae1775a298a4240c32e87d84ea7e8c6dccb06 @rafaelfranca rafaelfranca committed Dec 19, 2013
@@ -197,7 +197,6 @@ Rails.application.message_verifier(:remember_me).verify(signed_token) # => token
Rails.application.message_verifier(:remember_me).verify(tampered_token)
# raises ActiveSupport::MessageVerifier::InvalidSignature
-
```
### Module#concerning
View
@@ -35,14 +35,14 @@
This verifier can be used to generate and verify signed messages in the application.
- message = Rails.application.message_verifier('sensitive_data').generate('my sensible data')
- Rails.application.message_verifier('sensitive_data').verify(message)
+ message = Rails.application.message_verifier(:sensitive_data).generate('my sensible data')
+ Rails.application.message_verifier(:sensitive_data).verify(message)
# => 'my sensible data'
It is recommended not to use the same verifier for different things, so you can get different
verifiers passing the name argument.
- message = Rails.application.message_verifier('cookies').generate('my sensible cookie data')
+ message = Rails.application.message_verifier(:cookies).generate('my sensible cookie data')
See the `ActiveSupport::MessageVerifier` documentation for more information.
@@ -181,7 +181,7 @@ def key_generator
# See the +ActiveSupport::MessageVerifier+ documentation for more information.
def message_verifier(verifier_name)
@message_verifiers[verifier_name] ||= begin
- secret = key_generator.generate_key(verifier_name)
+ secret = key_generator.generate_key(verifier_name.to_s)
ActiveSupport::MessageVerifier.new(secret)
end
end
@@ -274,11 +274,11 @@ def index
app.config.session_store :disabled
end
- message = app.message_verifier('salt').generate("some_value")
+ message = app.message_verifier(:sensitive_value).generate("some_value")
- assert_equal 'some_value', Rails.application.message_verifier('salt').verify(message)
+ assert_equal 'some_value', Rails.application.message_verifier(:sensitive_value).verify(message)
- secret = app.key_generator.generate_key('salt')
+ secret = app.key_generator.generate_key('sensitive_value')
verifier = ActiveSupport::MessageVerifier.new(secret)
assert_equal 'some_value', verifier.verify(message)
end
@@ -289,8 +289,8 @@ def index
app.config.session_store :disabled
end
- default_verifier = app.message_verifier('salt')
- text_verifier = app.message_verifier('text')
+ default_verifier = app.message_verifier(:sensitive_value)
+ text_verifier = app.message_verifier(:text)
message = text_verifier.generate('some_value')
@@ -299,7 +299,7 @@ def index
default_verifier.verify(message)
end
- assert_equal default_verifier.object_id, app.message_verifier('salt').object_id
+ assert_equal default_verifier.object_id, app.message_verifier(:sensitive_value).object_id
assert_not_equal default_verifier.object_id, text_verifier.object_id
end

0 comments on commit bfdae17

Please sign in to comment.