@@ -0,0 +1,36 | |||
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2008 Jean-Philippe Lang | |
|
3 | # | |
|
4 | # This program is free software; you can redistribute it and/or | |
|
5 | # modify it under the terms of the GNU General Public License | |
|
6 | # as published by the Free Software Foundation; either version 2 | |
|
7 | # of the License, or (at your option) any later version. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
14 | # You should have received a copy of the GNU General Public License | |
|
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. | |
|
17 | ||
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
|
19 | ||
|
20 | class AuthSourceLdapTest < Test::Unit::TestCase | |
|
21 | ||
|
22 | def setup | |
|
23 | end | |
|
24 | ||
|
25 | def test_create | |
|
26 | a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName') | |
|
27 | assert a.save | |
|
28 | end | |
|
29 | ||
|
30 | def test_should_strip_ldap_attributes | |
|
31 | a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName', | |
|
32 | :attr_firstname => 'givenName ') | |
|
33 | assert a.save | |
|
34 | assert_equal 'givenName', a.reload.attr_firstname | |
|
35 | end | |
|
36 | end |
@@ -25,6 +25,8 class AuthSourceLdap < AuthSource | |||
|
25 | 25 | validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true |
|
26 | 26 | validates_numericality_of :port, :only_integer => true |
|
27 | 27 | |
|
28 | before_validation :strip_ldap_attributes | |
|
29 | ||
|
28 | 30 | def after_initialize |
|
29 | 31 | self.port = 389 if self.port == 0 |
|
30 | 32 | end |
@@ -71,7 +73,14 class AuthSourceLdap < AuthSource | |||
|
71 | 73 | "LDAP" |
|
72 | 74 | end |
|
73 | 75 | |
|
74 | private | |
|
76 | private | |
|
77 | ||
|
78 | def strip_ldap_attributes | |
|
79 | [:attr_login, :attr_firstname, :attr_lastname, :attr_mail].each do |attr| | |
|
80 | write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil? | |
|
81 | end | |
|
82 | end | |
|
83 | ||
|
75 | 84 | def initialize_ldap_con(ldap_user, ldap_password) |
|
76 | 85 | options = { :host => self.host, |
|
77 | 86 | :port => self.port, |
General Comments 0
You need to be logged in to leave comments.
Login now