Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix removed LdapError error class

Oliver Günther7e10047827c4
diff --git a/app/models/ldap_auth_source.rb b/app/models/ldap_auth_source.rb
index ea4a9fc78fb..3b45bda9a5a 100644
--- a/app/models/ldap_auth_source.rb
+++ b/app/models/ldap_auth_source.rb
@@ -52,7 +52,7 @@ class LdapAuthSource < AuthSource
Rails.logger.debug { "Authentication successful for '#{login}'" }
return attrs.except(:dn)
end
- rescue Net::LDAP::LdapError => error
+ rescue Net::LDAP::Error => error
raise 'LdapError: ' + error.message
end
@@ -64,7 +64,7 @@ class LdapAuthSource < AuthSource
Rails.logger.debug { "Lookup successful for '#{login}'" }
return attrs.except(:dn)
end
- rescue Net::LDAP::LdapError => error
+ rescue Net::LDAP::Error => error
raise 'LdapError: ' + error.message
end
@@ -78,7 +78,7 @@ class LdapAuthSource < AuthSource
unless authenticate_dn(account, account_password)
raise I18n.t('auth_source.ldap_error', error_message: I18n.t('auth_source.ldap_auth_failed'))
end
- rescue Net::LDAP::LdapError => text
+ rescue Net::LDAP::Error => text
raise I18n.t('auth_source.ldap_error', error_message: text.to_s)
end
@@ -128,7 +128,7 @@ class LdapAuthSource < AuthSource
port: port,
force_no_page: true,
encryption: ldap_encryption
- }
+ }
options.merge!(auth: { method: :simple, username: ldap_user, password: ldap_password }) unless ldap_user.blank? && ldap_password.blank?
Net::LDAP.new options
end
diff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rb
index a9903451833..328bf02f77f 100644
--- a/spec_legacy/unit/user_spec.rb
+++ b/spec_legacy/unit/user_spec.rb
@@ -217,7 +217,7 @@ describe User, type: :model do
context 'with failed connection to the LDAP server' do
it 'should return nil' do
@auth_source = LdapAuthSource.find(1)
- allow_any_instance_of(AuthSource).to receive(:initialize_ldap_con).and_raise(Net::LDAP::LdapError, 'Cannot connect')
+ allow_any_instance_of(AuthSource).to receive(:initialize_ldap_con).and_raise(Net::LDAP::Error, 'Cannot connect')
assert_equal nil, User.try_to_login('edavis', 'wrong')
end