net-ldap 0.8.0 → 0.9.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.

Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.travis.yml +19 -1
  4. data/CONTRIBUTING.md +54 -0
  5. data/Hacking.rdoc +2 -4
  6. data/History.rdoc +37 -0
  7. data/Manifest.txt +0 -4
  8. data/README.rdoc +8 -0
  9. data/Rakefile +1 -3
  10. data/lib/net/ber/core_ext.rb +5 -5
  11. data/lib/net/ber/core_ext/string.rb +7 -7
  12. data/lib/net/ber/core_ext/true_class.rb +2 -3
  13. data/lib/net/ldap.rb +134 -620
  14. data/lib/net/ldap/connection.rb +692 -0
  15. data/lib/net/ldap/dataset.rb +18 -4
  16. data/lib/net/ldap/entry.rb +1 -1
  17. data/lib/net/ldap/filter.rb +7 -7
  18. data/lib/net/ldap/password.rb +11 -11
  19. data/lib/net/ldap/pdu.rb +28 -4
  20. data/lib/net/ldap/version.rb +1 -1
  21. data/lib/net/snmp.rb +235 -241
  22. data/net-ldap.gemspec +7 -33
  23. data/script/install-openldap +47 -0
  24. data/script/package +7 -0
  25. data/script/release +16 -0
  26. data/test/ber/core_ext/test_array.rb +22 -0
  27. data/test/ber/core_ext/test_string.rb +25 -0
  28. data/test/ber/test_ber.rb +126 -0
  29. data/test/fixtures/openldap/memberof.ldif +33 -0
  30. data/test/fixtures/openldap/retcode.ldif +76 -0
  31. data/test/fixtures/openldap/slapd.conf.ldif +67 -0
  32. data/test/fixtures/seed.ldif +374 -0
  33. data/test/integration/test_add.rb +28 -0
  34. data/test/integration/test_ber.rb +30 -0
  35. data/test/integration/test_bind.rb +22 -0
  36. data/test/integration/test_delete.rb +31 -0
  37. data/test/integration/test_open.rb +88 -0
  38. data/test/integration/test_return_codes.rb +38 -0
  39. data/test/integration/test_search.rb +77 -0
  40. data/test/support/vm/openldap/.gitignore +1 -0
  41. data/test/support/vm/openldap/README.md +32 -0
  42. data/test/support/vm/openldap/Vagrantfile +33 -0
  43. data/test/test_dn.rb +44 -0
  44. data/test/test_entry.rb +62 -56
  45. data/test/test_filter.rb +98 -2
  46. data/test/test_filter_parser.rb +16 -0
  47. data/test/test_helper.rb +54 -0
  48. data/test/test_ldap.rb +60 -0
  49. data/test/test_ldap_connection.rb +382 -2
  50. data/test/test_ldif.rb +26 -1
  51. data/test/test_password.rb +3 -10
  52. data/test/test_rename.rb +2 -2
  53. data/test/test_search.rb +39 -0
  54. data/test/test_snmp.rb +1 -1
  55. data/test/test_ssl_ber.rb +40 -0
  56. metadata +70 -75
  57. data/.autotest +0 -11
  58. data/.gemtest +0 -0
  59. data/.rspec +0 -2
  60. data/autotest/discover.rb +0 -1
  61. data/spec/integration/ssl_ber_spec.rb +0 -39
  62. data/spec/spec.opts +0 -2
  63. data/spec/spec_helper.rb +0 -28
  64. data/spec/unit/ber/ber_spec.rb +0 -141
  65. data/spec/unit/ber/core_ext/array_spec.rb +0 -24
  66. data/spec/unit/ber/core_ext/string_spec.rb +0 -51
  67. data/spec/unit/ldap/dn_spec.rb +0 -80
  68. data/spec/unit/ldap/entry_spec.rb +0 -51
  69. data/spec/unit/ldap/filter_parser_spec.rb +0 -26
  70. data/spec/unit/ldap/filter_spec.rb +0 -115
  71. data/spec/unit/ldap/search_spec.rb +0 -49
  72. data/spec/unit/ldap_spec.rb +0 -223
  73. data/test/common.rb +0 -3
