net-ldap 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of net-ldap might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/History.rdoc +10 -0
- data/lib/net/ber.rb +34 -4
- data/lib/net/ldap.rb +67 -52
- data/lib/net/ldap/connection.rb +9 -2
- data/lib/net/ldap/version.rb +1 -1
- data/net-ldap.gemspec +1 -1
- data/script/install-openldap +3 -0
- data/test/ber/test_ber.rb +9 -1
- data/test/integration/test_bind.rb +8 -0
- data/test/test_auth_adapter.rb +2 -1
- data/test/test_ldap.rb +6 -0
- data/test/test_ldap_connection.rb +24 -15
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 118306d8baee26a65edeee4386ce94d9e23368a0
|
4
|
+
data.tar.gz: cff58ab35eeb9b18408c02f3aa7543c3a2bf5576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b0ed9d7079b989a6b239aa29a56c7ceb5731c0261b34ed6a2ff87181223bd49b3c56046becf06973a00189dc59d01f34bcd58738266b977b2101040d4d25945
|
7
|
+
data.tar.gz: a96783427d959ee0bb7e685a215e379d48bf3730f56f1dd7e3167cce10277a934361905b9d2964b4de4be46976f7904a13fe05f96d44580ceb953dc1e93b0847
|
data/.travis.yml
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.9.3
|
4
3
|
- 2.0.0
|
5
4
|
- 2.1
|
6
5
|
- 2.2
|
@@ -13,6 +12,9 @@ rvm:
|
|
13
12
|
env:
|
14
13
|
- INTEGRATION=openldap
|
15
14
|
|
15
|
+
before_install:
|
16
|
+
- gem update bundler
|
17
|
+
|
16
18
|
install:
|
17
19
|
- if [ "$INTEGRATION" = "openldap" ]; then sudo script/install-openldap; fi
|
18
20
|
- bundle install
|
data/History.rdoc
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== Net::LDAP 0.13.0
|
2
|
+
|
3
|
+
* Set a connect_timeout for the creation of a socket {#243}[https://github.com/ruby-ldap/ruby-net-ldap/pull/243]
|
4
|
+
* Update bundler before installing gems with bundler {#245}[https://github.com/ruby-ldap/ruby-net-ldap/pull/245]
|
5
|
+
* Net::LDAP#encryption accepts string {#239}[https://github.com/ruby-ldap/ruby-net-ldap/pull/239]
|
6
|
+
* Adds correct UTF-8 encoding to Net::BER::BerIdentifiedString {#242}[https://github.com/ruby-ldap/ruby-net-ldap/pull/242]
|
7
|
+
* Remove 2.3.0-preview since ruby-head already is included {#241}[https://github.com/ruby-ldap/ruby-net-ldap/pull/241]
|
8
|
+
* Drop support for ruby 1.9.3 {#240}[https://github.com/ruby-ldap/ruby-net-ldap/pull/240]
|
9
|
+
* Fixed capitalization of StartTLSError {#234}[https://github.com/ruby-ldap/ruby-net-ldap/pull/234]
|
10
|
+
|
1
11
|
=== Net::LDAP 0.12.1
|
2
12
|
|
3
13
|
* Whitespace formatting cleanup {#236}[https://github.com/ruby-ldap/ruby-net-ldap/pull/236]
|
data/lib/net/ber.rb
CHANGED
@@ -293,13 +293,43 @@ end
|
|
293
293
|
|
294
294
|
##
|
295
295
|
# A String object with a BER identifier attached.
|
296
|
+
#
|
296
297
|
class Net::BER::BerIdentifiedString < String
|
297
298
|
attr_accessor :ber_identifier
|
299
|
+
|
300
|
+
# The binary data provided when parsing the result of the LDAP search
|
301
|
+
# has the encoding 'ASCII-8BIT' (which is basically 'BINARY', or 'unknown').
|
302
|
+
#
|
303
|
+
# This is the kind of a backtrace showing how the binary `data` comes to
|
304
|
+
# BerIdentifiedString.new(data):
|
305
|
+
#
|
306
|
+
# @conn.read_ber(syntax)
|
307
|
+
# -> StringIO.new(self).read_ber(syntax), i.e. included from module
|
308
|
+
# -> Net::BER::BERParser.read_ber(syntax)
|
309
|
+
# -> (private)Net::BER::BERParser.parse_ber_object(syntax, id, data)
|
310
|
+
#
|
311
|
+
# In the `#parse_ber_object` method `data`, according to its OID, is being
|
312
|
+
# 'casted' to one of the Net::BER:BerIdentifiedXXX classes.
|
313
|
+
#
|
314
|
+
# As we are using LDAP v3 we can safely assume that the data is encoded
|
315
|
+
# in UTF-8 and therefore the only thing to be done when instantiating is to
|
316
|
+
# switch the encoding from 'ASCII-8BIT' to 'UTF-8'.
|
317
|
+
#
|
318
|
+
# Unfortunately, there are some ActiveDirectory specific attributes
|
319
|
+
# (like `objectguid`) that should remain binary (do they really?).
|
320
|
+
# Using the `#valid_encoding?` we can trap this cases. Special cases like
|
321
|
+
# Japanese, Korean, etc. encodings might also profit from this. However
|
322
|
+
# I have no clue how this encodings function.
|
298
323
|
def initialize args
|
299
|
-
super
|
300
|
-
|
301
|
-
|
302
|
-
|
324
|
+
super
|
325
|
+
#
|
326
|
+
# Check the encoding of the newly created String and set the encoding
|
327
|
+
# to 'UTF-8' (NOTE: we do NOT change the bytes, but only set the
|
328
|
+
# encoding to 'UTF-8').
|
329
|
+
current_encoding = encoding
|
330
|
+
if current_encoding == Encoding::BINARY
|
331
|
+
force_encoding('UTF-8')
|
332
|
+
force_encoding(current_encoding) unless valid_encoding?
|
303
333
|
end
|
304
334
|
end
|
305
335
|
end
|
data/lib/net/ldap.rb
CHANGED
@@ -79,6 +79,14 @@ Net::LDAP::AuthAdapter.register(:sasl, Net::LDAP::AuthAdapter::Sasl)
|
|
79
79
|
#
|
80
80
|
# p ldap.get_operation_result
|
81
81
|
#
|
82
|
+
# === Setting connect timeout
|
83
|
+
#
|
84
|
+
# By default, Net::LDAP uses TCP sockets with a connection timeout of 5 seconds.
|
85
|
+
#
|
86
|
+
# This value can be tweaked passing the :connect_timeout parameter.
|
87
|
+
# i.e.
|
88
|
+
# ldap = Net::LDAP.new ...,
|
89
|
+
# :connect_timeout => 3
|
82
90
|
#
|
83
91
|
# == A Brief Introduction to LDAP
|
84
92
|
#
|
@@ -461,11 +469,52 @@ class Net::LDAP
|
|
461
469
|
# call to #search, that value will override any treebase value you give
|
462
470
|
# here.
|
463
471
|
# * :encryption => specifies the encryption to be used in communicating
|
464
|
-
# with the LDAP server. The value
|
465
|
-
# parameters,
|
466
|
-
#
|
467
|
-
#
|
468
|
-
#
|
472
|
+
# with the LDAP server. The value must be a Hash containing additional
|
473
|
+
# parameters, which consists of two keys:
|
474
|
+
# method: - :simple_tls or :start_tls
|
475
|
+
# options: - Hash of options for that method
|
476
|
+
# The :simple_tls encryption method encrypts <i>all</i> communications
|
477
|
+
# with the LDAP server. It completely establishes SSL/TLS encryption with
|
478
|
+
# the LDAP server before any LDAP-protocol data is exchanged. There is no
|
479
|
+
# plaintext negotiation and no special encryption-request controls are
|
480
|
+
# sent to the server. <i>The :simple_tls option is the simplest, easiest
|
481
|
+
# way to encrypt communications between Net::LDAP and LDAP servers.</i>
|
482
|
+
# It's intended for cases where you have an implicit level of trust in the
|
483
|
+
# authenticity of the LDAP server. No validation of the LDAP server's SSL
|
484
|
+
# certificate is performed. This means that :simple_tls will not produce
|
485
|
+
# errors if the LDAP server's encryption certificate is not signed by a
|
486
|
+
# well-known Certification Authority. If you get communications or
|
487
|
+
# protocol errors when using this option, check with your LDAP server
|
488
|
+
# administrator. Pay particular attention to the TCP port you are
|
489
|
+
# connecting to. It's impossible for an LDAP server to support plaintext
|
490
|
+
# LDAP communications and <i>simple TLS</i> connections on the same port.
|
491
|
+
# The standard TCP port for unencrypted LDAP connections is 389, but the
|
492
|
+
# standard port for simple-TLS encrypted connections is 636. Be sure you
|
493
|
+
# are using the correct port.
|
494
|
+
#
|
495
|
+
# The :start_tls like the :simple_tls encryption method also encrypts all
|
496
|
+
# communcations with the LDAP server. With the exception that it operates
|
497
|
+
# over the standard TCP port.
|
498
|
+
#
|
499
|
+
# In order to verify certificates and enable other TLS options, the
|
500
|
+
# :tls_options hash can be passed alongside :simple_tls or :start_tls.
|
501
|
+
# This hash contains any options that can be passed to
|
502
|
+
# OpenSSL::SSL::SSLContext#set_params(). The most common options passed
|
503
|
+
# should be OpenSSL::SSL::SSLContext::DEFAULT_PARAMS, or the :ca_file option,
|
504
|
+
# which contains a path to a Certificate Authority file (PEM-encoded).
|
505
|
+
#
|
506
|
+
# Example for a default setup without custom settings:
|
507
|
+
# {
|
508
|
+
# :method => :simple_tls,
|
509
|
+
# :tls_options => OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
|
510
|
+
# }
|
511
|
+
#
|
512
|
+
# Example for specifying a CA-File and only allowing TLSv1.1 connections:
|
513
|
+
#
|
514
|
+
# {
|
515
|
+
# :method => :start_tls,
|
516
|
+
# :tls_options => { :ca_file => "/etc/cafile.pem", :ssl_version => "TLSv1_1" }
|
517
|
+
# }
|
469
518
|
# * :force_no_page => Set to true to prevent paged results even if your
|
470
519
|
# server says it supports them. This is a fix for MS Active Directory
|
471
520
|
# * :instrumentation_service => An object responsible for instrumenting
|
@@ -482,7 +531,8 @@ class Net::LDAP
|
|
482
531
|
@auth = args[:auth] || DefaultAuth
|
483
532
|
@base = args[:base] || DefaultTreebase
|
484
533
|
@force_no_page = args[:force_no_page] || DefaultForceNoPage
|
485
|
-
encryption args[:encryption] # may be nil
|
534
|
+
@encryption = args[:encryption] # may be nil
|
535
|
+
@connect_timeout = args[:connect_timeout]
|
486
536
|
|
487
537
|
if pr = @auth[:password] and pr.respond_to?(:call)
|
488
538
|
@auth[:password] = pr.call
|
@@ -546,52 +596,16 @@ class Net::LDAP
|
|
546
596
|
# additional capabilities are added, more configuration values will be
|
547
597
|
# added here.
|
548
598
|
#
|
549
|
-
#
|
550
|
-
#
|
551
|
-
# the LDAP server before any LDAP-protocol data is exchanged. There is no
|
552
|
-
# plaintext negotiation and no special encryption-request controls are
|
553
|
-
# sent to the server. <i>The :simple_tls option is the simplest, easiest
|
554
|
-
# way to encrypt communications between Net::LDAP and LDAP servers.</i>
|
555
|
-
# It's intended for cases where you have an implicit level of trust in the
|
556
|
-
# authenticity of the LDAP server. No validation of the LDAP server's SSL
|
557
|
-
# certificate is performed. This means that :simple_tls will not produce
|
558
|
-
# errors if the LDAP server's encryption certificate is not signed by a
|
559
|
-
# well-known Certification Authority. If you get communications or
|
560
|
-
# protocol errors when using this option, check with your LDAP server
|
561
|
-
# administrator. Pay particular attention to the TCP port you are
|
562
|
-
# connecting to. It's impossible for an LDAP server to support plaintext
|
563
|
-
# LDAP communications and <i>simple TLS</i> connections on the same port.
|
564
|
-
# The standard TCP port for unencrypted LDAP connections is 389, but the
|
565
|
-
# standard port for simple-TLS encrypted connections is 636. Be sure you
|
566
|
-
# are using the correct port.
|
567
|
-
#
|
568
|
-
# The :start_tls like the :simple_tls encryption method also encrypts all
|
569
|
-
# communcations with the LDAP server. With the exception that it operates
|
570
|
-
# over the standard TCP port.
|
571
|
-
#
|
572
|
-
# In order to verify certificates and enable other TLS options, the
|
573
|
-
# :tls_options hash can be passed alongside :simple_tls or :start_tls.
|
574
|
-
# This hash contains any options that can be passed to
|
575
|
-
# OpenSSL::SSL::SSLContext#set_params(). The most common options passed
|
576
|
-
# should be OpenSSL::SSL::SSLContext::DEFAULT_PARAMS, or the :ca_file option,
|
577
|
-
# which contains a path to a Certificate Authority file (PEM-encoded).
|
578
|
-
#
|
579
|
-
# Example for a default setup without custom settings:
|
580
|
-
# {
|
581
|
-
# :method => :simple_tls,
|
582
|
-
# :tls_options => OpenSSL::SSL::SSLContext::DEFAULT_PARAMS
|
583
|
-
# }
|
584
|
-
#
|
585
|
-
# Example for specifying a CA-File and only allowing TLSv1.1 connections:
|
586
|
-
#
|
587
|
-
# {
|
588
|
-
# :method => :start_tls,
|
589
|
-
# :tls_options => { :ca_file => "/etc/cafile.pem", :ssl_version => "TLSv1_1" }
|
590
|
-
# }
|
599
|
+
# This method is deprecated.
|
600
|
+
#
|
591
601
|
def encryption(args)
|
592
|
-
|
602
|
+
warn "Deprecation warning: please give :encryption option as a Hash to Net::LDAP.new"
|
603
|
+
return if args.nil?
|
604
|
+
return @encryption = args if args.is_a? Hash
|
605
|
+
|
606
|
+
case method = args.to_sym
|
593
607
|
when :simple_tls, :start_tls
|
594
|
-
args = { :method =>
|
608
|
+
args = { :method => method, :tls_options => {} }
|
595
609
|
end
|
596
610
|
@encryption = args
|
597
611
|
end
|
@@ -1242,8 +1256,9 @@ class Net::LDAP
|
|
1242
1256
|
:port => @port,
|
1243
1257
|
:hosts => @hosts,
|
1244
1258
|
:encryption => @encryption,
|
1245
|
-
:instrumentation_service => @instrumentation_service
|
1246
|
-
|
1259
|
+
:instrumentation_service => @instrumentation_service,
|
1260
|
+
:connect_timeout => @connect_timeout
|
1261
|
+
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Net::LDAP::ConnectionRefusedError => e
|
1247
1262
|
@result = {
|
1248
1263
|
:resultCode => 52,
|
1249
1264
|
:errorMessage => ResultStrings[ResultCodeUnavailable]
|
data/lib/net/ldap/connection.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
class Net::LDAP::Connection #:nodoc:
|
4
4
|
include Net::LDAP::Instrumentation
|
5
5
|
|
6
|
+
# Seconds before failing for socket connect timeout
|
7
|
+
DefaultConnectTimeout = 5
|
8
|
+
|
6
9
|
LdapVersion = 3
|
7
10
|
MaxSaslChallenges = 10
|
8
11
|
|
@@ -31,10 +34,14 @@ class Net::LDAP::Connection #:nodoc:
|
|
31
34
|
hosts = server[:hosts]
|
32
35
|
encryption = server[:encryption]
|
33
36
|
|
37
|
+
socket_opts = {
|
38
|
+
connect_timeout: server[:connect_timeout] || DefaultConnectTimeout
|
39
|
+
}
|
40
|
+
|
34
41
|
errors = []
|
35
42
|
hosts.each do |host, port|
|
36
43
|
begin
|
37
|
-
prepare_socket(server.merge(socket:
|
44
|
+
prepare_socket(server.merge(socket: Socket.tcp(host, port, socket_opts)))
|
38
45
|
return
|
39
46
|
rescue Net::LDAP::Error, SocketError, SystemCallError,
|
40
47
|
OpenSSL::SSL::SSLError => e
|
@@ -130,7 +137,7 @@ class Net::LDAP::Connection #:nodoc:
|
|
130
137
|
if pdu.result_code.zero?
|
131
138
|
@conn = self.class.wrap_with_ssl(@conn, args[:tls_options])
|
132
139
|
else
|
133
|
-
raise Net::LDAP::
|
140
|
+
raise Net::LDAP::StartTLSError, "start_tls failed: #{pdu.result_code}"
|
134
141
|
end
|
135
142
|
else
|
136
143
|
raise Net::LDAP::EncMethodUnsupportedError, "unsupported encryption method #{args[:method]}"
|
data/lib/net/ldap/version.rb
CHANGED
data/net-ldap.gemspec
CHANGED
@@ -26,7 +26,7 @@ the most recent LDAP RFCs (4510-4519, plutions of 4520-4532).}
|
|
26
26
|
s.homepage = %q{http://github.com/ruby-ldap/ruby-net-ldap}
|
27
27
|
s.rdoc_options = ["--main", "README.rdoc"]
|
28
28
|
s.require_paths = ["lib"]
|
29
|
-
s.required_ruby_version = ">=
|
29
|
+
s.required_ruby_version = ">= 2.0.0"
|
30
30
|
s.summary = %q{Net::LDAP for Ruby (also called net-ldap) implements client access for the Lightweight Directory Access Protocol (LDAP), an IETF standard protocol for accessing distributed directory services}
|
31
31
|
|
32
32
|
s.add_development_dependency("flexmock", "~> 1.3")
|
data/script/install-openldap
CHANGED
@@ -109,4 +109,7 @@ chgrp ssl-cert /etc/ssl/private/ldap01_slapd_key.pem
|
|
109
109
|
chmod g+r /etc/ssl/private/ldap01_slapd_key.pem
|
110
110
|
chmod o-r /etc/ssl/private/ldap01_slapd_key.pem
|
111
111
|
|
112
|
+
# Drop packets on a secondary port used to specific timeout tests
|
113
|
+
iptables -A OUTPUT -p tcp -j DROP --dport 8389
|
114
|
+
|
112
115
|
service slapd restart
|
data/test/ber/test_ber.rb
CHANGED
@@ -135,7 +135,15 @@ class TestBERIdentifiedString < Test::Unit::TestCase
|
|
135
135
|
assert_equal "UTF-8", bis.encoding.name
|
136
136
|
end
|
137
137
|
|
138
|
-
def
|
138
|
+
def test_umlaut_data_in_utf8
|
139
|
+
data = "Müller".force_encoding("UTF-8")
|
140
|
+
bis = Net::BER::BerIdentifiedString.new(data)
|
141
|
+
|
142
|
+
assert bis.valid_encoding?, "should be a valid encoding"
|
143
|
+
assert_equal "UTF-8", bis.encoding.name
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_utf8_data_in_utf8
|
139
147
|
data = ["e4b8ad"].pack("H*").force_encoding("UTF-8")
|
140
148
|
bis = Net::BER::BerIdentifiedString.new(data)
|
141
149
|
|
@@ -5,6 +5,14 @@ class TestBindIntegration < LDAPIntegrationTestCase
|
|
5
5
|
assert @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: "passworD1"), @ldap.get_operation_result.inspect
|
6
6
|
end
|
7
7
|
|
8
|
+
def test_bind_timeout
|
9
|
+
@ldap.port = 8389
|
10
|
+
error = assert_raise Net::LDAP::Error do
|
11
|
+
@ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: "passworD1")
|
12
|
+
end
|
13
|
+
assert_equal('Connection timed out - user specified timeout', error.message)
|
14
|
+
end
|
15
|
+
|
8
16
|
def test_bind_anonymous_fail
|
9
17
|
refute @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: ""), @ldap.get_operation_result.inspect
|
10
18
|
|
data/test/test_auth_adapter.rb
CHANGED
@@ -2,7 +2,8 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class TestAuthAdapter < Test::Unit::TestCase
|
4
4
|
def test_undefined_auth_adapter
|
5
|
-
flexmock(
|
5
|
+
flexmock(Socket).should_receive(:tcp).ordered.with('ldap.example.com', 379, { connect_timeout: 5 }).once.and_return(nil)
|
6
|
+
|
6
7
|
conn = Net::LDAP::Connection.new(host: 'ldap.example.com', port: 379)
|
7
8
|
assert_raise Net::LDAP::AuthMethodUnsupportedError, "Unsupported auth method (foo)" do
|
8
9
|
conn.bind(method: :foo)
|
data/test/test_ldap.rb
CHANGED
@@ -64,4 +64,10 @@ class TestLDAPInstrumentation < Test::Unit::TestCase
|
|
64
64
|
@subject.auth "joe_user", password
|
65
65
|
assert_not_include(@subject.inspect, password)
|
66
66
|
end
|
67
|
+
|
68
|
+
def test_encryption
|
69
|
+
enc = @subject.encryption('start_tls')
|
70
|
+
|
71
|
+
assert_equal enc[:method], :start_tls
|
72
|
+
end
|
67
73
|
end
|
@@ -15,8 +15,8 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
15
15
|
['test2.mocked.com', 636],
|
16
16
|
['test3.mocked.com', 636],
|
17
17
|
]
|
18
|
-
flexmock(
|
19
|
-
flexmock(
|
18
|
+
flexmock(Socket).should_receive(:tcp).ordered.with(*hosts[0], { connect_timeout: 5 }).once.and_return(nil)
|
19
|
+
flexmock(Socket).should_receive(:tcp).ordered.never
|
20
20
|
Net::LDAP::Connection.new(:hosts => hosts)
|
21
21
|
end
|
22
22
|
|
@@ -26,9 +26,9 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
26
26
|
['test2.mocked.com', 636],
|
27
27
|
['test3.mocked.com', 636],
|
28
28
|
]
|
29
|
-
flexmock(
|
30
|
-
flexmock(
|
31
|
-
flexmock(
|
29
|
+
flexmock(Socket).should_receive(:tcp).ordered.with(*hosts[0], { connect_timeout: 5 }).once.and_raise(SocketError)
|
30
|
+
flexmock(Socket).should_receive(:tcp).ordered.with(*hosts[1], { connect_timeout: 5 }).once.and_return(nil)
|
31
|
+
flexmock(Socket).should_receive(:tcp).ordered.never
|
32
32
|
Net::LDAP::Connection.new(:hosts => hosts)
|
33
33
|
end
|
34
34
|
|
@@ -38,17 +38,17 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
38
38
|
['test2.mocked.com', 636],
|
39
39
|
['test3.mocked.com', 636],
|
40
40
|
]
|
41
|
-
flexmock(
|
42
|
-
flexmock(
|
43
|
-
flexmock(
|
44
|
-
flexmock(
|
41
|
+
flexmock(Socket).should_receive(:tcp).ordered.with(*hosts[0], { connect_timeout: 5 }).once.and_raise(SocketError)
|
42
|
+
flexmock(Socket).should_receive(:tcp).ordered.with(*hosts[1], { connect_timeout: 5 }).once.and_raise(SocketError)
|
43
|
+
flexmock(Socket).should_receive(:tcp).ordered.with(*hosts[2], { connect_timeout: 5 }).once.and_raise(SocketError)
|
44
|
+
flexmock(Socket).should_receive(:tcp).ordered.never
|
45
45
|
assert_raise Net::LDAP::ConnectionError do
|
46
46
|
Net::LDAP::Connection.new(:hosts => hosts)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_result_for_connection_failed_is_set
|
51
|
-
flexmock(
|
51
|
+
flexmock(Socket).should_receive(:tcp).and_raise(Errno::ECONNREFUSED)
|
52
52
|
|
53
53
|
ldap_client = Net::LDAP.new(host: '127.0.0.1', port: 12345)
|
54
54
|
|
@@ -67,14 +67,14 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_blocked_port
|
70
|
-
flexmock(
|
70
|
+
flexmock(Socket).should_receive(:tcp).and_raise(SocketError)
|
71
71
|
assert_raise Net::LDAP::Error do
|
72
72
|
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_connection_refused
|
77
|
-
flexmock(
|
77
|
+
flexmock(Socket).should_receive(:tcp).and_raise(Errno::ECONNREFUSED)
|
78
78
|
stderr = capture_stderr do
|
79
79
|
assert_raise Net::LDAP::ConnectionRefusedError do
|
80
80
|
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
|
@@ -83,9 +83,18 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
83
83
|
assert_equal("Deprecation warning: Net::LDAP::ConnectionRefused will be deprecated. Use Errno::ECONNREFUSED instead.\n", stderr)
|
84
84
|
end
|
85
85
|
|
86
|
+
def test_connection_timedout
|
87
|
+
flexmock(Socket).should_receive(:tcp).and_raise(Errno::ETIMEDOUT)
|
88
|
+
stderr = capture_stderr do
|
89
|
+
assert_raise Net::LDAP::Error do
|
90
|
+
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
86
95
|
def test_raises_unknown_exceptions
|
87
96
|
error = Class.new(StandardError)
|
88
|
-
flexmock(
|
97
|
+
flexmock(Socket).should_receive(:tcp).and_raise(error)
|
89
98
|
assert_raise error do
|
90
99
|
Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
|
91
100
|
end
|
@@ -328,7 +337,7 @@ class TestLDAPConnectionErrors < Test::Unit::TestCase
|
|
328
337
|
def setup
|
329
338
|
@tcp_socket = flexmock(:connection)
|
330
339
|
@tcp_socket.should_receive(:write)
|
331
|
-
flexmock(
|
340
|
+
flexmock(Socket).should_receive(:tcp).and_return(@tcp_socket)
|
332
341
|
@connection = Net::LDAP::Connection.new(:host => 'test.mocked.com', :port => 636)
|
333
342
|
end
|
334
343
|
|
@@ -357,7 +366,7 @@ class TestLDAPConnectionInstrumentation < Test::Unit::TestCase
|
|
357
366
|
def setup
|
358
367
|
@tcp_socket = flexmock(:connection)
|
359
368
|
@tcp_socket.should_receive(:write)
|
360
|
-
flexmock(
|
369
|
+
flexmock(Socket).should_receive(:tcp).and_return(@tcp_socket)
|
361
370
|
|
362
371
|
@service = MockInstrumentationService.new
|
363
372
|
@connection = Net::LDAP::Connection.new \
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ldap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Cianfrocca
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date:
|
16
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: flexmock
|
@@ -203,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
203
203
|
requirements:
|
204
204
|
- - ">="
|
205
205
|
- !ruby/object:Gem::Version
|
206
|
-
version:
|
206
|
+
version: 2.0.0
|
207
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
208
|
requirements:
|
209
209
|
- - ">="
|
@@ -253,3 +253,4 @@ test_files:
|
|
253
253
|
- test/testdata.ldif
|
254
254
|
- testserver/ldapserver.rb
|
255
255
|
- testserver/testdata.ldif
|
256
|
+
has_rdoc:
|