mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Avoid BCrypt::Errors::InvalidSalt: invalid salt
when password_salt is nil. Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
5429f940e7
commit
c121d8026e
3 changed files with 16 additions and 1 deletions
|
@ -81,7 +81,9 @@ module Devise
|
|||
|
||||
# Digests the password using the configured encryptor.
|
||||
def password_digest(password)
|
||||
self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
|
||||
if self.password_salt.present?
|
||||
self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
|
|
@ -98,6 +98,13 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|||
assert_not user.valid_password?('654321')
|
||||
end
|
||||
|
||||
test 'should not validate password when salt is nil' do
|
||||
admin = create_admin
|
||||
admin.password_salt = nil
|
||||
admin.save
|
||||
assert_not admin.valid_password?('123456')
|
||||
end
|
||||
|
||||
test 'should respond to current password' do
|
||||
assert new_user.respond_to?(:current_password)
|
||||
end
|
||||
|
|
|
@ -37,6 +37,12 @@ class ActiveSupport::TestCase
|
|||
User.create!(valid_attributes(attributes))
|
||||
end
|
||||
|
||||
def create_admin(attributes={})
|
||||
valid_attributes = valid_attributes(attributes)
|
||||
valid_attributes.delete(:username)
|
||||
Admin.create!(valid_attributes)
|
||||
end
|
||||
|
||||
# Execute the block setting the given values and restoring old values after
|
||||
# the block is executed.
|
||||
def swap(object, new_values)
|
||||
|
|
Loading…
Reference in a new issue