##// END OF EJS Templates
Refactor: Extract method from AuthSourceLdap#authenticate...
Eric Davis -
r3325:b3330d399543
parent child
Show More
@@ -44,10 +44,8 class AuthSourceLdap < AuthSource
44 44 # only ask for the DN if on-the-fly registration is disabled
45 45 :attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry|
46 46 dn = entry.dn
47 attrs = [:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
48 :lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
49 :mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
50 :auth_source_id => self.id ] if onthefly_register?
47 attrs = get_user_attributes_from_ldap_entry(entry) if onthefly_register?
48
51 49 end
52 50 return nil if dn.empty?
53 51 logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
@@ -89,6 +87,15 class AuthSourceLdap < AuthSource
89 87 options.merge!(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank?
90 88 Net::LDAP.new options
91 89 end
90
91 def get_user_attributes_from_ldap_entry(entry)
92 [
93 :firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
94 :lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
95 :mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
96 :auth_source_id => self.id
97 ]
98 end
92 99
93 100 def self.get_attr(entry, attr_name)
94 101 if !attr_name.blank?
@@ -52,19 +52,22 class AuthSourceLdapTest < ActiveSupport::TestCase
52 52 context 'with a valid LDAP user' do
53 53 should 'return the firstname user attributes' do
54 54 response = @auth.authenticate('example1','123456')
55 assert response
55 assert response.is_a?(Array), "An array was not returned"
56 assert response.first.present?, "No user data returned"
56 57 assert_equal 'Example', response.first[:firstname]
57 58 end
58 59
59 60 should 'return the lastname user attributes' do
60 61 response = @auth.authenticate('example1','123456')
61 assert response
62 assert response.is_a?(Array), "An array was not returned"
63 assert response.first.present?, "No user data returned"
62 64 assert_equal 'One', response.first[:lastname]
63 65 end
64 66
65 67 should 'return mail user attributes' do
66 68 response = @auth.authenticate('example1','123456')
67 assert response
69 assert response.is_a?(Array), "An array was not returned"
70 assert response.first.present?, "No user data returned"
68 71 assert_equal 'example1@redmine.org', response.first[:mail]
69 72 end
70 73 end
General Comments 0
You need to be logged in to leave comments. Login now