Skip to content

Commit f16a4ff

Browse files
committed
Add failing test for Net::LDAP#open with nested queries
The nested query should match "user2", but with Net::LDAP#open, we see: <"user3"> expected but was <"user2">. And likewise with the outer search: <["user1", "user2"]> expected but was <["user1", "user3"]>. What's happening is that the nested query is being sent after the server has already sent more data to be read for the outer search, so when the inner search reads, it gets that result. And when it comes time for the outer search to handle the second results, it gets reads the next result off the wire, the result of the inner search. I was also able to get an infinite loop just by *always* performing an inner search instead of only searching on the first result.
1 parent 74fe070 commit f16a4ff

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/integration/test_open.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,32 @@ def test_binds_with_open
2020

2121
assert_equal 1, events.size
2222
end
23+
24+
def test_nested_search_without_open
25+
entries = []
26+
nested_entry = nil
27+
28+
@ldap.search(filter: "(|(uid=user1)(uid=user2))", base: "ou=People,dc=rubyldap,dc=com") do |entry|
29+
entries << entry.uid.first
30+
nested_entry ||= @ldap.search(filter: "uid=user3", base: "ou=People,dc=rubyldap,dc=com").first
31+
end
32+
33+
assert_equal "user3", nested_entry.uid.first
34+
assert_equal %w(user1 user2), entries
35+
end
36+
37+
def test_nested_search_with_open
38+
entries = []
39+
nested_entry = nil
40+
41+
@ldap.open do
42+
@ldap.search(filter: "(|(uid=user1)(uid=user2))", base: "ou=People,dc=rubyldap,dc=com") do |entry|
43+
entries << entry.uid.first
44+
nested_entry ||= @ldap.search(filter: "uid=user3", base: "ou=People,dc=rubyldap,dc=com").first
45+
end
46+
end
47+
48+
assert_equal "user3", nested_entry.uid.first
49+
assert_equal %w(user1 user2), entries
50+
end
2351
end

0 commit comments

Comments
 (0)