1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Ensure that we sanitize any AC::Parameters in find_or_initialize_with_errors.

As we are already slicing the Hash, we must be sure that this method will send
 a "safe" object down to the other finder methods that will use the Hash entries
 to do the querying.
This commit is contained in:
Lucas Mazza 2014-09-18 18:15:08 -03:00
parent 952c162bee
commit 39ed332299
2 changed files with 11 additions and 1 deletions

View file

@ -253,7 +253,7 @@ module Devise
# Find an initialize a group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
attributes = attributes.slice(*required_attributes)
attributes = attributes.slice(*required_attributes).with_indifferent_access
attributes.delete_if { |key, value| value.blank? }
if attributes.size == required_attributes.size

View file

@ -10,4 +10,14 @@ class AuthenticatableTest < ActiveSupport::TestCase
assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user
assert_nil User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id.to_s.next)
end
if defined?(ActionController::Parameters)
test 'does not passes an ActionController::Parameters to find_first_by_auth_conditions through find_or_initialize_with_errors' do
user = create_user(email: 'example@example.com')
attributes = ActionController::Parameters.new(email: 'example@example.com')
User.expects(:find_first_by_auth_conditions).with('email' => 'example@example.com').returns(user)
User.find_or_initialize_with_errors([:email], attributes)
end
end
end