Handle nil values correctly in User.authenticateUser
This commit is contained in:
parent
241d504a76
commit
1d9856ff93
2 changed files with 7 additions and 1 deletions
|
@ -203,7 +203,7 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
def self.authenticate(login, password)
|
def self.authenticate(login, password)
|
||||||
user = find_by_nick(login) || find_by_email(login)
|
user = find_by_nick(login) || find_by_email(login)
|
||||||
if user && user.has_password(password)
|
if user && password && user.has_password(password)
|
||||||
user
|
user
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -32,6 +32,12 @@ describe User do
|
||||||
it 'can not authenticate with incorrect password' do
|
it 'can not authenticate with incorrect password' do
|
||||||
expect(User.authenticate(user.nick, 'foobar')).to be_nil
|
expect(User.authenticate(user.nick, 'foobar')).to be_nil
|
||||||
end
|
end
|
||||||
|
it 'can not authenticate with nil nick' do
|
||||||
|
expect(User.authenticate(nil, 'blahblah')).to be_nil
|
||||||
|
end
|
||||||
|
it 'can not authenticate with nil password' do
|
||||||
|
expect(User.authenticate(user.nick, nil)).to be_nil
|
||||||
|
end
|
||||||
it 'can not set a password without matching confirmation' do
|
it 'can not set a password without matching confirmation' do
|
||||||
user.password = 'abcdefghij'
|
user.password = 'abcdefghij'
|
||||||
user.password_confirmation = 'foobarxyz'
|
user.password_confirmation = 'foobarxyz'
|
||||||
|
|
Loading…
Reference in a new issue