Mercurial > hg > soundsoftware-site
comparison test/unit/auth_source_ldap_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
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 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
19 | 19 |
20 class AuthSourceLdapTest < ActiveSupport::TestCase | 20 class AuthSourceLdapTest < ActiveSupport::TestCase |
21 include Redmine::I18n | |
21 fixtures :auth_sources | 22 fixtures :auth_sources |
22 | 23 |
23 def setup | 24 def setup |
24 end | 25 end |
25 | 26 |
42 :attr_firstname => 'givenName ') | 43 :attr_firstname => 'givenName ') |
43 assert a.save | 44 assert a.save |
44 assert_equal 389, a.port | 45 assert_equal 389, a.port |
45 end | 46 end |
46 | 47 |
48 def test_filter_should_be_validated | |
49 set_language_if_valid 'en' | |
50 | |
51 a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :attr_login => 'sn') | |
52 a.filter = "(mail=*@redmine.org" | |
53 assert !a.valid? | |
54 assert_include "LDAP filter is invalid", a.errors.full_messages | |
55 | |
56 a.filter = "(mail=*@redmine.org)" | |
57 assert a.valid? | |
58 end | |
59 | |
47 if ldap_configured? | 60 if ldap_configured? |
48 context '#authenticate' do | 61 context '#authenticate' do |
49 setup do | 62 setup do |
50 @auth = AuthSourceLdap.find(1) | 63 @auth = AuthSourceLdap.find(1) |
64 @auth.update_attribute :onthefly_register, true | |
51 end | 65 end |
52 | 66 |
53 context 'with a valid LDAP user' do | 67 context 'with a valid LDAP user' do |
54 should 'return the user attributes' do | 68 should 'return the user attributes' do |
55 attributes = @auth.authenticate('example1','123456') | 69 attributes = @auth.authenticate('example1','123456') |
80 should 'return nil' do | 94 should 'return nil' do |
81 assert_equal nil, @auth.authenticate('edavis','') | 95 assert_equal nil, @auth.authenticate('edavis','') |
82 end | 96 end |
83 end | 97 end |
84 | 98 |
99 context 'without filter' do | |
100 should 'return any user' do | |
101 assert @auth.authenticate('example1','123456') | |
102 assert @auth.authenticate('edavis', '123456') | |
103 end | |
104 end | |
105 | |
106 context 'with filter' do | |
107 setup do | |
108 @auth.filter = "(mail=*@redmine.org)" | |
109 end | |
110 | |
111 should 'return user who matches the filter only' do | |
112 assert @auth.authenticate('example1','123456') | |
113 assert_nil @auth.authenticate('edavis', '123456') | |
114 end | |
115 end | |
116 end | |
117 | |
118 def test_authenticate_should_timeout | |
119 auth_source = AuthSourceLdap.find(1) | |
120 auth_source.timeout = 1 | |
121 def auth_source.initialize_ldap_con(*args); sleep(5); end | |
122 | |
123 assert_raise AuthSourceTimeoutException do | |
124 auth_source.authenticate 'example1', '123456' | |
125 end | |
85 end | 126 end |
86 else | 127 else |
87 puts '(Test LDAP server not configured)' | 128 puts '(Test LDAP server not configured)' |
88 end | 129 end |
89 end | 130 end |