From 60741b3e1c025f50e93e6f5847716ed930b319a0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 1 Mar 2012 16:26:10 +0000 Subject: Adds an optional LDAP filter (#1060). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9044 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/unit/auth_source_ldap_test.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'test') diff --git a/test/unit/auth_source_ldap_test.rb b/test/unit/auth_source_ldap_test.rb index 5dc532f23..55e1479b8 100644 --- a/test/unit/auth_source_ldap_test.rb +++ b/test/unit/auth_source_ldap_test.rb @@ -18,6 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) class AuthSourceLdapTest < ActiveSupport::TestCase + include Redmine::I18n fixtures :auth_sources def setup @@ -44,6 +45,18 @@ class AuthSourceLdapTest < ActiveSupport::TestCase assert_equal 389, a.port end + def test_filter_should_be_validated + set_language_if_valid 'en' + + a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :attr_login => 'sn') + a.filter = "(mail=*@redmine.org" + assert !a.valid? + assert_equal "is invalid", a.errors[:filter].to_s + + a.filter = "(mail=*@redmine.org)" + assert a.valid? + end + if ldap_configured? context '#authenticate' do setup do @@ -83,6 +96,23 @@ class AuthSourceLdapTest < ActiveSupport::TestCase end end + context 'without filter' do + should 'return any user' do + assert @auth.authenticate('example1','123456') + assert @auth.authenticate('edavis', '123456') + end + end + + context 'with filter' do + setup do + @auth.filter = "(mail=*@redmine.org)" + end + + should 'return user who matches the filter only' do + assert @auth.authenticate('example1','123456') + assert_nil @auth.authenticate('edavis', '123456') + end + end end else puts '(Test LDAP server not configured)' -- cgit v1.2.3