Skip to content
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

Set operation result if LDAP server is not accessible #232

Merged
merged 1 commit into from Nov 6, 2015
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
6 changes: 6 additions & 0 deletions lib/net/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1243,5 +1243,11 @@ def new_connection
:hosts => @hosts,
:encryption => @encryption,
:instrumentation_service => @instrumentation_service
rescue Errno::ECONNREFUSED, Net::LDAP::ConnectionRefusedError => e
@result = {
:resultCode => 52,
:errorMessage => ResultStrings[ResultCodeUnavailable]
}
raise e
end
end # class LDAP
13 changes: 13 additions & 0 deletions test/test_ldap_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ def test_list_of_hosts_with_all_hosts_failure
end
end

def test_result_for_connection_failed_is_set
flexmock(TCPSocket).should_receive(:new).and_raise(Errno::ECONNREFUSED)

ldap_client = Net::LDAP.new(host: '127.0.0.1', port: 12345)

assert_raise Net::LDAP::ConnectionRefusedError do
Copy link
Author

Choose a reason for hiding this comment

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

I'm not not a reqular user of minitest. If there's a better approach to handle errors, I'm open to fix this. begin; rescue; end didn't work for that use case.

ldap_client.bind(method: :simple, username: 'asdf', password: 'asdf')
end

assert_equal(ldap_client.get_operation_result.code, 52)
assert_equal(ldap_client.get_operation_result.message, 'Unavailable')
end

def test_unresponsive_host
assert_raise Net::LDAP::Error do
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
Expand Down