diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index 8dca73c0..a38da759 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -874,7 +874,7 @@ def bind(auth = @auth) end end - @result.success? + @result.result_code == ResultCodeSuccess end end diff --git a/test/integration/test_bind.rb b/test/integration/test_bind.rb index 4a1a0194..f9cf8537 100644 --- a/test/integration/test_bind.rb +++ b/test/integration/test_bind.rb @@ -14,9 +14,8 @@ def test_bind_timeout error = assert_raise Net::LDAP::Error do @ldap.bind BIND_CREDS end - msgs = ['Operation timed out - user specified timeout', - 'Connection timed out - user specified timeout'] - assert_send([msgs, :include?, error.message]) + # Ruby 3.4+ appends " for host:port" to the message + assert_match(/\A(Operation|Connection) timed out - user specified timeout/, error.message) end def test_bind_anonymous_fail diff --git a/test/test_ldap.rb b/test/test_ldap.rb index 6c061475..47b139ca 100644 --- a/test/test_ldap.rb +++ b/test/test_ldap.rb @@ -48,6 +48,24 @@ def test_instrument_bind assert_equal bind_result, payload[:bind] end + def test_bind_requires_success_result_code + [Net::LDAP::ResultCodeSuccess, + Net::LDAP::ResultCodeReferral, + Net::LDAP::ResultCodeCompareFalse, + Net::LDAP::ResultCodeCompareTrue, + Net::LDAP::ResultCodeSaslBindInProgress, + Net::LDAP::ResultCodeInvalidCredentials].each do |code| + ber = Net::BER::BerIdentifiedArray.new([code, "", ""]) + ber.ber_identifier = Net::LDAP::PDU::BindResult + result = Net::LDAP::PDU.new([1, ber]) + @subject.connection = flexmock(:bind => result) + + assert_equal code == Net::LDAP::ResultCodeSuccess, @subject.bind, + "unexpected bind result for code #{code}" + assert_equal code, @subject.get_operation_result.code + end + end + def test_instrument_search events = @service.subscribe "search.net_ldap"