Importing, but disabling, tests from other repos.
This commit is contained in:
parent
090bad9d14
commit
28d58cd581
|
@ -25,13 +25,20 @@ class TestBer < Test::Unit::TestCase
|
||||||
assert_equal( "\x02\x01\x01", 1.to_ber )
|
assert_equal( "\x02\x01\x01", 1.to_ber )
|
||||||
assert_equal( "\x02\x01\x7F", 127.to_ber )
|
assert_equal( "\x02\x01\x7F", 127.to_ber )
|
||||||
assert_equal( "\x02\x01\x80", 128.to_ber )
|
assert_equal( "\x02\x01\x80", 128.to_ber )
|
||||||
|
#assert_equal( "\x02\x02\x00\x80", 128.to_ber )
|
||||||
assert_equal( "\x02\x01\xFF", 255.to_ber )
|
assert_equal( "\x02\x01\xFF", 255.to_ber )
|
||||||
|
#assert_equal( "\x02\x02\x00\xFF", 255.to_ber )
|
||||||
|
|
||||||
|
|
||||||
assert_equal( "\x02\x02\x01\x00", 256.to_ber )
|
assert_equal( "\x02\x02\x01\x00", 256.to_ber )
|
||||||
assert_equal( "\x02\x02\xFF\xFF", 65535.to_ber )
|
assert_equal( "\x02\x02\xFF\xFF", 65535.to_ber )
|
||||||
|
#assert_equal( "\x02\x03\x00\xFF\xFF", 65535.to_ber )
|
||||||
|
|
||||||
|
|
||||||
assert_equal( "\x02\x03\x01\x00\x00", 65536.to_ber )
|
assert_equal( "\x02\x03\x01\x00\x00", 65536.to_ber )
|
||||||
assert_equal( "\x02\x03\xFF\xFF\xFF", 16_777_215.to_ber )
|
assert_equal( "\x02\x03\xFF\xFF\xFF", 16_777_215.to_ber )
|
||||||
|
#assert_equal( "\x02\x04\x00\xFF\xFF\xFF", 16_777_215.to_ber )
|
||||||
|
|
||||||
|
|
||||||
assert_equal( "\x02\x04\x01\x00\x00\x00", 0x01000000.to_ber )
|
assert_equal( "\x02\x04\x01\x00\x00\x00", 0x01000000.to_ber )
|
||||||
assert_equal( "\x02\x04\x3F\xFF\xFF\xFF", 0x3FFFFFFF.to_ber )
|
assert_equal( "\x02\x04\x3F\xFF\xFF\xFF", 0x3FFFFFFF.to_ber )
|
||||||
|
@ -48,6 +55,7 @@ class TestBer < Test::Unit::TestCase
|
||||||
assert_equal( "\002\001\005", 5.to_ber )
|
assert_equal( "\002\001\005", 5.to_ber )
|
||||||
assert_equal( "\002\002\001\364", 500.to_ber )
|
assert_equal( "\002\002\001\364", 500.to_ber )
|
||||||
assert_equal( "\x02\x02\xC3P", 50000.to_ber )
|
assert_equal( "\x02\x02\xC3P", 50000.to_ber )
|
||||||
|
#assert_equal( "\002\003\0\303P", 50000.to_ber )
|
||||||
assert_equal( "\002\005\001*\005\362\000", 5000000000.to_ber )
|
assert_equal( "\002\005\001*\005\362\000", 5000000000.to_ber )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,6 +76,8 @@ class TestBer < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ber_parser_on_ldap_bind_request
|
def test_ber_parser_on_ldap_bind_request
|
||||||
|
require 'stringio'
|
||||||
|
|
||||||
s = StringIO.new(
|
s = StringIO.new(
|
||||||
"0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus" )
|
"0$\002\001\001`\037\002\001\003\004\rAdministrator\200\vad_is_bogus" )
|
||||||
|
|
||||||
|
@ -75,4 +85,12 @@ class TestBer < Test::Unit::TestCase
|
||||||
[1, [3, "Administrator", "ad_is_bogus"]],
|
[1, [3, "Administrator", "ad_is_bogus"]],
|
||||||
s.read_ber( Net::LDAP::AsnSyntax ))
|
s.read_ber( Net::LDAP::AsnSyntax ))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _test_oid
|
||||||
|
oid = Net::BER::BerIdentifiedOid.new( [1,3,6,1,2,1,1,1,0] )
|
||||||
|
assert_equal( "\006\b+\006\001\002\001\001\001\000", oid.to_ber )
|
||||||
|
|
||||||
|
oid = Net::BER::BerIdentifiedOid.new( "1.3.6.1.2.1.1.1.0" )
|
||||||
|
assert_equal( "\006\b+\006\001\002\001\001\001\000", oid.to_ber )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,59 @@
|
||||||
require 'common'
|
require 'common'
|
||||||
|
|
||||||
|
=begin
|
||||||
class TestEntry < Test::Unit::TestCase
|
class TestEntry < Test::Unit::TestCase
|
||||||
def test_entry
|
Commented out until I can make it a spec.
|
||||||
# FIX
|
context "An instance of Entry" do
|
||||||
|
setup do
|
||||||
|
@entry = Net::LDAP::Entry.new 'cn=Barbara,o=corp'
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be initialized with the DN" do
|
||||||
|
assert_equal 'cn=Barbara,o=corp', @entry.dn
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'return an empty array when accessing a nonexistent attribute (index lookup)' do
|
||||||
|
assert_equal [], @entry['sn']
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'return an empty array when accessing a nonexistent attribute (method call)' do
|
||||||
|
assert_equal [], @entry.sn
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'create an attribute on assignment (index lookup)' do
|
||||||
|
@entry['sn'] = 'Jensen'
|
||||||
|
assert_equal ['Jensen'], @entry['sn']
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'create an attribute on assignment (method call)' do
|
||||||
|
@entry.sn = 'Jensen'
|
||||||
|
assert_equal ['Jensen'], @entry.sn
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'have attributes accessible by index lookup' do
|
||||||
|
@entry['sn'] = 'Jensen'
|
||||||
|
assert_equal ['Jensen'], @entry['sn']
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'have attributes accessible using a Symbol as the index' do
|
||||||
|
@entry[:sn] = 'Jensen'
|
||||||
|
assert_equal ['Jensen'], @entry[:sn]
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'have attributes accessible by method call' do
|
||||||
|
@entry['sn'] = 'Jensen'
|
||||||
|
assert_equal ['Jensen'], @entry.sn
|
||||||
|
end
|
||||||
|
|
||||||
|
should 'ignore case of attribute names' do
|
||||||
|
@entry['sn'] = 'Jensen'
|
||||||
|
assert_equal ['Jensen'], @entry.sn
|
||||||
|
assert_equal ['Jensen'], @entry.Sn
|
||||||
|
assert_equal ['Jensen'], @entry.SN
|
||||||
|
assert_equal ['Jensen'], @entry['sn']
|
||||||
|
assert_equal ['Jensen'], @entry['Sn']
|
||||||
|
assert_equal ['Jensen'], @entry['SN']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
|
@ -4,29 +4,38 @@ require 'common'
|
||||||
require 'net/snmp'
|
require 'net/snmp'
|
||||||
|
|
||||||
class TestSnmp < Test::Unit::TestCase
|
class TestSnmp < Test::Unit::TestCase
|
||||||
|
|
||||||
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"
|
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"
|
||||||
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"
|
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"
|
||||||
|
|
||||||
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"
|
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"
|
||||||
|
|
||||||
|
|
||||||
def setup
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_invalid_packet
|
def test_invalid_packet
|
||||||
data = "xxxx"
|
data = "xxxx"
|
||||||
assert_raise( Net::BER::BerError ) {
|
assert_raise(Net::BER::BerError) {
|
||||||
ary = data.read_ber(Net::SNMP::AsnSyntax)
|
ary = data.read_ber(Net::SNMP::AsnSyntax)
|
||||||
}
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# The method String#read_ber! added by Net::BER consumes a well-formed BER
|
||||||
|
# object from the head of a string. If it doesn't find a complete,
|
||||||
|
# well-formed BER object, it returns nil and leaves the string unchanged.
|
||||||
|
# If it finds an object, it returns the object and removes it from the
|
||||||
|
# head of the string. This is good for handling partially-received data
|
||||||
|
# streams, such as from network connections.
|
||||||
|
def _test_consume_string
|
||||||
|
data = "xxx"
|
||||||
|
assert_equal(nil, data.read_ber!)
|
||||||
|
assert_equal("xxx", data)
|
||||||
|
|
||||||
|
data = SnmpGetRequest + "!!!"
|
||||||
|
ary = data.read_ber!(Net::SNMP::AsnSyntax)
|
||||||
|
assert_equal("!!!", data)
|
||||||
|
assert ary.is_a?(Array)
|
||||||
|
assert ary.is_a?(Net::BER::BerIdentifiedArray)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_weird_packet
|
def test_weird_packet
|
||||||
assert_raise( Net::SnmpPdu::Error ) {
|
assert_raise(Net::SnmpPdu::Error) {
|
||||||
Net::SnmpPdu.parse("aaaaaaaaaaaaaa")
|
Net::SnmpPdu.parse("aaaaaaaaaaaaaa")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -35,39 +44,33 @@ Net::SnmpPdu.parse("aaaaaaaaaaaaaa")
|
||||||
data = SnmpGetRequest.dup
|
data = SnmpGetRequest.dup
|
||||||
pkt = data.read_ber(Net::SNMP::AsnSyntax)
|
pkt = data.read_ber(Net::SNMP::AsnSyntax)
|
||||||
assert pkt.is_a?(Net::BER::BerIdentifiedArray)
|
assert pkt.is_a?(Net::BER::BerIdentifiedArray)
|
||||||
assert_equal( 48, pkt.ber_identifier) # Constructed [0], signifies GetRequest
|
assert_equal(48, pkt.ber_identifier) # Constructed [0], signifies GetRequest
|
||||||
|
|
||||||
pdu = Net::SnmpPdu.parse(pkt)
|
pdu = Net::SnmpPdu.parse(pkt)
|
||||||
assert_equal(:get_request, pdu.pdu_type )
|
assert_equal(:get_request, pdu.pdu_type)
|
||||||
assert_equal(16170, pdu.request_id ) # whatever was in the test data. 16170 is not magic.
|
assert_equal(16170, pdu.request_id) # whatever was in the test data. 16170 is not magic.
|
||||||
assert_equal( [[[1,3,6,1,2,1,1,1,0],nil]], pdu.variables )
|
assert_equal([[[1, 3, 6, 1, 2, 1, 1, 1, 0], nil]], pdu.variables)
|
||||||
|
|
||||||
assert_equal( pdu.to_ber_string, SnmpGetRequest )
|
assert_equal(pdu.to_ber_string, SnmpGetRequest)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_empty_pdu
|
def test_empty_pdu
|
||||||
pdu = Net::SnmpPdu.new
|
pdu = Net::SnmpPdu.new
|
||||||
assert_raise( Net::SnmpPdu::Error ) {
|
assert_raise(Net::SnmpPdu::Error) { pdu.to_ber_string }
|
||||||
pdu.to_ber_string
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_malformations
|
def test_malformations
|
||||||
pdu = Net::SnmpPdu.new
|
pdu = Net::SnmpPdu.new
|
||||||
pdu.version = 0
|
pdu.version = 0
|
||||||
pdu.version = 2
|
pdu.version = 2
|
||||||
assert_raise( Net::SnmpPdu::Error ) {
|
assert_raise(Net::SnmpPdu::Error) { pdu.version = 100 }
|
||||||
pdu.version = 100
|
|
||||||
}
|
|
||||||
|
|
||||||
pdu.pdu_type = :get_request
|
pdu.pdu_type = :get_request
|
||||||
pdu.pdu_type = :get_next_request
|
pdu.pdu_type = :get_next_request
|
||||||
pdu.pdu_type = :get_response
|
pdu.pdu_type = :get_response
|
||||||
pdu.pdu_type = :set_request
|
pdu.pdu_type = :set_request
|
||||||
pdu.pdu_type = :trap
|
pdu.pdu_type = :trap
|
||||||
assert_raise( Net::SnmpPdu::Error ) {
|
assert_raise(Net::SnmpPdu::Error) { pdu.pdu_type = :something_else }
|
||||||
pdu.pdu_type = :something_else
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_make_response
|
def test_make_response
|
||||||
|
@ -78,9 +81,9 @@ pdu.to_ber_string
|
||||||
pdu.request_id = 9999
|
pdu.request_id = 9999
|
||||||
pdu.error_status = 0
|
pdu.error_status = 0
|
||||||
pdu.error_index = 0
|
pdu.error_index = 0
|
||||||
pdu.add_variable_binding [1,3,6,1,2,1,1,1,0], "test"
|
pdu.add_variable_binding [1, 3, 6, 1, 2, 1, 1, 1, 0], "test"
|
||||||
|
|
||||||
assert_equal( SnmpGetResponse, pdu.to_ber_string )
|
assert_equal(SnmpGetResponse, pdu.to_ber_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_make_bad_response
|
def test_make_bad_response
|
||||||
|
@ -94,20 +97,18 @@ pdu.to_ber_string
|
||||||
|
|
||||||
def test_snmp_integers
|
def test_snmp_integers
|
||||||
c32 = Net::SNMP::Counter32.new(100)
|
c32 = Net::SNMP::Counter32.new(100)
|
||||||
assert_equal( "A\001d", c32.to_ber )
|
assert_equal("A\001d", c32.to_ber)
|
||||||
g32 = Net::SNMP::Gauge32.new(100)
|
g32 = Net::SNMP::Gauge32.new(100)
|
||||||
assert_equal( "B\001d", g32.to_ber )
|
assert_equal("B\001d", g32.to_ber)
|
||||||
t32 = Net::SNMP::TimeTicks32.new(100)
|
t32 = Net::SNMP::TimeTicks32.new(100)
|
||||||
assert_equal( "C\001d", t32.to_ber )
|
assert_equal("C\001d", t32.to_ber)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_community
|
def test_community
|
||||||
data = SnmpGetRequestXXX.dup
|
data = SnmpGetRequestXXX.dup
|
||||||
ary = data.read_ber(Net::SNMP::AsnSyntax)
|
ary = data.read_ber(Net::SNMP::AsnSyntax)
|
||||||
pdu = Net::SnmpPdu.parse( ary )
|
pdu = Net::SnmpPdu.parse(ary)
|
||||||
assert_equal( "xxxxxx", pdu.community )
|
assert_equal("xxxxxx", pdu.community)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue