diff --git a/app/models/user.rb b/app/models/user.rb index 01478df8d..801a37865 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -223,11 +223,11 @@ returns return if !password || password == '' # try to find user based on login - user = User.find_by( login: username.downcase, active: true ) + user = User.find_by(login: username.downcase, active: true) # try second lookup with email if !user - user = User.find_by( email: username.downcase, active: true ) + user = User.find_by(email: username.downcase, active: true) end # check failed logins diff --git a/lib/auth.rb b/lib/auth.rb index 26e33564c..70d2cca5a 100644 --- a/lib/auth.rb +++ b/lib/auth.rb @@ -7,7 +7,7 @@ class Auth authenticate user via username and password - result = Auth.check( username, password, user ) + result = Auth.check(username, password, user) returns @@ -28,7 +28,7 @@ returns ] # added configured backends - Setting.where( area: 'Security::Authentication' ).each {|setting| + Setting.where(area: 'Security::Authentication').each {|setting| if setting.state_current[:value] config.push setting.state_current[:value] end @@ -40,10 +40,10 @@ returns next if !config_item[:adapter] # load backend - backend = load_adapter( config_item[:adapter] ) + backend = load_adapter(config_item[:adapter]) next if !backend - user_auth = backend.check( username, password, config_item, user ) + user_auth = backend.check(username, password, config_item, user) # auth not ok next if !user_auth diff --git a/lib/auth/internal.rb b/lib/auth/internal.rb index d146b0c49..3aa9121d1 100644 --- a/lib/auth/internal.rb +++ b/lib/auth/internal.rb @@ -9,7 +9,7 @@ module Auth::Internal # sha auth check if user.password =~ /^\{sha2\}/ - crypted = Digest::SHA2.hexdigest( password ) + crypted = Digest::SHA2.hexdigest(password) return user if user.password == "{sha2}#{crypted}" end diff --git a/test/unit/auth_test.rb b/test/unit/auth_test.rb index 41ec20d32..0216f87de 100644 --- a/test/unit/auth_test.rb +++ b/test/unit/auth_test.rb @@ -1,59 +1,21 @@ # encoding: utf-8 require 'test_helper' -# set config -if !ENV['LDAP_HOST'] - fail "ERROR: Need LDAP_HOST - hint LDAP_HOST='ldap://ci.zammad.org'" -end - -Setting.create_or_update( - title: 'Authentication via LDAP', - name: 'auth_ldap', - area: 'Security::Authentication', - description: 'Enables user authentication via LDAP.', - state: { - adapter: 'Auth::Ldap', - host: ENV['LDAP_HOST'], - port: 389, - bind_dn: 'cn=Manager,dc=example,dc=org', - bind_pw: 'example', - uid: 'mail', - base: 'dc=example,dc=org', - always_filter: '', - always_roles: %w(Admin Agent), - always_groups: ['Users'], - sync_params: { - firstname: 'sn', - lastname: 'givenName', - email: 'mail', - login: 'mail', - }, - }, - frontend: false -) - -user = User.lookup(email: 'nicole.braun@zammad.org') -if user - user.update_attributes( - login: 'nicole.braun', - password: 'some_pass', - active: true, - ) -else - User.create_if_not_exists( - login: 'nicole.braun', - firstname: 'Nicole', - lastname: 'Braun', - email: 'nicole.braun@zammad.org', - password: 'some_pass', - active: true, - updated_by_id: 1, - created_by_id: 1 - ) -end - class AuthTest < ActiveSupport::TestCase test 'auth' do + + user = User.find_by(email: 'nicole.braun@zammad.org') + user.update_attributes( + login: 'nicole.braun', + firstname: 'Nicole', + lastname: 'Braun', + email: 'nicole.braun@zammad.org', + password: 'some_pass', + active: true, + updated_by_id: 1, + created_by_id: 1 + ) + tests = [ # test 1 @@ -99,18 +61,6 @@ class AuthTest < ActiveSupport::TestCase } }, - # test 5 - { - username: 'paige.chen@example.org', - password: 'password', - result: true, - verify: { - firstname: 'Chen', - lastname: 'Paige', - email: 'paige.chen@example.org', - } - }, - ] tests.each { |test| user = User.authenticate(test[:username], test[:password])