Skip to content

Commit a56d249

Browse files
author
blackhedd
committed
tests and change notes
1 parent 19452a6 commit a56d249

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Added a "consuming" String#read_ber! method.
2626
* Added missing synactic support for Filter ANDs, NOTs and a few other
2727
things.
28+
* Added some support for SNMP data-handling.
2829

2930

3031
== Net::LDAP 0.0.4: August 15, 2006

tests/testsnmp.rb

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
class TestSnmp < Test::Unit::TestCase
1313

1414
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"
15+
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"
16+
1517

1618
def setup
1719
end
@@ -46,7 +48,7 @@ def test_consume_string
4648

4749
def test_weird_packet
4850
assert_raise( Net::SnmpPdu::Error ) {
49-
Net::SnmpPdu.new("aaaaaaaaaaaaaa")
51+
Net::SnmpPdu.parse("aaaaaaaaaaaaaa")
5052
}
5153
end
5254

@@ -56,11 +58,50 @@ def test_get_request
5658
assert pkt.is_a?(Net::BER::BerIdentifiedArray)
5759
assert_equal( 48, pkt.ber_identifier) # Constructed [0], signifies GetRequest
5860

59-
pdu = Net::SnmpPdu.new(pkt)
61+
pdu = Net::SnmpPdu.parse(pkt)
6062
assert_equal(:get_request, pdu.pdu_type )
6163
assert_equal(16170, pdu.request_id ) # whatever was in the test data. 16170 is not magic.
62-
assert_equal( [[1,3,6,1,2,1,1,1,0]], pdu.variables )
64+
assert_equal( [[[1,3,6,1,2,1,1,1,0],nil]], pdu.variables )
65+
66+
assert_equal( pdu.to_ber_string, SnmpGetRequest )
67+
end
68+
69+
def test_empty_pdu
70+
pdu = Net::SnmpPdu.new
71+
assert_raise( Net::SnmpPdu::Error ) {
72+
pdu.to_ber_string
73+
}
74+
end
75+
76+
def test_malformations
77+
pdu = Net::SnmpPdu.new
78+
assert_raise( Net::SnmpPdu::Error ) {
79+
pdu.version = 100
80+
}
81+
82+
pdu.pdu_type = :get_request
83+
pdu.pdu_type = :get_next_request
84+
pdu.pdu_type = :get_response
85+
pdu.pdu_type = :set_request
86+
pdu.pdu_type = :trap
87+
assert_raise( Net::SnmpPdu::Error ) {
88+
pdu.pdu_type = :something_else
89+
}
90+
end
91+
92+
def test_make_response
93+
pdu = Net::SnmpPdu.new
94+
pdu.version = 0
95+
pdu.community = "public"
96+
pdu.pdu_type = :get_response
97+
pdu.request_id = 9999
98+
pdu.error_status = 0
99+
pdu.error_index = 0
100+
pdu.add_variable_binding [1,3,6,1,2,1,1,1,0], "test"
101+
102+
assert_equal( SnmpGetResponse, pdu.to_ber_string )
63103
end
104+
64105
end
65106

66107

0 commit comments

Comments
 (0)