net-ldap 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of net-ldap might be problematic. Click here for more details.
- data/History.txt +7 -6
- data/LICENSE +3 -2
- data/Manifest.txt +13 -5
- data/README.txt +34 -28
- data/Rakefile +115 -11
- data/lib/net-ldap.rb +1 -0
- data/lib/net/ber.rb +52 -514
- data/lib/net/ber/ber_parser.rb +112 -0
- data/lib/net/ldap.rb +486 -540
- data/lib/net/ldap/core_ext/all.rb +43 -0
- data/lib/net/ldap/core_ext/array.rb +42 -0
- data/lib/net/ldap/core_ext/bignum.rb +25 -0
- data/lib/net/ldap/core_ext/false_class.rb +11 -0
- data/lib/net/ldap/core_ext/fixnum.rb +64 -0
- data/lib/net/ldap/core_ext/string.rb +40 -0
- data/lib/net/ldap/core_ext/true_class.rb +11 -0
- data/lib/net/ldap/dataset.rb +64 -73
- data/lib/net/ldap/entry.rb +0 -9
- data/lib/net/ldap/filter.rb +1 -8
- data/lib/net/ldap/pdu.rb +2 -3
- data/lib/net/ldap/psw.rb +31 -38
- data/lib/net/ldif.rb +2 -7
- data/lib/net/snmp.rb +2 -4
- data/spec/integration/ssl_ber_spec.rb +36 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/ber/ber_spec.rb +18 -0
- data/test/common.rb +0 -4
- data/test/test_ber.rb +73 -95
- data/test/test_filter.rb +1 -1
- data/test/test_ldif.rb +1 -1
- data/test/test_snmp.rb +61 -78
- data/testserver/ldapserver.rb +0 -19
- metadata +118 -24
- data/Release-Announcement +0 -95
- data/pre-setup.rb +0 -45
- data/setup.rb +0 -1366
- data/tests/NOTICE.txt +0 -6
- data/tests/testldap.rb +0 -190
data/tests/NOTICE.txt
DELETED
data/tests/testldap.rb
DELETED
@@ -1,190 +0,0 @@
|
|
1
|
-
# $Id$
|
2
|
-
#
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
$:.unshift "lib"
|
7
|
-
|
8
|
-
require 'test/unit'
|
9
|
-
|
10
|
-
require 'net/ldap'
|
11
|
-
require 'stringio'
|
12
|
-
|
13
|
-
|
14
|
-
class TestLdapClient < Test::Unit::TestCase
|
15
|
-
|
16
|
-
# TODO: these tests crash and burn if the associated
|
17
|
-
# LDAP testserver isn't up and running.
|
18
|
-
# We rely on being able to read a file with test data
|
19
|
-
# in LDIF format.
|
20
|
-
# TODO, WARNING: for the moment, this data is in a file
|
21
|
-
# whose name and location are HARDCODED into the
|
22
|
-
# instance method load_test_data.
|
23
|
-
|
24
|
-
def setup
|
25
|
-
@host = "127.0.0.1"
|
26
|
-
@port = 3890
|
27
|
-
@auth = {
|
28
|
-
:method => :simple,
|
29
|
-
:username => "cn=bigshot,dc=bayshorenetworks,dc=com",
|
30
|
-
:password => "opensesame"
|
31
|
-
}
|
32
|
-
|
33
|
-
@ldif = load_test_data
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# Get some test data which will be used to validate
|
39
|
-
# the responses from the test LDAP server we will
|
40
|
-
# connect to.
|
41
|
-
# TODO, Bogus: we are HARDCODING the location of the file for now.
|
42
|
-
#
|
43
|
-
def load_test_data
|
44
|
-
ary = File.readlines( "tests/testdata.ldif" )
|
45
|
-
hash = {}
|
46
|
-
while line = ary.shift and line.chomp!
|
47
|
-
if line =~ /^dn:[\s]*/i
|
48
|
-
dn = $'
|
49
|
-
hash[dn] = {}
|
50
|
-
while attr = ary.shift and attr.chomp! and attr =~ /^([\w]+)[\s]*:[\s]*/
|
51
|
-
hash[dn][$1.downcase.intern] ||= []
|
52
|
-
hash[dn][$1.downcase.intern] << $'
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
hash
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# Binding tests.
|
62
|
-
# Need tests for all kinds of network failures and incorrect auth.
|
63
|
-
# TODO: Implement a class-level timeout for operations like bind.
|
64
|
-
# Search has a timeout defined at the protocol level, other ops do not.
|
65
|
-
# TODO, use constants for the LDAP result codes, rather than hardcoding them.
|
66
|
-
def test_bind
|
67
|
-
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth
|
68
|
-
assert_equal( true, ldap.bind )
|
69
|
-
assert_equal( 0, ldap.get_operation_result.code )
|
70
|
-
assert_equal( "Success", ldap.get_operation_result.message )
|
71
|
-
|
72
|
-
bad_username = @auth.merge( {:username => "cn=badguy,dc=imposters,dc=com"} )
|
73
|
-
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => bad_username
|
74
|
-
assert_equal( false, ldap.bind )
|
75
|
-
assert_equal( 48, ldap.get_operation_result.code )
|
76
|
-
assert_equal( "Inappropriate Authentication", ldap.get_operation_result.message )
|
77
|
-
|
78
|
-
bad_password = @auth.merge( {:password => "cornhusk"} )
|
79
|
-
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => bad_password
|
80
|
-
assert_equal( false, ldap.bind )
|
81
|
-
assert_equal( 49, ldap.get_operation_result.code )
|
82
|
-
assert_equal( "Invalid Credentials", ldap.get_operation_result.message )
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
def test_search
|
88
|
-
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth
|
89
|
-
|
90
|
-
search = {:base => "dc=smalldomain,dc=com"}
|
91
|
-
assert_equal( false, ldap.search( search ))
|
92
|
-
assert_equal( 32, ldap.get_operation_result.code )
|
93
|
-
|
94
|
-
search = {:base => "dc=bayshorenetworks,dc=com"}
|
95
|
-
assert_equal( true, ldap.search( search ))
|
96
|
-
assert_equal( 0, ldap.get_operation_result.code )
|
97
|
-
|
98
|
-
ldap.search( search ) {|res|
|
99
|
-
assert_equal( res, @ldif )
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
# This is a helper routine for test_search_attributes.
|
107
|
-
def internal_test_search_attributes attrs_to_search
|
108
|
-
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth
|
109
|
-
assert( ldap.bind )
|
110
|
-
|
111
|
-
search = {
|
112
|
-
:base => "dc=bayshorenetworks,dc=com",
|
113
|
-
:attributes => attrs_to_search
|
114
|
-
}
|
115
|
-
|
116
|
-
ldif = @ldif
|
117
|
-
ldif.each {|dn,entry|
|
118
|
-
entry.delete_if {|attr,value|
|
119
|
-
! attrs_to_search.include?(attr)
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
assert_equal( true, ldap.search( search ))
|
124
|
-
ldap.search( search ) {|res|
|
125
|
-
res_keys = res.keys.sort
|
126
|
-
ldif_keys = ldif.keys.sort
|
127
|
-
assert( res_keys, ldif_keys )
|
128
|
-
res.keys.each {|rk|
|
129
|
-
assert( res[rk], ldif[rk] )
|
130
|
-
}
|
131
|
-
}
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
def test_search_attributes
|
136
|
-
internal_test_search_attributes [:mail]
|
137
|
-
internal_test_search_attributes [:cn]
|
138
|
-
internal_test_search_attributes [:ou]
|
139
|
-
internal_test_search_attributes [:hasaccessprivilege]
|
140
|
-
internal_test_search_attributes ["mail"]
|
141
|
-
internal_test_search_attributes ["cn"]
|
142
|
-
internal_test_search_attributes ["ou"]
|
143
|
-
internal_test_search_attributes ["hasaccessrole"]
|
144
|
-
|
145
|
-
internal_test_search_attributes [:mail, :cn, :ou, :hasaccessrole]
|
146
|
-
internal_test_search_attributes [:mail, "cn", :ou, "hasaccessrole"]
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
def test_search_filters
|
151
|
-
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth
|
152
|
-
search = {
|
153
|
-
:base => "dc=bayshorenetworks,dc=com",
|
154
|
-
:filter => Net::LDAP::Filter.eq( "sn", "Fosse" )
|
155
|
-
}
|
156
|
-
|
157
|
-
ldap.search( search ) {|res|
|
158
|
-
p res
|
159
|
-
}
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
def test_open
|
165
|
-
ldap = Net::LDAP.new :host => @host, :port => @port, :auth => @auth
|
166
|
-
ldap.open {|ldap|
|
167
|
-
10.times {
|
168
|
-
rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" )
|
169
|
-
assert_equal( true, rc )
|
170
|
-
}
|
171
|
-
}
|
172
|
-
end
|
173
|
-
|
174
|
-
|
175
|
-
def test_ldap_open
|
176
|
-
Net::LDAP.open( :host => @host, :port => @port, :auth => @auth ) {|ldap|
|
177
|
-
10.times {
|
178
|
-
rc = ldap.search( :base => "dc=bayshorenetworks,dc=com" )
|
179
|
-
assert_equal( true, rc )
|
180
|
-
}
|
181
|
-
}
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
|