]> source.dussan.org Git - redmine.git/commitdiff
Refactor: Extract method from AuthSourceLdap#authenticate
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 16 Feb 2010 17:03:54 +0000 (17:03 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 16 Feb 2010 17:03:54 +0000 (17:03 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3439 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/auth_source_ldap.rb
test/unit/auth_source_ldap_test.rb

index a619b2f85770b78d62b2403810a262dde0b42b0f..04f4c89b320154edfce8918e010c61a4ebfb48a3 100644 (file)
@@ -44,10 +44,8 @@ class AuthSourceLdap < AuthSource
                      # only ask for the DN if on-the-fly registration is disabled
                      :attributes=> (onthefly_register? ? ['dn', self.attr_firstname, self.attr_lastname, self.attr_mail] : ['dn'])) do |entry|
       dn = entry.dn
-      attrs = [:firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
-               :lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
-               :mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
-               :auth_source_id => self.id ] if onthefly_register?
+      attrs = get_user_attributes_from_ldap_entry(entry) if onthefly_register?
+
     end
     return nil if dn.empty?
     logger.debug "DN found for #{login}: #{dn}" if logger && logger.debug?
@@ -89,6 +87,15 @@ class AuthSourceLdap < AuthSource
     options.merge!(:auth => { :method => :simple, :username => ldap_user, :password => ldap_password }) unless ldap_user.blank? && ldap_password.blank?
     Net::LDAP.new options
   end
+
+  def get_user_attributes_from_ldap_entry(entry)
+    [
+     :firstname => AuthSourceLdap.get_attr(entry, self.attr_firstname),
+     :lastname => AuthSourceLdap.get_attr(entry, self.attr_lastname),
+     :mail => AuthSourceLdap.get_attr(entry, self.attr_mail),
+     :auth_source_id => self.id
+    ]
+  end
   
   def self.get_attr(entry, attr_name)
     if !attr_name.blank?
index 16cc614fbda75bb5a221c3a27116713d29cbd79a..d9f13ac8222186c43ab372f41a78c8bdac999cb6 100644 (file)
@@ -52,19 +52,22 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
       context 'with a valid LDAP user' do
         should 'return the firstname user attributes' do
           response =  @auth.authenticate('example1','123456')
-          assert response
+          assert response.is_a?(Array), "An array was not returned"
+          assert response.first.present?, "No user data returned"
           assert_equal 'Example', response.first[:firstname]
         end
 
         should 'return the lastname user attributes' do
           response =  @auth.authenticate('example1','123456')
-          assert response
+          assert response.is_a?(Array), "An array was not returned"
+          assert response.first.present?, "No user data returned"
           assert_equal 'One', response.first[:lastname]
         end
 
         should 'return mail user attributes' do
           response =  @auth.authenticate('example1','123456')
-          assert response
+          assert response.is_a?(Array), "An array was not returned"
+          assert response.first.present?, "No user data returned"
           assert_equal 'example1@redmine.org', response.first[:mail]
         end
       end