Class: Rex::Proto::DRDA::UnitTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- Rex::Proto::DRDA::UnitTest
- Defined in:
- lib/rex/proto/drda/packet.rb.ut.rb
Constant Summary collapse
Instance Method Summary collapse
-
#test_all_ddm_codepoints ⇒ Object
Similarly, so should DDM Structs.
-
#test_all_param_codepoints ⇒ Object
All parameter names should have a corresponding codepoint, except “DDM_PARAM” (a generic parameter).
-
#test_ddm_struct ⇒ Object
Make some similiar assertions about DDMs, though specific DDMs will have particular elements after the codepoint, usually more than one.
-
#test_mgrlvlls_param ⇒ Object
Test a sample param.
-
#test_param_struct ⇒ Object
Ensure that all params have the same struct.
-
#test_secchk_ddm ⇒ Object
Test a sample ddm.
-
#test_server_packet_read ⇒ Object
Exercise the SERVER_PACKET#read function with a sample packet.
-
#test_server_packet_structure ⇒ Object
The server packet is special since it’s an Array of BASIC_DDM’s, and doesn’t have a particular, fixed struct.
Instance Method Details
#test_all_ddm_codepoints ⇒ Object
Similarly, so should DDM Structs.
42 43 44 45 46 47 48 49 50 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 42 def test_all_ddm_codepoints ddms = Klass.constants.map {|x| x if x =~ /DDM$/}.compact assert_operator ddms.size, :>=, 4 # Allow for more later. ddms.each do |p| cp = p.split(/_DDM/).first next if cp == "BASIC" assert_kind_of Numeric, Konst.const_get(cp) end end |
#test_all_param_codepoints ⇒ Object
All parameter names should have a corresponding codepoint, except “DDM_PARAM” (a generic parameter).
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 30 def test_all_param_codepoints params = Klass.constants.map {|x| x if x =~ /PARAM$/}.compact assert_operator params.size, :>=, 6 # Allow for more later. params.each do |p| cp = p.split(/_PARAM/).first next if cp == "DDM" assert Konst.const_defined? cp assert_kind_of Numeric, Konst.const_get(cp) end end |
#test_ddm_struct ⇒ Object
Make some similiar assertions about DDMs, though specific DDMs will have particular elements after the codepoint, usually more than one.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 67 def test_ddm_struct ddms = Klass.constants.map {|x| x if x =~ /DDM$/}.compact ddms.each do |d| obj = Klass.const_get(d).new assert_operator obj.size, :>=, 7 assert_respond_to obj, :length assert_respond_to obj, :magic assert_respond_to obj, :format assert_respond_to obj, :correlid assert_respond_to obj, :length2 assert_respond_to obj, :codepoint end end |
#test_mgrlvlls_param ⇒ Object
Test a sample param
15 16 17 18 19 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 15 def test_mgrlvlls_param p = Klass::MGRLVLLS_PARAM.new assert_kind_of(Struct, p) assert_equal(Konst::MGRLVLLS, p.codepoint) end |
#test_param_struct ⇒ Object
Ensure that all params have the same struct.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 53 def test_param_struct params = Klass.constants.map {|x| x if x =~ /PARAM$/}.compact params.each do |p| obj = Klass.const_get(p).new assert_equal 3, obj.size assert_respond_to obj, :codepoint assert_respond_to obj, :length assert_respond_to obj, :payload end end |
#test_secchk_ddm ⇒ Object
Test a sample ddm
22 23 24 25 26 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 22 def test_secchk_ddm d = Klass::SECCHK_DDM.new assert_kind_of Struct, d assert_equal Konst::SECCHK, d.codepoint end |
#test_server_packet_read ⇒ Object
Exercise the SERVER_PACKET#read function with a sample packet.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 94 def test_server_packet_read pkt = "0015d0420001000f1219000611490000000511a4000050d0520002004a2201000611490000000c112ee2d8d3f0f8f0f2f4000d002fd8e3c4e2d8d3e7f8f6000a00350006119c033300062103022e00172135c3f0c1f8f6c1f0f14bc5c6f1f2070402195612008cd0030002008624080000000000303030303053514c303830323400ffffffff0200000000000000030000000000000000000000202020202020202020202000124d59444232444220202020202020202020200000003331ff383139ff4d59555345522020ff4d594442324442ff514442322f4c494e5558ff353538ff353538ff30ff31323038ff30ffff".scan(/../).map {|x| x.to_i(16).chr}.join s = Klass::SERVER_PACKET.new assert_equal 0, s.size s.read(pkt) assert_equal 3, s.size assert_equal Konst::SECCHKRM, s[0].codepoint assert_equal Konst::ACCRDBRM, s[1].codepoint assert_equal Konst::SQLCARD, s[2].codepoint assert_equal 0xd0, s[0].magic assert_equal 0x52, s[1].format assert_equal 134, s[2].length2 assert_equal 21+80+140, s.sz end |
#test_server_packet_structure ⇒ Object
The server packet is special since it’s an Array of BASIC_DDM’s, and doesn’t have a particular, fixed struct. (It would be nice to build those up on the fly, but we’re not really interested in validating most server responses right now.
85 86 87 88 89 90 91 |
# File 'lib/rex/proto/drda/packet.rb.ut.rb', line 85 def test_server_packet_structure s = Klass::SERVER_PACKET.new assert_kind_of Array, s assert_respond_to s, :to_s assert_respond_to s, :sz assert_respond_to s, :read end |