From 4bc667ffb29bbf590b5cf84752ff379637e809b3 Mon Sep 17 00:00:00 2001 From: blackhedd Date: Tue, 18 Apr 2006 21:11:33 +0000 Subject: [PATCH] Implemented Net::LDAP::open --- lib/net/ldap.rb | 20 ++++++++++++-------- tests/testldap.rb | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index d56fc33..17fe391 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -137,10 +137,8 @@ module Net # open # def LDAP::open args - #ldap = LDAP.new args - #ldap.connect - #yield ldap - #ldap.disconnect + ldap = LDAP.new args + ldap.open {|ldap1| yield ldap1 } end @@ -149,12 +147,18 @@ module Net # closed when the block completes. It's for executing multiple # LDAP operations without requiring a separate network connection # (and authentication) for each one. - # - # + #-- + # First we make a connection and then a binding, but we don't + # do anything with the bind results. + # We then pass self to the caller's block, where he will execute + # his LDAP operations. Of course they will all generate auth failures + # if the bind was unsuccessful. def open - conn = connect + raise LdapError.new( "open already in progress" ) if @open_connection + @open_connection = Connection.new( :host => @host, :port => @port ) + @open_connection.bind @auth yield self - disconnect + @open_connection.close end diff --git a/tests/testldap.rb b/tests/testldap.rb index e166442..9d9848a 100644 --- a/tests/testldap.rb +++ b/tests/testldap.rb @@ -154,8 +154,22 @@ class TestLdapClient < Test::Unit::TestCase def test_open - Net::LDAP.open( :host => @host, :port => @port, :auth => @auth ) { - p "NO TESTS!!!" + ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth + ldap.open {|ldap| + 10.times { + rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" ) + assert_equal( 0, rc ) + } + } + end + + + def test_ldap_open + Net::LDAP.open( :host => @host, :port => @port, :auth => @auth ) {|ldap| + 10.times { + rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" ) + assert_equal( 0, rc ) + } } end