Skip to content

Fix size option for ldap.search method #140

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 7 commits into from
Oct 21, 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
13 changes: 12 additions & 1 deletion lib/net/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,18 @@ def search(args = {})
end

if return_result_set
(!@result.nil? && @result.result_code == 0) ? result_set : nil
unless @result.nil?
case @result.result_code
when ResultStrings.key("Success")
# everything good
result_set
when ResultStrings.key("Size Limit Exceeded")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to use a constant in this case. I didn't see one already defined, though, but I'd be in favor of one (or a few) for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 We can define the constants, and then define ResultStrings values in terms of those constants.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, not to contradict @jch, we can worry about this in a followup PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

# LDAP: Size limit exceeded
# This happens when we use size option and results are truncated
# Still we need to return user results
result_set
end
end
else
@result.success?
end
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_return_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_time_limit_exceeded
end

def test_size_limit_exceeded
refute @ldap.search(filter: "cn=sizeLimitExceeded", base: "ou=Retcodes,dc=rubyldap,dc=com")
@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
12 changes: 12 additions & 0 deletions test/integration/test_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ def test_search_without_result
assert result
refute_equal entries, result
end

def test_search_with_size
entries = []

result = @ldap.search(filter: "(uid=user1)", base: "dc=rubyldap,dc=com", size: 1) do |entry|
assert_kind_of Net::LDAP::Entry, entry
entries << entry
end

refute entries.empty?
assert_equal entries, result
end
end
17 changes: 17 additions & 0 deletions test/test_ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@ def test_instrument_search
assert_equal [entry], payload[:result]
assert_equal "(uid=user1)", payload[:filter]
end

def test_instrument_search_with_size
events = @service.subscribe "search.net_ldap"

flexmock(@connection).should_receive(:bind).and_return(flexmock(:bind_result, :result_code => 0))
flexmock(@connection).should_receive(:search).with(Hash, Proc).
yields(entry = Net::LDAP::Entry.new("uid=user1,ou=users,dc=example,dc=com")).
and_return(flexmock(:search_result, :success? => true, :result_code => 4))

refute_nil @subject.search(:filter => "(uid=user1)", :size => 1)

payload, result = events.pop
assert_equal [entry], result
assert_equal [entry], payload[:result]
assert_equal "(uid=user1)", payload[:filter]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include an assertion with the size in the payload.

assert_equal result.size, payload[:size]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 perfect!

end
end