Skip to content

Commit 4bc667f

Browse files
author
blackhedd
committed
Implemented Net::LDAP::open
1 parent 36526cd commit 4bc667f

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

lib/net/ldap.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,8 @@ def initialize args
137137
# open
138138
#
139139
def LDAP::open args
140-
#ldap = LDAP.new args
141-
#ldap.connect
142-
#yield ldap
143-
#ldap.disconnect
140+
ldap = LDAP.new args
141+
ldap.open {|ldap1| yield ldap1 }
144142
end
145143

146144

@@ -149,12 +147,18 @@ def LDAP::open args
149147
# closed when the block completes. It's for executing multiple
150148
# LDAP operations without requiring a separate network connection
151149
# (and authentication) for each one.
152-
#
153-
#
150+
#--
151+
# First we make a connection and then a binding, but we don't
152+
# do anything with the bind results.
153+
# We then pass self to the caller's block, where he will execute
154+
# his LDAP operations. Of course they will all generate auth failures
155+
# if the bind was unsuccessful.
154156
def open
155-
conn = connect
157+
raise LdapError.new( "open already in progress" ) if @open_connection
158+
@open_connection = Connection.new( :host => @host, :port => @port )
159+
@open_connection.bind @auth
156160
yield self
157-
disconnect
161+
@open_connection.close
158162
end
159163

160164

tests/testldap.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,22 @@ def test_search_filters
154154

155155

156156
def test_open
157-
Net::LDAP.open( :host => @host, :port => @port, :auth => @auth ) {
158-
p "NO TESTS!!!"
157+
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth
158+
ldap.open {|ldap|
159+
10.times {
160+
rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" )
161+
assert_equal( 0, rc )
162+
}
163+
}
164+
end
165+
166+
167+
def test_ldap_open
168+
Net::LDAP.open( :host => @host, :port => @port, :auth => @auth ) {|ldap|
169+
10.times {
170+
rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" )
171+
assert_equal( 0, rc )
172+
}
159173
}
160174
end
161175

0 commit comments

Comments
 (0)