diff --git a/app/controllers/auth_sources_controller.rb b/app/controllers/auth_sources_controller.rb index cf139a187..2a854ad48 100644 --- a/app/controllers/auth_sources_controller.rb +++ b/app/controllers/auth_sources_controller.rb @@ -64,8 +64,8 @@ class AuthSourcesController < ApplicationController begin @auth_method.test_connection flash[:notice] = l(:notice_successful_connection) - rescue => text - flash[:error] = l(:error_unable_to_connect, text.message) + rescue Exception => e + flash[:error] = l(:error_unable_to_connect, e.message) end redirect_to :action => 'index' end diff --git a/test/functional/ldap_auth_sources_controller_test.rb b/test/functional/ldap_auth_sources_controller_test.rb index b24cbc281..bfb2c569e 100644 --- a/test/functional/ldap_auth_sources_controller_test.rb +++ b/test/functional/ldap_auth_sources_controller_test.rb @@ -93,4 +93,22 @@ class LdapAuthSourcesControllerTest < ActionController::TestCase post :destroy, :id => 1 end end + + def test_test_connection + AuthSourceLdap.any_instance.stubs(:test_connection).returns(true) + + get :test_connection, :id => 1 + assert_redirected_to '/ldap_auth_sources' + assert_not_nil flash[:notice] + assert_match /successful/i, flash[:notice] + end + + def test_test_connection_with_failure + AuthSourceLdap.any_instance.stubs(:test_connection).raises(Exception.new("Something went wrong")) + + get :test_connection, :id => 1 + assert_redirected_to '/ldap_auth_sources' + assert_not_nil flash[:error] + assert_include '(Something went wrong)', flash[:error] + end end