net-ldap 0.14.0 → 0.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -2
- data/.rubocop_todo.yml +343 -219
- data/.travis.yml +27 -3
- data/CONTRIBUTING.md +1 -1
- data/History.rdoc +21 -0
- data/README.rdoc +10 -7
- data/Rakefile +1 -1
- data/lib/net-ldap.rb +1 -1
- data/lib/net/ber.rb +5 -6
- data/lib/net/ber/ber_parser.rb +3 -3
- data/lib/net/ber/core_ext.rb +6 -6
- data/lib/net/ldap.rb +65 -55
- data/lib/net/ldap/auth_adapter/gss_spnego.rb +2 -2
- data/lib/net/ldap/auth_adapter/sasl.rb +4 -2
- data/lib/net/ldap/auth_adapter/simple.rb +1 -1
- data/lib/net/ldap/connection.rb +58 -35
- data/lib/net/ldap/dataset.rb +2 -2
- data/lib/net/ldap/dn.rb +13 -14
- data/lib/net/ldap/entry.rb +5 -6
- data/lib/net/ldap/error.rb +1 -0
- data/lib/net/ldap/filter.rb +10 -3
- data/lib/net/ldap/instrumentation.rb +2 -2
- data/lib/net/ldap/password.rb +3 -5
- data/lib/net/ldap/pdu.rb +1 -1
- data/lib/net/ldap/version.rb +1 -1
- data/lib/net/snmp.rb +1 -1
- data/net-ldap.gemspec +4 -4
- data/script/ldap-docker +12 -0
- data/test/ber/test_ber.rb +1 -1
- data/test/fixtures/ca/docker-ca.pem +18 -0
- data/test/fixtures/{openldap/retcode.ldif → ldif/06-retcode.ldif} +7 -8
- data/test/fixtures/ldif/50-seed.ldif +374 -0
- data/test/integration/test_add.rb +1 -3
- data/test/integration/test_ber.rb +2 -2
- data/test/integration/test_bind.rb +193 -14
- data/test/integration/test_delete.rb +1 -3
- data/test/integration/test_open.rb +10 -11
- data/test/integration/test_password_modify.rb +29 -16
- data/test/integration/test_return_codes.rb +12 -4
- data/test/integration/test_search.rb +8 -8
- data/test/test_dn.rb +2 -3
- data/test/test_entry.rb +3 -2
- data/test/test_filter_parser.rb +5 -0
- data/test/test_helper.rb +12 -5
- data/test/test_ldap.rb +5 -5
- data/test/test_ldap_connection.rb +47 -35
- data/test/test_ldif.rb +13 -13
- data/test/test_password.rb +2 -2
- data/test/test_snmp.rb +4 -5
- data/test/test_ssl_ber.rb +7 -3
- data/testserver/ldapserver.rb +13 -22
- metadata +17 -26
- data/script/install-openldap +0 -115
- data/test/fixtures/cacert.pem +0 -20
- data/test/fixtures/openldap/memberof.ldif +0 -33
- data/test/fixtures/openldap/slapd.conf.ldif +0 -67
- data/test/fixtures/seed.ldif +0 -374
- data/test/support/vm/openldap/README.md +0 -32
- data/test/support/vm/openldap/Vagrantfile +0 -33
@@ -4,7 +4,7 @@ class TestSearchIntegration < LDAPIntegrationTestCase
|
|
4
4
|
def test_search
|
5
5
|
entries = []
|
6
6
|
|
7
|
-
result = @ldap.search(base: "dc=
|
7
|
+
result = @ldap.search(base: "dc=example,dc=org") do |entry|
|
8
8
|
assert_kind_of Net::LDAP::Entry, entry
|
9
9
|
entries << entry
|
10
10
|
end
|
@@ -16,7 +16,7 @@ class TestSearchIntegration < LDAPIntegrationTestCase
|
|
16
16
|
def test_search_without_result
|
17
17
|
entries = []
|
18
18
|
|
19
|
-
result = @ldap.search(base: "dc=
|
19
|
+
result = @ldap.search(base: "dc=example,dc=org", return_result: false) do |entry|
|
20
20
|
assert_kind_of Net::LDAP::Entry, entry
|
21
21
|
entries << entry
|
22
22
|
end
|
@@ -26,24 +26,24 @@ class TestSearchIntegration < LDAPIntegrationTestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_search_filter_string
|
29
|
-
entries = @ldap.search(base: "dc=
|
29
|
+
entries = @ldap.search(base: "dc=example,dc=org", filter: "(uid=user1)")
|
30
30
|
assert_equal 1, entries.size
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_search_filter_object
|
34
34
|
filter = Net::LDAP::Filter.eq("uid", "user1") | Net::LDAP::Filter.eq("uid", "user2")
|
35
|
-
entries = @ldap.search(base: "dc=
|
35
|
+
entries = @ldap.search(base: "dc=example,dc=org", filter: filter)
|
36
36
|
assert_equal 2, entries.size
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_search_constrained_attributes
|
40
|
-
entry = @ldap.search(base: "uid=user1,ou=People,dc=
|
40
|
+
entry = @ldap.search(base: "uid=user1,ou=People,dc=example,dc=org", attributes: ["cn", "sn"]).first
|
41
41
|
assert_equal [:cn, :dn, :sn], entry.attribute_names.sort # :dn is always included
|
42
42
|
assert_empty entry[:mail]
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_search_attributes_only
|
46
|
-
entry = @ldap.search(base: "uid=user1,ou=People,dc=
|
46
|
+
entry = @ldap.search(base: "uid=user1,ou=People,dc=example,dc=org", attributes_only: true).first
|
47
47
|
|
48
48
|
assert_empty entry[:cn], "unexpected attribute value: #{entry[:cn]}"
|
49
49
|
end
|
@@ -52,7 +52,7 @@ class TestSearchIntegration < LDAPIntegrationTestCase
|
|
52
52
|
entries = []
|
53
53
|
events = @service.subscribe "search.net_ldap_connection"
|
54
54
|
|
55
|
-
result = @ldap.search(base: "dc=
|
55
|
+
result = @ldap.search(base: "dc=example,dc=org", time: 5) do |entry|
|
56
56
|
assert_kind_of Net::LDAP::Entry, entry
|
57
57
|
entries << entry
|
58
58
|
end
|
@@ -66,7 +66,7 @@ class TestSearchIntegration < LDAPIntegrationTestCase
|
|
66
66
|
def test_search_with_size
|
67
67
|
entries = []
|
68
68
|
|
69
|
-
result = @ldap.search(base: "dc=
|
69
|
+
result = @ldap.search(base: "dc=example,dc=org", size: 1) do |entry|
|
70
70
|
assert_kind_of Net::LDAP::Entry, entry
|
71
71
|
entries << entry
|
72
72
|
end
|
data/test/test_dn.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative 'test_helper'
|
2
|
-
|
2
|
+
require_relative '../lib/net/ldap/dn'
|
3
3
|
|
4
4
|
class TestDN < Test::Unit::TestCase
|
5
5
|
def test_escape
|
@@ -26,7 +26,6 @@ class TestDN < Test::Unit::TestCase
|
|
26
26
|
assert_equal ['1.23.4', '#A3B4D5', 'ou', 'Company'], dn.to_a
|
27
27
|
end
|
28
28
|
|
29
|
-
# TODO: raise a more specific exception than RuntimeError
|
30
29
|
def test_bad_input_raises_error
|
31
30
|
[
|
32
31
|
'cn=James,',
|
@@ -38,7 +37,7 @@ class TestDN < Test::Unit::TestCase
|
|
38
37
|
'd1.2=Value',
|
39
38
|
].each do |input|
|
40
39
|
dn = Net::LDAP::DN.new(input)
|
41
|
-
assert_raises(
|
40
|
+
assert_raises(Net::LDAP::InvalidDNError) { dn.to_a }
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
data/test/test_entry.rb
CHANGED
@@ -47,7 +47,8 @@ class TestEntryLDIF < Test::Unit::TestCase
|
|
47
47
|
%Q{dn: something
|
48
48
|
foo: foo
|
49
49
|
barAttribute: bar
|
50
|
-
}
|
50
|
+
},
|
51
|
+
)
|
51
52
|
end
|
52
53
|
|
53
54
|
def test_attribute
|
@@ -59,7 +60,7 @@ barAttribute: bar
|
|
59
60
|
@entry.foo = 'bar'
|
60
61
|
assert_equal ['bar'], @entry.foo
|
61
62
|
|
62
|
-
@entry.fOo= 'baz'
|
63
|
+
@entry.fOo = 'baz'
|
63
64
|
assert_equal ['baz'], @entry.foo
|
64
65
|
end
|
65
66
|
end
|
data/test/test_filter_parser.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
2
3
|
require_relative 'test_helper'
|
3
4
|
|
4
5
|
class TestFilterParser < Test::Unit::TestCase
|
@@ -21,4 +22,8 @@ class TestFilterParser < Test::Unit::TestCase
|
|
21
22
|
def test_colons
|
22
23
|
assert_kind_of Net::LDAP::Filter, Net::LDAP::Filter::FilterParser.parse("(ismemberof=cn=edu:berkeley:app:calmessages:deans,ou=campus groups,dc=berkeley,dc=edu)")
|
23
24
|
end
|
25
|
+
|
26
|
+
def test_attr_tag
|
27
|
+
assert_kind_of Net::LDAP::Filter, Net::LDAP::Filter::FilterParser.parse("(mail;primary=jane@example.org)")
|
28
|
+
end
|
24
29
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Add 'lib' to load path.
|
2
2
|
require 'test/unit'
|
3
|
-
|
3
|
+
require_relative '../lib/net/ldap'
|
4
4
|
require 'flexmock/test_unit'
|
5
5
|
|
6
6
|
# Whether integration tests should be run.
|
@@ -14,10 +14,18 @@ CA_FILE =
|
|
14
14
|
if File.exist?("/etc/ssl/certs/cacert.pem")
|
15
15
|
"/etc/ssl/certs/cacert.pem"
|
16
16
|
else
|
17
|
-
File.expand_path("fixtures/
|
17
|
+
File.expand_path("fixtures/ca/docker-ca.pem", File.dirname(__FILE__))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
BIND_CREDS = {
|
22
|
+
method: :simple,
|
23
|
+
username: "cn=admin,dc=example,dc=org",
|
24
|
+
password: "admin",
|
25
|
+
}.freeze
|
26
|
+
|
27
|
+
TLS_OPTS = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS.merge({}).freeze
|
28
|
+
|
21
29
|
if RUBY_VERSION < "2.0"
|
22
30
|
class String
|
23
31
|
def b
|
@@ -57,10 +65,9 @@ class LDAPIntegrationTestCase < Test::Unit::TestCase
|
|
57
65
|
@ldap = Net::LDAP.new \
|
58
66
|
host: ENV.fetch('INTEGRATION_HOST', 'localhost'),
|
59
67
|
port: ENV.fetch('INTEGRATION_PORT', 389),
|
60
|
-
|
61
|
-
admin_password: 'passworD1',
|
62
|
-
search_domains: %w(dc=rubyldap,dc=com),
|
68
|
+
search_domains: %w(dc=example,dc=org),
|
63
69
|
uid: 'uid',
|
64
70
|
instrumentation_service: @service
|
71
|
+
@ldap.authenticate "cn=admin,dc=example,dc=org", "admin"
|
65
72
|
end
|
66
73
|
end
|
data/test/test_ldap.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
class TestLDAPInstrumentation < Test::Unit::TestCase
|
4
4
|
# Fake Net::LDAP::Connection for testing
|
@@ -94,7 +94,7 @@ class TestLDAPInstrumentation < Test::Unit::TestCase
|
|
94
94
|
|
95
95
|
def test_normalize_encryption_symbol
|
96
96
|
enc = @subject.send(:normalize_encryption, :start_tls)
|
97
|
-
assert_equal enc,
|
97
|
+
assert_equal enc, :method => :start_tls, :tls_options => {}
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_normalize_encryption_nil
|
@@ -104,11 +104,11 @@ class TestLDAPInstrumentation < Test::Unit::TestCase
|
|
104
104
|
|
105
105
|
def test_normalize_encryption_string
|
106
106
|
enc = @subject.send(:normalize_encryption, 'start_tls')
|
107
|
-
assert_equal enc,
|
107
|
+
assert_equal enc, :method => :start_tls, :tls_options => {}
|
108
108
|
end
|
109
109
|
|
110
110
|
def test_normalize_encryption_hash
|
111
|
-
enc = @subject.send(:normalize_encryption,
|
112
|
-
assert_equal enc,
|
111
|
+
enc = @subject.send(:normalize_encryption, :method => :start_tls, :tls_options => { :foo => :bar })
|
112
|
+
assert_equal enc, :method => :start_tls, :tls_options => { :foo => :bar }
|
113
113
|
end
|
114
114
|
end
|
@@ -16,9 +16,7 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
16
16
|
class FakeTCPSocket
|
17
17
|
def initialize(host, port, socket_opts = {})
|
18
18
|
status, error = host.split(".")
|
19
|
-
if status == "fail"
|
20
|
-
raise Object.const_get(error)
|
21
|
-
end
|
19
|
+
raise Object.const_get(error) if status == "fail"
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
@@ -97,7 +95,7 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
97
95
|
|
98
96
|
def test_connection_timeout
|
99
97
|
connection = Net::LDAP::Connection.new(:host => "fail.Errno::ETIMEDOUT", :port => 636, :socket_class => FakeTCPSocket)
|
100
|
-
|
98
|
+
capture_stderr do
|
101
99
|
assert_raise Net::LDAP::Error do
|
102
100
|
connection.socket
|
103
101
|
end
|
@@ -126,7 +124,7 @@ class TestLDAPConnection < Test::Unit::TestCase
|
|
126
124
|
end
|
127
125
|
|
128
126
|
def test_modify_ops_replace
|
129
|
-
args = { :operations =>[[:replace, "mail", "testuser@example.com"]] }
|
127
|
+
args = { :operations => [[:replace, "mail", "testuser@example.com"]] }
|
130
128
|
result = Net::LDAP::Connection.modify_ops(args[:operations])
|
131
129
|
expected = ["0#\n\x01\x020\x1E\x04\x04mail1\x16\x04\x14testuser@example.com"]
|
132
130
|
assert_equal(expected, result)
|
@@ -193,9 +191,9 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
193
191
|
result2 = make_message(2)
|
194
192
|
|
195
193
|
mock = flexmock("socket")
|
196
|
-
mock.should_receive(:read_ber)
|
197
|
-
|
198
|
-
|
194
|
+
mock.should_receive(:read_ber)
|
195
|
+
.and_return(result1)
|
196
|
+
.and_return(result2)
|
199
197
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
200
198
|
|
201
199
|
assert result = conn.queued_read(2)
|
@@ -208,9 +206,9 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
208
206
|
result2 = make_message(2, app_tag: Net::LDAP::PDU::ModifyResponse)
|
209
207
|
|
210
208
|
mock = flexmock("socket")
|
211
|
-
mock.should_receive(:read_ber)
|
212
|
-
|
213
|
-
|
209
|
+
mock.should_receive(:read_ber)
|
210
|
+
.and_return(result1)
|
211
|
+
.and_return(result2)
|
214
212
|
mock.should_receive(:write)
|
215
213
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
216
214
|
|
@@ -229,9 +227,9 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
229
227
|
result2 = make_message(2, app_tag: Net::LDAP::PDU::AddResponse)
|
230
228
|
|
231
229
|
mock = flexmock("socket")
|
232
|
-
mock.should_receive(:read_ber)
|
233
|
-
|
234
|
-
|
230
|
+
mock.should_receive(:read_ber)
|
231
|
+
.and_return(result1)
|
232
|
+
.and_return(result2)
|
235
233
|
mock.should_receive(:write)
|
236
234
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
237
235
|
|
@@ -247,9 +245,9 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
247
245
|
result2 = make_message(2, app_tag: Net::LDAP::PDU::ModifyRDNResponse)
|
248
246
|
|
249
247
|
mock = flexmock("socket")
|
250
|
-
mock.should_receive(:read_ber)
|
251
|
-
|
252
|
-
|
248
|
+
mock.should_receive(:read_ber)
|
249
|
+
.and_return(result1)
|
250
|
+
.and_return(result2)
|
253
251
|
mock.should_receive(:write)
|
254
252
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
255
253
|
|
@@ -268,9 +266,9 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
268
266
|
result2 = make_message(2, app_tag: Net::LDAP::PDU::DeleteResponse)
|
269
267
|
|
270
268
|
mock = flexmock("socket")
|
271
|
-
mock.should_receive(:read_ber)
|
272
|
-
|
273
|
-
|
269
|
+
mock.should_receive(:read_ber)
|
270
|
+
.and_return(result1)
|
271
|
+
.and_return(result2)
|
274
272
|
mock.should_receive(:write)
|
275
273
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
276
274
|
|
@@ -286,13 +284,13 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
286
284
|
result2 = make_message(2, app_tag: Net::LDAP::PDU::ExtendedResponse)
|
287
285
|
|
288
286
|
mock = flexmock("socket")
|
289
|
-
mock.should_receive(:read_ber)
|
290
|
-
|
291
|
-
|
287
|
+
mock.should_receive(:read_ber)
|
288
|
+
.and_return(result1)
|
289
|
+
.and_return(result2)
|
292
290
|
mock.should_receive(:write)
|
293
291
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
294
|
-
flexmock(Net::LDAP::Connection).should_receive(:wrap_with_ssl).with(mock, {})
|
295
|
-
|
292
|
+
flexmock(Net::LDAP::Connection).should_receive(:wrap_with_ssl).with(mock, {}, nil)
|
293
|
+
.and_return(mock)
|
296
294
|
|
297
295
|
conn.next_msgid # simulates ongoing query
|
298
296
|
|
@@ -305,9 +303,9 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
305
303
|
result2 = make_message(2, app_tag: Net::LDAP::PDU::BindResult)
|
306
304
|
|
307
305
|
mock = flexmock("socket")
|
308
|
-
mock.should_receive(:read_ber)
|
309
|
-
|
310
|
-
|
306
|
+
mock.should_receive(:read_ber)
|
307
|
+
.and_return(result1)
|
308
|
+
.and_return(result2)
|
311
309
|
mock.should_receive(:write)
|
312
310
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
313
311
|
|
@@ -316,7 +314,8 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
316
314
|
assert result = conn.bind(
|
317
315
|
method: :simple,
|
318
316
|
username: "uid=user1,ou=People,dc=rubyldap,dc=com",
|
319
|
-
password: "passworD1"
|
317
|
+
password: "passworD1",
|
318
|
+
)
|
320
319
|
assert result.success?
|
321
320
|
assert_equal 2, result.message_id
|
322
321
|
end
|
@@ -326,9 +325,9 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
326
325
|
result2 = make_message(2, app_tag: Net::LDAP::PDU::BindResult)
|
327
326
|
|
328
327
|
mock = flexmock("socket")
|
329
|
-
mock.should_receive(:read_ber)
|
330
|
-
|
331
|
-
|
328
|
+
mock.should_receive(:read_ber)
|
329
|
+
.and_return(result1)
|
330
|
+
.and_return(result2)
|
332
331
|
mock.should_receive(:write)
|
333
332
|
conn = Net::LDAP::Connection.new(:socket => mock)
|
334
333
|
|
@@ -338,10 +337,23 @@ class TestLDAPConnectionSocketReads < Test::Unit::TestCase
|
|
338
337
|
method: :sasl,
|
339
338
|
mechanism: "fake",
|
340
339
|
initial_credential: "passworD1",
|
341
|
-
challenge_response: flexmock("challenge proc")
|
340
|
+
challenge_response: flexmock("challenge proc"),
|
341
|
+
)
|
342
342
|
assert result.success?
|
343
343
|
assert_equal 2, result.message_id
|
344
344
|
end
|
345
|
+
|
346
|
+
def test_invalid_pdu_type
|
347
|
+
options = {
|
348
|
+
code: Net::LDAP::ResultCodeSuccess,
|
349
|
+
matched_dn: "",
|
350
|
+
error_message: "",
|
351
|
+
}
|
352
|
+
ber = Net::BER::BerIdentifiedArray.new([options[:code], options[:matched_dn], options[:error_message]])
|
353
|
+
assert_raise Net::LDAP::PDU::Error do
|
354
|
+
Net::LDAP::PDU.new([0, ber])
|
355
|
+
end
|
356
|
+
end
|
345
357
|
end
|
346
358
|
|
347
359
|
class TestLDAPConnectionErrors < Test::Unit::TestCase
|
@@ -471,8 +483,8 @@ class TestLDAPConnectionInstrumentation < Test::Unit::TestCase
|
|
471
483
|
search_result_ber = Net::BER::BerIdentifiedArray.new([Net::LDAP::ResultCodeSuccess, "", ""])
|
472
484
|
search_result_ber.ber_identifier = Net::LDAP::PDU::SearchResult
|
473
485
|
search_result = [1, search_result_ber]
|
474
|
-
@tcp_socket.should_receive(:read_ber).and_return(search_data)
|
475
|
-
|
486
|
+
@tcp_socket.should_receive(:read_ber).and_return(search_data)
|
487
|
+
.and_return(search_result)
|
476
488
|
|
477
489
|
events = @service.subscribe "search.net_ldap_connection"
|
478
490
|
unread = @service.subscribe "search_messages_unread.net_ldap_connection"
|
data/test/test_ldif.rb
CHANGED
@@ -22,46 +22,46 @@ class TestLdif < Test::Unit::TestCase
|
|
22
22
|
def test_ldif_with_comments
|
23
23
|
str = ["# Hello from LDIF-land", "# This is an unterminated comment"]
|
24
24
|
io = StringIO.new(str[0] + "\r\n" + str[1])
|
25
|
-
ds = Net::LDAP::Dataset
|
25
|
+
ds = Net::LDAP::Dataset.read_ldif(io)
|
26
26
|
assert_equal(str, ds.comments)
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_ldif_with_password
|
30
30
|
psw = "goldbricks"
|
31
|
-
hashed_psw = "{SHA}" + Base64
|
31
|
+
hashed_psw = "{SHA}" + Base64.encode64(Digest::SHA1.digest(psw)).chomp
|
32
32
|
|
33
|
-
ldif_encoded = Base64
|
34
|
-
ds = Net::LDAP::Dataset
|
33
|
+
ldif_encoded = Base64.encode64(hashed_psw).chomp
|
34
|
+
ds = Net::LDAP::Dataset.read_ldif(StringIO.new("dn: Goldbrick\r\nuserPassword:: #{ldif_encoded}\r\n\r\n"))
|
35
35
|
recovered_psw = ds["Goldbrick"][:userpassword].shift
|
36
36
|
assert_equal(hashed_psw, recovered_psw)
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_ldif_with_continuation_lines
|
40
|
-
ds = Net::LDAP::Dataset
|
40
|
+
ds = Net::LDAP::Dataset.read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n"))
|
41
41
|
assert_equal(true, ds.key?("abcdefghijklmn"))
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_ldif_with_continuation_lines_and_extra_whitespace
|
45
|
-
ds1 = Net::LDAP::Dataset
|
45
|
+
ds1 = Net::LDAP::Dataset.read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n"))
|
46
46
|
assert_equal(true, ds1.key?("abcdefg hijklmn"))
|
47
|
-
ds2 = Net::LDAP::Dataset
|
47
|
+
ds2 = Net::LDAP::Dataset.read_ldif(StringIO.new("dn: abcdefg\r\n hij klmn\r\n\r\n"))
|
48
48
|
assert_equal(true, ds2.key?("abcdefghij klmn"))
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_ldif_tab_is_not_continuation
|
52
|
-
ds = Net::LDAP::Dataset
|
52
|
+
ds = Net::LDAP::Dataset.read_ldif(StringIO.new("dn: key\r\n\tnotcontinued\r\n\r\n"))
|
53
53
|
assert_equal(true, ds.key?("key"))
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_ldif_with_base64_dn
|
57
57
|
str = "dn:: Q049QmFzZTY0IGRuIHRlc3QsT1U9VGVzdCxPVT1Vbml0cyxEQz1leGFtcGxlLERDPWNvbQ==\r\n\r\n"
|
58
|
-
ds = Net::LDAP::Dataset
|
58
|
+
ds = Net::LDAP::Dataset.read_ldif(StringIO.new(str))
|
59
59
|
assert_equal(true, ds.key?("CN=Base64 dn test,OU=Test,OU=Units,DC=example,DC=com"))
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_ldif_with_base64_dn_and_continuation_lines
|
63
63
|
str = "dn:: Q049QmFzZTY0IGRuIHRlc3Qgd2l0aCBjb250aW51YXRpb24gbGluZSxPVT1UZXN0LE9VPVVua\r\n XRzLERDPWV4YW1wbGUsREM9Y29t\r\n\r\n"
|
64
|
-
ds = Net::LDAP::Dataset
|
64
|
+
ds = Net::LDAP::Dataset.read_ldif(StringIO.new(str))
|
65
65
|
assert_equal(true, ds.key?("CN=Base64 dn test with continuation line,OU=Test,OU=Units,DC=example,DC=com"))
|
66
66
|
end
|
67
67
|
|
@@ -69,14 +69,14 @@ class TestLdif < Test::Unit::TestCase
|
|
69
69
|
# to verify the content.
|
70
70
|
def test_ldif
|
71
71
|
File.open(TestLdifFilename, "r") do |f|
|
72
|
-
ds = Net::LDAP::Dataset
|
72
|
+
ds = Net::LDAP::Dataset.read_ldif(f)
|
73
73
|
assert_equal(13, ds.length)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
# Must test folded lines and base64-encoded lines as well as normal ones.
|
78
78
|
def test_to_ldif
|
79
|
-
data = File.open(TestLdifFilename, "rb"
|
79
|
+
data = File.open(TestLdifFilename, "rb", &:read)
|
80
80
|
io = StringIO.new(data)
|
81
81
|
|
82
82
|
# added .lines to turn to array because 1.9 doesn't have
|
@@ -84,7 +84,7 @@ class TestLdif < Test::Unit::TestCase
|
|
84
84
|
entries = data.lines.grep(/^dn:\s*/) { $'.chomp }
|
85
85
|
dn_entries = entries.dup
|
86
86
|
|
87
|
-
ds = Net::LDAP::Dataset
|
87
|
+
ds = Net::LDAP::Dataset.read_ldif(io) do |type, value|
|
88
88
|
case type
|
89
89
|
when :dn
|
90
90
|
assert_equal(dn_entries.first, value)
|