Skip to content

Implement search timeout parameter #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/net/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ def open
# Net::LDAP::SearchScope_WholeSubtree. Default is WholeSubtree.)
# * :size (an integer indicating the maximum number of search entries to
# return. Default is zero, which signifies no limit.)
# * :time (an integer restricting the maximum time in seconds allowed for a search. Default is zero, no time limit RFC 4511 4.5.1.5)
# * :deref (one of: Net::LDAP::DerefAliases_Never, Net::LDAP::DerefAliases_Search,
# Net::LDAP::DerefAliases_Find, Net::LDAP::DerefAliases_Always. Default is Never.)
#
Expand Down Expand Up @@ -683,8 +684,8 @@ def search(args = {})
when ResultStrings.key("Success")
# everything good
result_set
when ResultStrings.key("Size Limit Exceeded")
# LDAP: Size limit exceeded
when ResultStrings.key("Size Limit Exceeded"), ResultStrings.key("Time Limit Exceeded")
# LDAP: Size/Time limit exceeded
# This happens when we use size option and results are truncated
# Still we need to return user results
result_set
Expand Down
7 changes: 5 additions & 2 deletions lib/net/ldap/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ def search(args = nil)

# limiting, paging, sorting
# size: https://tools.ietf.org/html/rfc4511#section-4.5.1.4
# time: https://tools.ietf.org/html/rfc4511#section-4.5.1.5
size = args[:size].to_i
time = args[:time].to_i
paged = args[:paged_searches_supported]
sort = args.fetch(:sort_controls, false)

Expand Down Expand Up @@ -421,7 +423,8 @@ def search(args = nil)
filter: filter,
base: base,
scope: scope,
limit: size,
size: size,
time: time,
sort: sort,
referrals: refs,
deref: deref,
Expand All @@ -443,7 +446,7 @@ def search(args = nil)
scope.to_ber_enumerated,
deref.to_ber_enumerated,
query_limit.to_ber, # size limit
0.to_ber,
time.to_ber,
attrs_only.to_ber,
filter.to_ber,
ber_attrs.to_ber_sequence
Expand Down
4 changes: 2 additions & 2 deletions test/integration/test_return_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def test_protocol_error
end

def test_time_limit_exceeded
refute @ldap.search(filter: "cn=timeLimitExceeded", base: "ou=Retcodes,dc=rubyldap,dc=com")
assert @ldap.search(filter: "cn=timeLimitExceeded", base: "ou=Retcodes,dc=rubyldap,dc=com")
assert result = @ldap.get_operation_result

assert_equal 3, result.code
assert_equal Net::LDAP::ResultStrings[3], result.message
end

def test_size_limit_exceeded
@ldap.search(filter: "cn=sizeLimitExceeded", base: "ou=Retcodes,dc=rubyldap,dc=com")
assert @ldap.search(filter: "cn=sizeLimitExceeded", base: "ou=Retcodes,dc=rubyldap,dc=com")
assert result = @ldap.get_operation_result

assert_equal 4, result.code
Expand Down
14 changes: 14 additions & 0 deletions test/integration/test_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ def test_search_without_result
refute_equal entries, result
end

def test_search_timeout
entries = []
events = @service.subscribe "search.net_ldap_connection"

result = @ldap.search(base: "dc=rubyldap,dc=com", time: 5) do |entry|
assert_kind_of Net::LDAP::Entry, entry
entries << entry
end

payload, _ = events.pop
assert_equal 5, payload[:time]
assert_equal entries, result
end

def test_search_with_size
entries = []

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy