Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverts both "[#4245] Allow password to nil (#4261)" and "Add more tests (#4970)" #5051

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/devise/models/database_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.required_fields(klass)
# the hashed password.
def password=(new_password)
@password = new_password
self.encrypted_password = password_digest(@password)
self.encrypted_password = password_digest(@password) if @password.present?
end

# Verifies whether a password (ie from sign in) is the user password.
Expand All @@ -70,7 +70,7 @@ def valid_password?(password)

# Set password and password confirmation to nil
def clean_up_passwords
@password = @password_confirmation = nil
self.password = self.password_confirmation = nil
end

# Update record attributes when :current_password matches, otherwise
Expand Down Expand Up @@ -198,7 +198,6 @@ def send_password_change_notification
# See https://github.com/plataformatec/devise-encryptable for examples
# of other hashing engines.
def password_digest(password)
return if password.blank?
Devise::Encryptor.digest(self.class, password)
end

Expand Down
23 changes: 3 additions & 20 deletions test/models/database_authenticatable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def setup
assert_nil user.authenticatable_salt
end

test 'should set encrypted password to nil if password is nil' do
assert_nil new_user(password: nil).encrypted_password
assert_nil new_user(password: '').encrypted_password
test 'should not generate a hashed password if password is blank' do
assert_blank new_user(password: nil).encrypted_password
assert_blank new_user(password: '').encrypted_password
end

test 'should hash password again if password has changed' do
Expand Down Expand Up @@ -148,16 +148,6 @@ def setup
refute user.valid_password?('654321')
end

test 'should be invalid if the password is nil' do
user = new_user(password: nil)
refute user.valid_password?(nil)
end

test 'should be invalid if the password is blank' do
user = new_user(password: '')
refute user.valid_password?('')
end

test 'should respond to current password' do
assert new_user.respond_to?(:current_password)
end
Expand Down Expand Up @@ -317,11 +307,4 @@ def setup
]
end
end

test 'nil password should be invalid if password is set to nil' do
user = User.create(email: "[email protected]", password: "12345678")
user.password = nil
refute user.valid_password?('12345678')
refute user.valid_password?(nil)
end
end