1
0
Fork 0
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:
Thibaud Guillaume-Gentil 2010-09-21 10:52:57 +02:00 committed by José Valim
parent 5429f940e7
commit c121d8026e
3 changed files with 16 additions and 1 deletions

View file

@ -81,8 +81,10 @@ module Devise
# Digests the password using the configured encryptor.
def password_digest(password)
if self.password_salt.present?
self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
end
end
module ClassMethods
Devise::Models.config(self, :pepper, :stretches, :encryptor)

View file

@ -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

View file

@ -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)