data/.autotest DELETED
@@ -1,11 +0,0 @@
1
- require 'rubygems'
2
- #require 'redgreen/autotest'
3
- require 'autotest/timestamp'
4
-
5
- Autotest.add_hook :initialize do |autotest|
6
- %w{.git .hg .DS_Store ._* tmp log doc}.each do |exception|
7
- autotest.add_exception(exception)
8
- end
9
- end
10
-
11
- # vim: syntax=ruby
data/.gemtest DELETED
File without changes
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --colour
2
- --format documentation
@@ -1 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'net/ldap'
4
- require 'timeout'
5
-
6
- describe "BER serialisation (SSL)" do
7
- # Transmits str to #to and reads it back from #from.
8
- #
9
- def transmit(str)
10
- Timeout::timeout(1) do
11
- to.write(str)
12
- to.close
13
-
14
- from.read
15
- end
16
- end
17
-
18
- attr_reader :to, :from
19
- before(:each) do
20
- @from, @to = IO.pipe
21
-
22
- # The production code operates on sockets, which do need #connect called
23
- # on them to work. Pipes are more robust for this test, so we'll skip
24
- # the #connect call since it fails.
25
- flexmock(OpenSSL::SSL::SSLSocket).
26
- new_instances.should_receive(:connect => nil)
27
-
28
- @to = Net::LDAP::Connection.wrap_with_ssl(to)
29
- @from = Net::LDAP::Connection.wrap_with_ssl(from)
30
- end
31
-
32
- it "should transmit strings" do
33
- transmit('foo').should == 'foo'
34
- end
35
- it "should correctly transmit numbers" do
36
- to.write 1234.to_ber
37
- from.read_ber.should == 1234
38
- end
39
- end
@@ -1,2 +0,0 @@
1
- --format specdoc
2
- --colour
@@ -1,28 +0,0 @@
1
- require 'net/ldap'
2
-
3
- RSpec.configure do |config|
4
- config.mock_with :flexmock
5
-
6
- def raw_string(s)
7
- # Conveniently, String#b only needs to be called when it exists
8
- s.respond_to?(:b) ? s.b : s
9
- end
10
- end
11
-
12
- class MockInstrumentationService
13
- def initialize
14
- @events = {}
15
- end
16
-
17
- def instrument(event, payload)
18
- result = yield(payload)
19
- @events[event] ||= []
20
- @events[event] << [payload, result]
21
- result
22
- end
23
-
24
- def subscribe(event)
25
- @events[event] ||= []
26
- @events[event]
27
- end
28
- end
@@ -1,141 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'net/ber'
4
- require 'net/ldap'
5
-
6
- describe "BER encoding of" do
7
-
8
- RSpec::Matchers.define :properly_encode_and_decode do
9
- match do |given|
10
- given.to_ber.read_ber.should == given
11
- end
12
- end
13
-
14
- context "arrays" do
15
- it "should properly encode/decode []" do
16
- [].should properly_encode_and_decode
17
- end
18
- it "should properly encode/decode [1,2,3]" do
19
- ary = [1,2,3]
20
- encoded_ary = ary.map { |el| el.to_ber }.to_ber
21
-
22
- encoded_ary.read_ber.should == ary
23
- end
24
- end
25
- context "booleans" do
26
- it "should encode true" do
27
- true.to_ber.should == "\x01\x01\x01"
28
- end
29
- it "should encode false" do
30
- false.to_ber.should == "\x01\x01\x00"
31
- end
32
- end
33
- context "numbers" do
34
- # Sample based
35
- {
36
- 0 => raw_string("\x02\x01\x00"),
37
- 1 => raw_string("\x02\x01\x01"),
38
- 127 => raw_string("\x02\x01\x7F"),
39
- 128 => raw_string("\x02\x01\x80"),
40
- 255 => raw_string("\x02\x01\xFF"),
41
- 256 => raw_string("\x02\x02\x01\x00"),
42
- 65535 => raw_string("\x02\x02\xFF\xFF"),
43
- 65536 => raw_string("\x02\x03\x01\x00\x00"),
44
- 16_777_215 => raw_string("\x02\x03\xFF\xFF\xFF"),
45
- 0x01000000 => raw_string("\x02\x04\x01\x00\x00\x00"),
46
- 0x3FFFFFFF => raw_string("\x02\x04\x3F\xFF\xFF\xFF"),
47
- 0x4FFFFFFF => raw_string("\x02\x04\x4F\xFF\xFF\xFF"),
48
-
49
- # Some odd samples...
50
- 5 => raw_string("\002\001\005"),
51
- 500 => raw_string("\002\002\001\364"),
52
- 50_000 => raw_string("\x02\x02\xC3P"),
53
- 5_000_000_000 => raw_string("\002\005\001*\005\362\000")
54
- }.each do |number, expected_encoding|
55
- it "should encode #{number} as #{expected_encoding.inspect}" do
56
- number.to_ber.should == expected_encoding
57
- end
58
- end
59
-
60
- # Round-trip encoding: This is mostly to be sure to cover Bignums well.
61
- context "when decoding with #read_ber" do
62
- it "should correctly handle powers of two" do
63
- 100.times do |p|
64
- n = 2 << p
65
-
66
- n.should properly_encode_and_decode
67
- end
68
- end
69
- it "should correctly handle powers of ten" do
70
- 100.times do |p|
71
- n = 5 * 10**p
72
-
73
- n.should properly_encode_and_decode
74
- end
75
- end
76
- end
77
- end
78
- if "Ruby 1.9".respond_to?(:encoding)
79
- context "strings" do
80
- it "should properly encode UTF-8 strings" do
81
- "\u00e5".force_encoding("UTF-8").to_ber.should ==
82
- raw_string("\x04\x02\xC3\xA5")
83
- end
84
- it "should properly encode strings encodable as UTF-8" do
85
- "teststring".encode("US-ASCII").to_ber.should == "\x04\nteststring"
86
- end
87
- it "should properly encode binary data strings using to_ber_bin" do
88
- # This is used for searching for GUIDs in Active Directory
89
- ["6a31b4a12aa27a41aca9603f27dd5116"].pack("H*").to_ber_bin.should ==
90
- raw_string("\x04\x10" + "j1\xB4\xA1*\xA2zA\xAC\xA9`?'\xDDQ\x16")
91
- end
92
- it "should not fail on strings that can not be converted to UTF-8" do
93
- error = Encoding::UndefinedConversionError
94
- lambda {"\x81".to_ber }.should_not raise_exception(error)
95
- end
96
- end
97
- end
98
- end
99
-
100
- describe "BER decoding of" do
101
- context "numbers" do
102
- it "should decode #{"\002\001\006".inspect} (6)" do
103
- "\002\001\006".read_ber(Net::LDAP::AsnSyntax).should == 6
104
- end
105
- it "should decode #{"\004\007testing".inspect} ('testing')" do
106
- "\004\007testing".read_ber(Net::LDAP::AsnSyntax).should == 'testing'
107
- end
108
- it "should decode an ldap bind request" do
109
- "0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus".
110
- read_ber(Net::LDAP::AsnSyntax).should ==
111
- [1, [3, "Administrator", "ad_is_bogus"]]
112
- end
113
- end
114
- end
115
-
116
- describe Net::BER::BerIdentifiedString do
117
- describe "initialize" do
118
- subject { Net::BER::BerIdentifiedString.new(data) }
119
-
120
- context "binary data" do
121
- let(:data) { ["6a31b4a12aa27a41aca9603f27dd5116"].pack("H*").force_encoding("ASCII-8BIT") }
122
-
123
- its(:valid_encoding?) { should be_true }
124
- specify { subject.encoding.name.should == "ASCII-8BIT" }
125
- end
126
-
127
- context "ascii data in UTF-8" do
128
- let(:data) { "some text".force_encoding("UTF-8") }
129
-
130
- its(:valid_encoding?) { should be_true }
131
- specify { subject.encoding.name.should == "UTF-8" }
132
- end
133
-
134
- context "UTF-8 data in UTF-8" do
135
- let(:data) { ["e4b8ad"].pack("H*").force_encoding("UTF-8") }
136
-
137
- its(:valid_encoding?) { should be_true }
138
- specify { subject.encoding.name.should == "UTF-8" }
139
- end
140
- end
141
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
- require 'metaid'
3
-
4
- describe Array, "when extended with BER core extensions" do
5
-
6
- it "should correctly convert a control code array" do
7
- control_codes = []
8
- control_codes << ['1.2.3'.to_ber, true.to_ber].to_ber_sequence
9
- control_codes << ['1.7.9'.to_ber, false.to_ber].to_ber_sequence
10
- control_codes = control_codes.to_ber_sequence
11
- res = [['1.2.3', true],['1.7.9',false]].to_ber_control
12
- res.should eq(control_codes)
13
- end
14
-
15
- it "should wrap the array in another array if a nested array is not passed" do
16
- result1 = ['1.2.3', true].to_ber_control
17
- result2 = [['1.2.3', true]].to_ber_control
18
- result1.should eq(result2)
19
- end
20
-
21
- it "should return an empty string if an empty array is passed" do
22
- [].to_ber_control.should be_empty
23
- end
24
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
- require 'metaid'
3
-
4
- describe String, "when extended with BER core extensions" do
5
- describe "<- #read_ber! (consuming read_ber method)" do
6
- context "when passed an ldap bind request and some extra data" do
7
- attr_reader :str, :result
8
- before(:each) do
9
- @str = raw_string("0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus UNCONSUMED")
10
- @result = str.read_ber!(Net::LDAP::AsnSyntax)
11
- end
12
-
13
- it "should correctly parse the ber message" do
14
- result.should == [1, [3, "Administrator", "ad_is_bogus"]]
15
- end
16
- it "should leave unconsumed part of message in place" do
17
- str.should == " UNCONSUMED"
18
- end
19
-
20
- context "if an exception occurs during #read_ber" do
21
- attr_reader :initial_value
22
- before(:each) do
23
- stub_exception_class = Class.new(StandardError)
24
-
25
- @initial_value = raw_string("0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus")
26
- @str = initial_value.dup
27
-
28
- # Defines a string
29
- io = StringIO.new(initial_value)
30
- io.meta_def :read_ber do |syntax|
31
- read
32
- raise stub_exception_class
33
- end
34
- flexmock(StringIO).should_receive(:new).and_return(io)
35
-
36
- begin
37
- str.read_ber!(Net::LDAP::AsnSyntax)
38
- rescue stub_exception_class
39
- # EMPTY ON PURPOSE
40
- else
41
- raise "The stub code should raise an exception!"
42
- end
43
- end
44
-
45
- it "should not modify string" do
46
- str.should == initial_value
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
- require 'net/ldap/dn'
3
-
4
- describe Net::LDAP::DN do
5
- describe "<- .construct" do
6
- attr_reader :dn
7
-
8
- before(:each) do
9
- @dn = Net::LDAP::DN.new('cn', ',+"\\<>;', 'ou=company')
10
- end
11
-
12
- it "should construct a Net::LDAP::DN" do
13
- dn.should be_an_instance_of(Net::LDAP::DN)
14
- end
15
-
16
- it "should escape all the required characters" do
17
- dn.to_s.should == 'cn=\\,\\+\\"\\\\\\<\\>\\;,ou=company'
18
- end
19
- end
20
-
21
- describe "<- .to_a" do
22
- context "parsing" do
23
- {
24
- 'cn=James, ou=Company\\,\\20LLC' => ['cn','James','ou','Company, LLC'],
25
- 'cn = \ James , ou = "Comp\28ny" ' => ['cn',' James','ou','Comp(ny'],
26
- '1.23.4= #A3B4D5 ,ou=Company' => ['1.23.4','#A3B4D5','ou','Company'],
27
- }.each do |key, value|
28
- context "(#{key})" do
29
- attr_reader :dn
30
-
31
- before(:each) do
32
- @dn = Net::LDAP::DN.new(key)
33
- end
34
-
35
- it "should decode into a Net::LDAP::DN" do
36
- dn.should be_an_instance_of(Net::LDAP::DN)
37
- end
38
-
39
- it "should return the correct array" do
40
- dn.to_a.should == value
41
- end
42
- end
43
- end
44
- end
45
-
46
- context "parsing bad input" do
47
- [
48
- 'cn=James,',
49
- 'cn=#aa aa',
50
- 'cn="James',
51
- 'cn=J\ames',
52
- 'cn=\\',
53
- '1.2.d=Value',
54
- 'd1.2=Value',
55
- ].each do |value|
56
- context "(#{value})" do
57
- attr_reader :dn
58
-
59
- before(:each) do
60
- @dn = Net::LDAP::DN.new(value)
61
- end
62
-
63
- it "should decode into a Net::LDAP::DN" do
64
- dn.should be_an_instance_of(Net::LDAP::DN)
65
- end
66
-
67
- it "should raise an error on parsing" do
68
- lambda { dn.to_a }.should raise_error
69
- end
70
- end
71
- end
72
- end
73
- end
74
-
75
- describe "<- .escape(str)" do
76
- it "should escape ,, +, \", \\, <, >, and ;" do
77
- Net::LDAP::DN.escape(',+"\\<>;').should == '\\,\\+\\"\\\\\\<\\>\\;'
78
- end
79
- end
80
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Net::LDAP::Entry do
4
- attr_reader :entry
5
- before(:each) do
6
- @entry = Net::LDAP::Entry.from_single_ldif_string(
7
- %Q{dn: something
8
- foo: foo
9
- barAttribute: bar
10
- }
11
- )
12
- end
13
-
14
- describe "entry access" do
15
- it "should always respond to #dn" do
16
- entry.should respond_to(:dn)
17
- end
18
-
19
- context "<- #foo" do
20
- it "should respond_to?" do
21
- entry.should respond_to(:foo)
22
- end
23
- it "should return 'foo'" do
24
- entry.foo.should == ['foo']
25
- end
26
- end
27
- context "<- #Foo" do
28
- it "should respond_to?" do
29
- entry.should respond_to(:Foo)
30
- end
31
- it "should return 'foo'" do
32
- entry.foo.should == ['foo']
33
- end
34
- end
35
- context "<- #foo=" do
36
- it "should respond_to?" do
37
- entry.should respond_to(:foo=)
38
- end
39
- it "should set 'foo'" do
40
- entry.foo= 'bar'
41
- entry.foo.should == ['bar']
42
- end
43
- end
44
- context "<- #fOo=" do
45
- it "should return 'foo'" do
46
- entry.fOo= 'bar'
47
- entry.fOo.should == ['bar']
48
- end
49
- end
50
- end
51
- end