@@ -29,6 +29,9 class AccountController < ApplicationController | |||||
29 | else |
|
29 | else | |
30 | authenticate_user |
|
30 | authenticate_user | |
31 | end |
|
31 | end | |
|
32 | rescue AuthSourceException => e | |||
|
33 | logger.error "An error occured when authenticating #{params[:username]}: #{e.message}" | |||
|
34 | render_error :message => e.message | |||
32 | end |
|
35 | end | |
33 |
|
36 | |||
34 | # Log out current user and redirect to welcome page |
|
37 | # Log out current user and redirect to welcome page |
@@ -15,6 +15,10 | |||||
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
|
18 | # Generic exception for when the AuthSource can not be reached | |||
|
19 | # (eg. can not connect to the LDAP) | |||
|
20 | class AuthSourceException < Exception; end | |||
|
21 | ||||
18 | class AuthSource < ActiveRecord::Base |
|
22 | class AuthSource < ActiveRecord::Base | |
19 | include Redmine::Ciphering |
|
23 | include Redmine::Ciphering | |
20 |
|
24 |
@@ -40,8 +40,8 class AuthSourceLdap < AuthSource | |||||
40 | logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? |
|
40 | logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? | |
41 | return attrs.except(:dn) |
|
41 | return attrs.except(:dn) | |
42 | end |
|
42 | end | |
43 |
rescue Net::LDAP::LdapError => |
|
43 | rescue Net::LDAP::LdapError => e | |
44 | raise "LdapError: " + text |
|
44 | raise AuthSourceException.new(e.message) | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | # test the connection to the LDAP |
|
47 | # test the connection to the LDAP |
@@ -51,6 +51,16 class AccountControllerTest < ActionController::TestCase | |||||
51 | :content => /Invalid user or password/ |
|
51 | :content => /Invalid user or password/ | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
|
54 | def test_login_should_rescue_auth_source_exception | |||
|
55 | source = AuthSource.create!(:name => 'Test') | |||
|
56 | User.find(2).update_attribute :auth_source_id, source.id | |||
|
57 | AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong")) | |||
|
58 | ||||
|
59 | post :login, :username => 'jsmith', :password => 'jsmith' | |||
|
60 | assert_response 500 | |||
|
61 | assert_error_tag :content => /Something wrong/ | |||
|
62 | end | |||
|
63 | ||||
54 | if Object.const_defined?(:OpenID) |
|
64 | if Object.const_defined?(:OpenID) | |
55 |
|
65 | |||
56 | def test_login_with_openid_for_existing_user |
|
66 | def test_login_with_openid_for_existing_user |
General Comments 0
You need to be logged in to leave comments.
Login now