Class: Mu::Xtractr::Test
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- Mu::Xtractr::Test
- Defined in:
- lib/mu/xtractr/test/tc_xtractr.rb
Instance Attribute Summary collapse
-
#xtractr ⇒ Object
readonly
Returns the value of attribute xtractr.
Instance Method Summary collapse
- #setup ⇒ Object
- #test_about ⇒ Object
- #test_field ⇒ Object
- #test_fields ⇒ Object
- #test_flow ⇒ Object
- #test_flows ⇒ Object
- #test_host ⇒ Object
- #test_hosts ⇒ Object
- #test_packet ⇒ Object
- #test_packets ⇒ Object
- #test_service ⇒ Object
- #test_services ⇒ Object
Instance Attribute Details
#xtractr ⇒ Object (readonly)
Returns the value of attribute xtractr.
21 22 23 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 21 def xtractr @xtractr end |
Instance Method Details
#setup ⇒ Object
23 24 25 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 23 def setup @xtractr = Xtractr.new end |
#test_about ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 27 def test_about about = xtractr.about assert_equal(1778, about.packets) assert_equal(32, about.flows) assert_equal(12, about.hosts) assert_equal(5, about.services) assert_equal(171.172, about.duration) end |
#test_field ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 94 def test_field [ 'pkt.src', 'pkt.dst', 'pkt.flow', 'pkt.id', 'pkt.pcap', 'pkt.first', 'pkt.dir', 'pkt.time', 'pkt.offset', 'pkt.length', 'pkt.service', 'pkt.title' ].each do |name| assert_nothing_raised { xtractr.field name } end assert_raise(ArgumentError) { xtractr.field 'blah' } end |
#test_fields ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 85 def test_fields fields = xtractr.fields assert_equal(170, fields.size) fields.each { |field| assert_instance_of(Field, field) } assert_equal(12, xtractr.fields(/^pkt\./).size) assert_equal(12, xtractr.fields("PKT.").size) assert_equal(12, xtractr.fields("pkt.").size) end |
#test_flow ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 120 def test_flow flow = xtractr.flow 1 assert_kind_of(Flow, flow) assert_raise(ArgumentError) do flow = xtractr.flow xtractr.about.flows+1 end end |
#test_flows ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 105 def test_flows flows = xtractr.flows assert_kind_of(Flows, flows) assert_equal('*', flows.q) flows = xtractr.flows 'blah:foo' assert_equal('blah:foo', flows.q) flows = xtractr.flows 1..10 assert_equal('flow.id:[1 10]', flows.q) flows = xtractr.flows 1...10 assert_equal('flow.id:[1 9]', flows.q) end |
#test_host ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 46 def test_host [ '4.2.2.1', '8.18.65.67', '8.18.65.32', '8.18.65.58', '8.18.65.82', '8.18.65.27', '8.18.65.10', '8.18.65.88', '8.18.65.89', '66.235.132.121', '192.168.1.10', '224.0.0.251', ].each do |address| assert_nothing_raised { xtractr.host address } end assert_raise(ArgumentError) { xtractr.host '1.1.1.1' } end |
#test_hosts ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 36 def test_hosts hosts = xtractr.hosts assert_equal(12, hosts.size) hosts.each { |host| assert_instance_of(Host, host) } assert_equal(8, xtractr.hosts(/^8.18/).size) assert_equal(8, xtractr.hosts('8.18').size) assert_equal(1, xtractr.hosts(/^4.2/).size) assert_equal(1, xtractr.hosts('4.2').size) end |
#test_packet ⇒ Object
144 145 146 147 148 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 144 def test_packet pkt = xtractr.packet 1 assert_kind_of(Packet, pkt) assert_equal(1, pkt.id) end |
#test_packets ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 129 def test_packets packets = xtractr.packets assert_kind_of(Packets, packets) assert_equal('*', packets.q) packets = xtractr.packets 'blah:foo' assert_equal('blah:foo', packets.q) packets = xtractr.packets 1..10 assert_equal('pkt.id:[1 10]', packets.q) packets = xtractr.packets 1...10 assert_equal('pkt.id:[1 9]', packets.q) end |
#test_service ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 76 def test_service [ 'DNS', 'TCP', 'HTTP', 'HTTP/XML', 'MDNS' ].each do |name| assert_nothing_raised { xtractr.service name } assert_nothing_raised { xtractr.service name.downcase } end assert_raise(ArgumentError) { xtractr.service 'blah' } end |
#test_services ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/mu/xtractr/test/tc_xtractr.rb', line 67 def test_services services = xtractr.services assert_equal(5, services.size) services.each { |service| assert_instance_of(Service, service) } assert_equal(2, xtractr.services(/HTTP/).size) assert_equal(2, xtractr.services('HTTP').size) assert_equal(2, xtractr.services('http').size) end |