Skip to content

Commit 0bce7b2

Browse files
committed
Instrument Net::LDAP::Connection#bind
1 parent 8098c5f commit 0bce7b2

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

lib/net/ldap.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,15 +1324,17 @@ def next_msgid
13241324
end
13251325

13261326
def bind(auth)
1327-
meth = auth[:method]
1328-
if [:simple, :anonymous, :anon].include?(meth)
1329-
bind_simple auth
1330-
elsif meth == :sasl
1331-
bind_sasl(auth)
1332-
elsif meth == :gss_spnego
1333-
bind_gss_spnego(auth)
1334-
else
1335-
raise Net::LDAP::LdapError, "Unsupported auth method (#{meth})"
1327+
instrument "bind.net_ldap_connection" do |payload|
1328+
payload[:method] = meth = auth[:method]
1329+
if [:simple, :anonymous, :anon].include?(meth)
1330+
bind_simple auth
1331+
elsif meth == :sasl
1332+
bind_sasl(auth)
1333+
elsif meth == :gss_spnego
1334+
bind_gss_spnego(auth)
1335+
else
1336+
raise Net::LDAP::LdapError, "Unsupported auth method (#{meth})"
1337+
end
13361338
end
13371339
end
13381340

spec/unit/ldap_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,23 @@
175175
result.should == read_result
176176
end
177177

178+
it "should publish a bind.net_ldap_connection event" do
179+
ber = Net::BER::BerIdentifiedArray.new([0, "", ""])
180+
ber.ber_identifier = Net::LDAP::PDU::BindResult
181+
bind_result = [2, ber]
182+
@tcp_socket.should_receive(:read_ber).and_return(bind_result)
183+
184+
events = @service.subscribe "bind.net_ldap_connection"
185+
186+
result = subject.bind(method: :anon)
187+
result.should be_success
188+
189+
# a read event
190+
payload, result = events.pop
191+
payload.should have_key(:result)
192+
result.should be_success
193+
end
194+
178195
it "should publish a search.net_ldap_connection event" do
179196
# search data
180197
search_data_ber = Net::BER::BerIdentifiedArray.new([2, [

0 commit comments

Comments
 (0)