socialcast-net-ldap 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/COPYING +272 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +29 -0
- data/Hacking.rdoc +16 -0
- data/History.txt +137 -0
- data/LICENSE +56 -0
- data/Manifest.txt +45 -0
- data/README.txt +70 -0
- data/Rakefile +124 -0
- data/lib/net-ldap.rb +1 -0
- data/lib/net/ber.rb +341 -0
- data/lib/net/ber/ber_parser.rb +168 -0
- data/lib/net/ber/core_ext.rb +72 -0
- data/lib/net/ber/core_ext/array.rb +79 -0
- data/lib/net/ber/core_ext/bignum.rb +19 -0
- data/lib/net/ber/core_ext/false_class.rb +7 -0
- data/lib/net/ber/core_ext/fixnum.rb +63 -0
- data/lib/net/ber/core_ext/string.rb +57 -0
- data/lib/net/ber/core_ext/true_class.rb +9 -0
- data/lib/net/ldap.rb +1539 -0
- data/lib/net/ldap/dataset.rb +174 -0
- data/lib/net/ldap/entry.rb +208 -0
- data/lib/net/ldap/filter.rb +781 -0
- data/lib/net/ldap/password.rb +52 -0
- data/lib/net/ldap/pdu.rb +279 -0
- data/lib/net/ldif.rb +34 -0
- data/lib/net/snmp.rb +295 -0
- data/spec/integration/ssl_ber_spec.rb +33 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/ber/ber_spec.rb +109 -0
- data/spec/unit/ber/core_ext/string_spec.rb +51 -0
- data/spec/unit/ldap/entry_spec.rb +51 -0
- data/spec/unit/ldap/filter_spec.rb +83 -0
- data/spec/unit/ldap_spec.rb +48 -0
- data/test/common.rb +3 -0
- data/test/test_entry.rb +59 -0
- data/test/test_filter.rb +115 -0
- data/test/test_ldif.rb +68 -0
- data/test/test_password.rb +17 -0
- data/test/test_rename.rb +79 -0
- data/test/test_snmp.rb +114 -0
- data/test/testdata.ldif +101 -0
- data/testserver/ldapserver.rb +210 -0
- data/testserver/testdata.ldif +101 -0
- metadata +178 -0
data/test/test_filter.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'common'
|
2
|
+
|
3
|
+
class TestFilter < Test::Unit::TestCase
|
4
|
+
Filter = Net::LDAP::Filter
|
5
|
+
|
6
|
+
def test_bug_7534_rfc2254
|
7
|
+
assert_equal("(cn=Tim Wizard)",
|
8
|
+
Filter.from_rfc2254("(cn=Tim Wizard)").to_rfc2254)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_invalid_filter_string
|
12
|
+
assert_raises(Net::LDAP::LdapError) { Filter.from_rfc2254("") }
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_invalid_filter
|
16
|
+
assert_raises(Net::LDAP::LdapError) {
|
17
|
+
# This test exists to prove that our constructor blocks unknown filter
|
18
|
+
# types. All filters must be constructed using helpers.
|
19
|
+
Filter.__send__(:new, :xx, nil, nil)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_to_s
|
24
|
+
assert_equal("(uid=george *)", Filter.eq("uid", "george *").to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_apostrophe
|
28
|
+
assert_equal("(uid=O'Keefe)", Filter.construct("uid=O'Keefe").to_rfc2254)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_c2
|
32
|
+
assert_equal("(uid=george *)",
|
33
|
+
Filter.from_rfc2254("uid=george *").to_rfc2254)
|
34
|
+
assert_equal("(uid:=george *)",
|
35
|
+
Filter.from_rfc2254("uid:=george *").to_rfc2254)
|
36
|
+
assert_equal("(uid=george*)",
|
37
|
+
Filter.from_rfc2254(" ( uid = george* ) ").to_rfc2254)
|
38
|
+
assert_equal("(!(uid=george*))",
|
39
|
+
Filter.from_rfc2254("uid!=george*").to_rfc2254)
|
40
|
+
assert_equal("(uid<=george*)",
|
41
|
+
Filter.from_rfc2254("uid <= george*").to_rfc2254)
|
42
|
+
assert_equal("(uid>=george*)",
|
43
|
+
Filter.from_rfc2254("uid>=george*").to_rfc2254)
|
44
|
+
assert_equal("(&(uid=george*)(mail=*))",
|
45
|
+
Filter.from_rfc2254("(& (uid=george* ) (mail=*))").to_rfc2254)
|
46
|
+
assert_equal("(|(uid=george*)(mail=*))",
|
47
|
+
Filter.from_rfc2254("(| (uid=george* ) (mail=*))").to_rfc2254)
|
48
|
+
assert_equal("(!(mail=*))",
|
49
|
+
Filter.from_rfc2254("(! (mail=*))").to_rfc2254)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_filters_from_ber
|
53
|
+
[
|
54
|
+
Net::LDAP::Filter.eq("objectclass", "*"),
|
55
|
+
Net::LDAP::Filter.pres("objectclass"),
|
56
|
+
Net::LDAP::Filter.eq("objectclass", "ou"),
|
57
|
+
Net::LDAP::Filter.ge("uid", "500"),
|
58
|
+
Net::LDAP::Filter.le("uid", "500"),
|
59
|
+
(~ Net::LDAP::Filter.pres("objectclass")),
|
60
|
+
(Net::LDAP::Filter.pres("objectclass") & Net::LDAP::Filter.pres("ou")),
|
61
|
+
(Net::LDAP::Filter.pres("objectclass") & Net::LDAP::Filter.pres("ou") & Net::LDAP::Filter.pres("sn")),
|
62
|
+
(Net::LDAP::Filter.pres("objectclass") | Net::LDAP::Filter.pres("ou") | Net::LDAP::Filter.pres("sn")),
|
63
|
+
|
64
|
+
Net::LDAP::Filter.eq("objectclass", "*aaa"),
|
65
|
+
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb"),
|
66
|
+
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb*ccc"),
|
67
|
+
Net::LDAP::Filter.eq("objectclass", "aaa*bbb"),
|
68
|
+
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*ccc"),
|
69
|
+
Net::LDAP::Filter.eq("objectclass", "abc*def*1111*22*g"),
|
70
|
+
Net::LDAP::Filter.eq("objectclass", "*aaa*"),
|
71
|
+
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb*"),
|
72
|
+
Net::LDAP::Filter.eq("objectclass", "*aaa*bbb*ccc*"),
|
73
|
+
Net::LDAP::Filter.eq("objectclass", "aaa*"),
|
74
|
+
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*"),
|
75
|
+
Net::LDAP::Filter.eq("objectclass", "aaa*bbb*ccc*"),
|
76
|
+
].each {|ber|
|
77
|
+
f = Net::LDAP::Filter.parse_ber(ber.to_ber.read_ber(Net::LDAP::AsnSyntax))
|
78
|
+
assert(f == ber)
|
79
|
+
assert_equal(f.to_ber, ber.to_ber)
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_ber_from_rfc2254_filter
|
84
|
+
[
|
85
|
+
Net::LDAP::Filter.construct("objectclass=*"),
|
86
|
+
Net::LDAP::Filter.construct("objectclass=ou"),
|
87
|
+
Net::LDAP::Filter.construct("uid >= 500"),
|
88
|
+
Net::LDAP::Filter.construct("uid <= 500"),
|
89
|
+
Net::LDAP::Filter.construct("(!(uid=*))"),
|
90
|
+
Net::LDAP::Filter.construct("(&(uid=*)(objectclass=*))"),
|
91
|
+
Net::LDAP::Filter.construct("(&(uid=*)(objectclass=*)(sn=*))"),
|
92
|
+
Net::LDAP::Filter.construct("(|(uid=*)(objectclass=*))"),
|
93
|
+
Net::LDAP::Filter.construct("(|(uid=*)(objectclass=*)(sn=*))"),
|
94
|
+
|
95
|
+
Net::LDAP::Filter.construct("objectclass=*aaa"),
|
96
|
+
Net::LDAP::Filter.construct("objectclass=*aaa*bbb"),
|
97
|
+
Net::LDAP::Filter.construct("objectclass=*aaa bbb"),
|
98
|
+
Net::LDAP::Filter.construct("objectclass=*aaa bbb"),
|
99
|
+
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*ccc"),
|
100
|
+
Net::LDAP::Filter.construct("objectclass=aaa*bbb"),
|
101
|
+
Net::LDAP::Filter.construct("objectclass=aaa*bbb*ccc"),
|
102
|
+
Net::LDAP::Filter.construct("objectclass=abc*def*1111*22*g"),
|
103
|
+
Net::LDAP::Filter.construct("objectclass=*aaa*"),
|
104
|
+
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*"),
|
105
|
+
Net::LDAP::Filter.construct("objectclass=*aaa*bbb*ccc*"),
|
106
|
+
Net::LDAP::Filter.construct("objectclass=aaa*"),
|
107
|
+
Net::LDAP::Filter.construct("objectclass=aaa*bbb*"),
|
108
|
+
Net::LDAP::Filter.construct("objectclass=aaa*bbb*ccc*"),
|
109
|
+
].each {|ber|
|
110
|
+
f = Net::LDAP::Filter.parse_ber(ber.to_ber.read_ber(Net::LDAP::AsnSyntax))
|
111
|
+
assert(f == ber)
|
112
|
+
assert_equal(f.to_ber, ber.to_ber)
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
data/test/test_ldif.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# $Id: testldif.rb 61 2006-04-18 20:55:55Z blackhedd $
|
2
|
+
|
3
|
+
require 'common'
|
4
|
+
|
5
|
+
require 'net/ldif'
|
6
|
+
require 'digest/sha1'
|
7
|
+
require 'base64'
|
8
|
+
|
9
|
+
class TestLdif < Test::Unit::TestCase
|
10
|
+
TestLdifFilename = "#{File.dirname(__FILE__)}/testdata.ldif"
|
11
|
+
|
12
|
+
def test_empty_ldif
|
13
|
+
ds = Net::LDAP::Dataset.read_ldif(StringIO.new)
|
14
|
+
assert_equal(true, ds.empty?)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_ldif_with_comments
|
18
|
+
str = ["# Hello from LDIF-land", "# This is an unterminated comment"]
|
19
|
+
io = StringIO.new(str[0] + "\r\n" + str[1])
|
20
|
+
ds = Net::LDAP::Dataset::read_ldif(io)
|
21
|
+
assert_equal(str, ds.comments)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_ldif_with_password
|
25
|
+
psw = "goldbricks"
|
26
|
+
hashed_psw = "{SHA}" + Base64::encode64(Digest::SHA1.digest(psw)).chomp
|
27
|
+
|
28
|
+
ldif_encoded = Base64::encode64(hashed_psw).chomp
|
29
|
+
ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: Goldbrick\r\nuserPassword:: #{ldif_encoded}\r\n\r\n"))
|
30
|
+
recovered_psw = ds["Goldbrick"][:userpassword].shift
|
31
|
+
assert_equal(hashed_psw, recovered_psw)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_ldif_with_continuation_lines
|
35
|
+
ds = Net::LDAP::Dataset::read_ldif(StringIO.new("dn: abcdefg\r\n hijklmn\r\n\r\n"))
|
36
|
+
assert_equal(true, ds.has_key?("abcdefg hijklmn"))
|
37
|
+
end
|
38
|
+
|
39
|
+
# TODO, INADEQUATE. We need some more tests
|
40
|
+
# to verify the content.
|
41
|
+
def test_ldif
|
42
|
+
File.open(TestLdifFilename, "r") {|f|
|
43
|
+
ds = Net::LDAP::Dataset::read_ldif(f)
|
44
|
+
assert_equal(13, ds.length)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
# Must test folded lines and base64-encoded lines as well as normal ones.
|
49
|
+
def test_to_ldif
|
50
|
+
data = File.open(TestLdifFilename, "rb") { |f| f.read }
|
51
|
+
io = StringIO.new(data)
|
52
|
+
|
53
|
+
# added .lines to turn to array because 1.9 doesn't have
|
54
|
+
# .grep on basic strings
|
55
|
+
entries = data.lines.grep(/^dn:\s*/) { $'.chomp }
|
56
|
+
dn_entries = entries.dup
|
57
|
+
|
58
|
+
ds = Net::LDAP::Dataset::read_ldif(io) { |type, value|
|
59
|
+
case type
|
60
|
+
when :dn
|
61
|
+
assert_equal(dn_entries.first, value)
|
62
|
+
dn_entries.shift
|
63
|
+
end
|
64
|
+
}
|
65
|
+
assert_equal(entries.size, ds.size)
|
66
|
+
assert_equal(entries.sort, ds.to_ldif.grep(/^dn:\s*/) { $'.chomp })
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# $Id: testpsw.rb 72 2006-04-24 21:58:14Z blackhedd $
|
2
|
+
|
3
|
+
require 'common'
|
4
|
+
|
5
|
+
class TestPassword < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_psw
|
8
|
+
assert_equal(
|
9
|
+
"{MD5}xq8jwrcfibi0sZdZYNkSng==",
|
10
|
+
Net::LDAP::Password.generate( :md5, "cashflow" ))
|
11
|
+
|
12
|
+
assert_equal(
|
13
|
+
"{SHA}YE4eGkN4BvwNN1f5R7CZz0kFn14=",
|
14
|
+
Net::LDAP::Password.generate( :sha, "cashflow" ))
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/test_rename.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'common'
|
2
|
+
|
3
|
+
class TestRename < Test::Unit::TestCase
|
4
|
+
def test_the_truth
|
5
|
+
assert true
|
6
|
+
end
|
7
|
+
# Commented out since it assumes you have a live LDAP server somewhere. This
|
8
|
+
# will be migrated to the integration specs, as soon as they are ready.
|
9
|
+
|
10
|
+
# HOST= '10.10.10.71'
|
11
|
+
# PORT = 389
|
12
|
+
# BASE = "o=test"
|
13
|
+
# AUTH = { :method => :simple, :username => "cn=testadmin,#{BASE}", :password => 'password' }
|
14
|
+
# BASIC_USER = "cn=jsmith,ou=sales,#{BASE}"
|
15
|
+
# RENAMED_USER = "cn=jbrown,ou=sales,#{BASE}"
|
16
|
+
# MOVED_USER = "cn=jsmith,ou=marketing,#{BASE}"
|
17
|
+
# RENAMED_MOVED_USER = "cn=jjones,ou=marketing,#{BASE}"
|
18
|
+
#
|
19
|
+
# def setup
|
20
|
+
# # create the entries we're going to manipulate
|
21
|
+
# Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
|
22
|
+
# if ldap.add(:dn => "ou=sales,#{BASE}", :attributes => { :ou => "sales", :objectclass => "organizationalUnit" })
|
23
|
+
# puts "Add failed: #{ldap.get_operation_result.message} - code: #{ldap.get_operation_result.code}"
|
24
|
+
# end
|
25
|
+
# ldap.add(:dn => "ou=marketing,#{BASE}", :attributes => { :ou => "marketing", :objectclass => "organizationalUnit" })
|
26
|
+
# ldap.add(:dn => BASIC_USER, :attributes => { :cn => "jsmith", :objectclass => "inetOrgPerson", :sn => "Smith" })
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# def test_rename_entry
|
31
|
+
# dn = nil
|
32
|
+
# Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
|
33
|
+
# ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jbrown")
|
34
|
+
#
|
35
|
+
# ldap.search(:base => RENAMED_USER) do |entry|
|
36
|
+
# dn = entry.dn
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
# assert_equal(RENAMED_USER, dn)
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# def test_move_entry
|
43
|
+
# dn = nil
|
44
|
+
# Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
|
45
|
+
# ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jsmith", :new_superior => "ou=marketing,#{BASE}")
|
46
|
+
#
|
47
|
+
# ldap.search(:base => MOVED_USER) do |entry|
|
48
|
+
# dn = entry.dn
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
# assert_equal(MOVED_USER, dn)
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# def test_move_and_rename_entry
|
55
|
+
# dn = nil
|
56
|
+
# Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
|
57
|
+
# ldap.rename(:olddn => BASIC_USER, :newrdn => "cn=jjones", :new_superior => "ou=marketing,#{BASE}")
|
58
|
+
#
|
59
|
+
# ldap.search(:base => RENAMED_MOVED_USER) do |entry|
|
60
|
+
# dn = entry.dn
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
# assert_equal(RENAMED_MOVED_USER, dn)
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# def teardown
|
67
|
+
# # delete the entries
|
68
|
+
# # note: this doesn't always completely clear up on eDirectory as objects get locked while
|
69
|
+
# # the rename/move is being completed on the server and this prevents the delete from happening
|
70
|
+
# Net::LDAP::open(:host => HOST, :port => PORT, :auth => AUTH) do |ldap|
|
71
|
+
# ldap.delete(:dn => BASIC_USER)
|
72
|
+
# ldap.delete(:dn => RENAMED_USER)
|
73
|
+
# ldap.delete(:dn => MOVED_USER)
|
74
|
+
# ldap.delete(:dn => RENAMED_MOVED_USER)
|
75
|
+
# ldap.delete(:dn => "ou=sales,#{BASE}")
|
76
|
+
# ldap.delete(:dn => "ou=marketing,#{BASE}")
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
end
|
data/test/test_snmp.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# $Id: testsnmp.rb 231 2006-12-21 15:09:29Z blackhedd $
|
2
|
+
|
3
|
+
require 'common'
|
4
|
+
require 'net/snmp'
|
5
|
+
|
6
|
+
class TestSnmp < Test::Unit::TestCase
|
7
|
+
SnmpGetRequest = "0'\002\001\000\004\006public\240\032\002\002?*\002\001\000\002\001\0000\0160\f\006\b+\006\001\002\001\001\001\000\005\000"
|
8
|
+
SnmpGetResponse = "0+\002\001\000\004\006public\242\036\002\002'\017\002\001\000\002\001\0000\0220\020\006\b+\006\001\002\001\001\001\000\004\004test"
|
9
|
+
|
10
|
+
SnmpGetRequestXXX = "0'\002\001\000\004\006xxxxxx\240\032\002\002?*\002\001\000\002\001\0000\0160\f\006\b+\006\001\002\001\001\001\000\005\000"
|
11
|
+
|
12
|
+
def test_invalid_packet
|
13
|
+
data = "xxxx"
|
14
|
+
assert_raise(Net::BER::BerError) {
|
15
|
+
ary = data.read_ber(Net::SNMP::AsnSyntax)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
# The method String#read_ber! added by Net::BER consumes a well-formed BER
|
20
|
+
# object from the head of a string. If it doesn't find a complete,
|
21
|
+
# well-formed BER object, it returns nil and leaves the string unchanged.
|
22
|
+
# If it finds an object, it returns the object and removes it from the
|
23
|
+
# head of the string. This is good for handling partially-received data
|
24
|
+
# streams, such as from network connections.
|
25
|
+
def _test_consume_string
|
26
|
+
data = "xxx"
|
27
|
+
assert_equal(nil, data.read_ber!)
|
28
|
+
assert_equal("xxx", data)
|
29
|
+
|
30
|
+
data = SnmpGetRequest + "!!!"
|
31
|
+
ary = data.read_ber!(Net::SNMP::AsnSyntax)
|
32
|
+
assert_equal("!!!", data)
|
33
|
+
assert ary.is_a?(Array)
|
34
|
+
assert ary.is_a?(Net::BER::BerIdentifiedArray)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_weird_packet
|
38
|
+
assert_raise(Net::SnmpPdu::Error) {
|
39
|
+
Net::SnmpPdu.parse("aaaaaaaaaaaaaa")
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_get_request
|
44
|
+
data = SnmpGetRequest.dup
|
45
|
+
pkt = data.read_ber(Net::SNMP::AsnSyntax)
|
46
|
+
assert pkt.is_a?(Net::BER::BerIdentifiedArray)
|
47
|
+
assert_equal(48, pkt.ber_identifier) # Constructed [0], signifies GetRequest
|
48
|
+
|
49
|
+
pdu = Net::SnmpPdu.parse(pkt)
|
50
|
+
assert_equal(:get_request, pdu.pdu_type)
|
51
|
+
assert_equal(16170, pdu.request_id) # whatever was in the test data. 16170 is not magic.
|
52
|
+
assert_equal([[[1, 3, 6, 1, 2, 1, 1, 1, 0], nil]], pdu.variables)
|
53
|
+
|
54
|
+
assert_equal(pdu.to_ber_string, SnmpGetRequest)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_empty_pdu
|
58
|
+
pdu = Net::SnmpPdu.new
|
59
|
+
assert_raise(Net::SnmpPdu::Error) { pdu.to_ber_string }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_malformations
|
63
|
+
pdu = Net::SnmpPdu.new
|
64
|
+
pdu.version = 0
|
65
|
+
pdu.version = 2
|
66
|
+
assert_raise(Net::SnmpPdu::Error) { pdu.version = 100 }
|
67
|
+
|
68
|
+
pdu.pdu_type = :get_request
|
69
|
+
pdu.pdu_type = :get_next_request
|
70
|
+
pdu.pdu_type = :get_response
|
71
|
+
pdu.pdu_type = :set_request
|
72
|
+
pdu.pdu_type = :trap
|
73
|
+
assert_raise(Net::SnmpPdu::Error) { pdu.pdu_type = :something_else }
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_make_response
|
77
|
+
pdu = Net::SnmpPdu.new
|
78
|
+
pdu.version = 0
|
79
|
+
pdu.community = "public"
|
80
|
+
pdu.pdu_type = :get_response
|
81
|
+
pdu.request_id = 9999
|
82
|
+
pdu.error_status = 0
|
83
|
+
pdu.error_index = 0
|
84
|
+
pdu.add_variable_binding [1, 3, 6, 1, 2, 1, 1, 1, 0], "test"
|
85
|
+
|
86
|
+
assert_equal(SnmpGetResponse, pdu.to_ber_string)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_make_bad_response
|
90
|
+
pdu = Net::SnmpPdu.new
|
91
|
+
assert_raise(Net::SnmpPdu::Error) {pdu.to_ber_string}
|
92
|
+
pdu.pdu_type = :get_response
|
93
|
+
pdu.request_id = 999
|
94
|
+
pdu.to_ber_string
|
95
|
+
# Not specifying variables doesn't create an error. (Maybe it should?)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_snmp_integers
|
99
|
+
c32 = Net::SNMP::Counter32.new(100)
|
100
|
+
assert_equal("A\001d", c32.to_ber)
|
101
|
+
g32 = Net::SNMP::Gauge32.new(100)
|
102
|
+
assert_equal("B\001d", g32.to_ber)
|
103
|
+
t32 = Net::SNMP::TimeTicks32.new(100)
|
104
|
+
assert_equal("C\001d", t32.to_ber)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_community
|
108
|
+
data = SnmpGetRequestXXX.dup
|
109
|
+
ary = data.read_ber(Net::SNMP::AsnSyntax)
|
110
|
+
pdu = Net::SnmpPdu.parse(ary)
|
111
|
+
assert_equal("xxxxxx", pdu.community)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
data/test/testdata.ldif
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# $Id: testdata.ldif 50 2006-04-17 17:57:33Z blackhedd $
|
2
|
+
#
|
3
|
+
# This is test-data for an LDAP server in LDIF format.
|
4
|
+
#
|
5
|
+
dn: dc=bayshorenetworks,dc=com
|
6
|
+
objectClass: dcObject
|
7
|
+
objectClass: organization
|
8
|
+
o: Bayshore Networks LLC
|
9
|
+
dc: bayshorenetworks
|
10
|
+
|
11
|
+
dn: cn=Manager,dc=bayshorenetworks,dc=com
|
12
|
+
objectClass: organizationalrole
|
13
|
+
cn: Manager
|
14
|
+
|
15
|
+
dn: ou=people,dc=bayshorenetworks,dc=com
|
16
|
+
objectClass: organizationalunit
|
17
|
+
ou: people
|
18
|
+
|
19
|
+
dn: ou=privileges,dc=bayshorenetworks,dc=com
|
20
|
+
objectClass: organizationalunit
|
21
|
+
ou: privileges
|
22
|
+
|
23
|
+
dn: ou=roles,dc=bayshorenetworks,dc=com
|
24
|
+
objectClass: organizationalunit
|
25
|
+
ou: roles
|
26
|
+
|
27
|
+
dn: ou=office,dc=bayshorenetworks,dc=com
|
28
|
+
objectClass: organizationalunit
|
29
|
+
ou: office
|
30
|
+
|
31
|
+
dn: mail=nogoodnik@steamheat.net,ou=people,dc=bayshorenetworks,dc=com
|
32
|
+
cn: Bob Fosse
|
33
|
+
mail: nogoodnik@steamheat.net
|
34
|
+
sn: Fosse
|
35
|
+
ou: people
|
36
|
+
objectClass: top
|
37
|
+
objectClass: inetorgperson
|
38
|
+
objectClass: authorizedperson
|
39
|
+
hasAccessRole: uniqueIdentifier=engineer,ou=roles
|
40
|
+
hasAccessRole: uniqueIdentifier=ldapadmin,ou=roles
|
41
|
+
hasAccessRole: uniqueIdentifier=ldapsuperadmin,ou=roles
|
42
|
+
hasAccessRole: uniqueIdentifier=ogilvy_elephant_user,ou=roles
|
43
|
+
hasAccessRole: uniqueIdentifier=ogilvy_eagle_user,ou=roles
|
44
|
+
hasAccessRole: uniqueIdentifier=greenplug_user,ou=roles
|
45
|
+
hasAccessRole: uniqueIdentifier=brandplace_logging_user,ou=roles
|
46
|
+
hasAccessRole: uniqueIdentifier=brandplace_report_user,ou=roles
|
47
|
+
hasAccessRole: uniqueIdentifier=workorder_user,ou=roles
|
48
|
+
hasAccessRole: uniqueIdentifier=bayshore_eagle_user,ou=roles
|
49
|
+
hasAccessRole: uniqueIdentifier=bayshore_eagle_superuser,ou=roles
|
50
|
+
hasAccessRole: uniqueIdentifier=kledaras_user,ou=roles
|
51
|
+
|
52
|
+
dn: mail=elephant@steamheat.net,ou=people,dc=bayshorenetworks,dc=com
|
53
|
+
cn: Gwen Verdon
|
54
|
+
mail: elephant@steamheat.net
|
55
|
+
sn: Verdon
|
56
|
+
ou: people
|
57
|
+
objectClass: top
|
58
|
+
objectClass: inetorgperson
|
59
|
+
objectClass: authorizedperson
|
60
|
+
hasAccessRole: uniqueIdentifier=brandplace_report_user,ou=roles
|
61
|
+
hasAccessRole: uniqueIdentifier=engineer,ou=roles
|
62
|
+
hasAccessRole: uniqueIdentifier=ogilvy_elephant_user,ou=roles
|
63
|
+
hasAccessRole: uniqueIdentifier=ldapsuperadmin,ou=roles
|
64
|
+
hasAccessRole: uniqueIdentifier=ldapadmin,ou=roles
|
65
|
+
|
66
|
+
dn: uniqueIdentifier=engineering,ou=privileges,dc=bayshorenetworks,dc=com
|
67
|
+
uniqueIdentifier: engineering
|
68
|
+
ou: privileges
|
69
|
+
objectClass: accessPrivilege
|
70
|
+
|
71
|
+
dn: uniqueIdentifier=engineer,ou=roles,dc=bayshorenetworks,dc=com
|
72
|
+
uniqueIdentifier: engineer
|
73
|
+
ou: roles
|
74
|
+
objectClass: accessRole
|
75
|
+
hasAccessPrivilege: uniqueIdentifier=engineering,ou=privileges
|
76
|
+
|
77
|
+
dn: uniqueIdentifier=ldapadmin,ou=roles,dc=bayshorenetworks,dc=com
|
78
|
+
uniqueIdentifier: ldapadmin
|
79
|
+
ou: roles
|
80
|
+
objectClass: accessRole
|
81
|
+
|
82
|
+
dn: uniqueIdentifier=ldapsuperadmin,ou=roles,dc=bayshorenetworks,dc=com
|
83
|
+
uniqueIdentifier: ldapsuperadmin
|
84
|
+
ou: roles
|
85
|
+
objectClass: accessRole
|
86
|
+
|
87
|
+
dn: mail=catperson@steamheat.net,ou=people,dc=bayshorenetworks,dc=com
|
88
|
+
cn: Sid Sorokin
|
89
|
+
mail: catperson@steamheat.net
|
90
|
+
sn: Sorokin
|
91
|
+
ou: people
|
92
|
+
objectClass: top
|
93
|
+
objectClass: inetorgperson
|
94
|
+
objectClass: authorizedperson
|
95
|
+
hasAccessRole: uniqueIdentifier=engineer,ou=roles
|
96
|
+
hasAccessRole: uniqueIdentifier=ogilvy_elephant_user,ou=roles
|
97
|
+
hasAccessRole: uniqueIdentifier=ldapsuperadmin,ou=roles
|
98
|
+
hasAccessRole: uniqueIdentifier=ogilvy_eagle_user,ou=roles
|
99
|
+
hasAccessRole: uniqueIdentifier=greenplug_user,ou=roles
|
100
|
+
hasAccessRole: uniqueIdentifier=workorder_user,ou=roles
|
101
|
+
|