diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb index cfc0fb4be..0be3f88a6 100644 --- a/app/models/auth_source_ldap.rb +++ b/app/models/auth_source_ldap.rb @@ -63,7 +63,7 @@ class AuthSourceLdap < AuthSource end end rescue *NETWORK_EXCEPTIONS => e - raise AuthSourceException.new(e.message) + raise AuthSourceException.new(l(:error_can_not_connect_ldap, e.message)) end # Test the connection to the LDAP @@ -77,7 +77,7 @@ class AuthSourceLdap < AuthSource end end rescue *NETWORK_EXCEPTIONS => e - raise AuthSourceException.new(e.message) + raise AuthSourceException.new(l(:error_can_not_connect_ldap, e.message)) end def auth_method_name @@ -107,7 +107,7 @@ class AuthSourceLdap < AuthSource end results rescue *NETWORK_EXCEPTIONS => e - raise AuthSourceException.new(e.message) + raise AuthSourceException.new(l(:error_can_not_connect_ldap, e.message)) end def ldap_mode diff --git a/config/locales/en.yml b/config/locales/en.yml index efaea5252..833becdb4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -224,6 +224,7 @@ en: error_invalid_csv_file_or_settings: "The file is not a CSV file or does not match the settings below" error_can_not_read_import_file: "An error occurred while reading the file to import" error_attachment_extension_not_allowed: "Attachment extension %{extension} is not allowed" + error_can_not_connect_ldap: "Cannot connect to LDAP: %{value}" error_ldap_bind_credentials: "Invalid LDAP Account/Password" error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue" error_no_projects_with_tracker_allowed_for_new_issue: "There are no projects with trackers for which you can create an issue" diff --git a/test/unit/auth_source_ldap_test.rb b/test/unit/auth_source_ldap_test.rb index 2b317b694..5cf02afc8 100644 --- a/test/unit/auth_source_ldap_test.rb +++ b/test/unit/auth_source_ldap_test.rb @@ -271,5 +271,23 @@ class AuthSourceLdapTest < ActiveSupport::TestCase end else puts '(Test LDAP server not configured)' + + def test_authenticate_with_cannot_connect_ldap + auth_source = AuthSourceLdap.find(1) + + error = assert_raise(AuthSourceException) do + auth_source.authenticate('example1','123456') + end + assert_match /\ACannot connect to LDAP: /, error.message + end + + def test_test_connection_with_cannot_connect_ldap + auth_source = AuthSourceLdap.find(1) + + error = assert_raise(AuthSourceException) do + auth_source.test_connection + end + assert_match /\ACannot connect to LDAP: /, error.message + end end end