Class: Mu::Xtractr::Packet::Test

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/mu/xtractr/test/tc_packet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xtractrObject (readonly)

Returns the value of attribute xtractr.



22
23
24
# File 'lib/mu/xtractr/test/tc_packet.rb', line 22

def xtractr
  @xtractr
end

Instance Method Details

#setupObject



24
25
26
# File 'lib/mu/xtractr/test/tc_packet.rb', line 24

def setup
    @xtractr = Xtractr.new
end

#test_attributesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mu/xtractr/test/tc_packet.rb', line 32

def test_attributes
    pkt = xtractr.packets('pkt.service:HTTP').first
    assert_equal(6, pkt.id)
    assert_equal(606, pkt.offset)
    assert_equal(412, pkt.length)
    assert_equal(0.313968, pkt.time)
    assert_equal(0, pkt.dir)
    assert_kind_of(Host, pkt.src)
    assert_equal('192.168.1.10', pkt.src.address)
    assert_kind_of(Host, pkt.dst)
    assert_equal('8.18.65.67', pkt.dst.address)
    assert_kind_of(Service, pkt.service)
    assert_equal('HTTP', pkt.service.name)
    assert_equal('GET /WebObjects/MZStore.woa/wa/viewGrouping?id=39 HTTP/1.1 ', pkt.title)
    
    assert_equal(2, pkt.instance_variable_get(:@flow_id))
    assert_nil(pkt.instance_variable_get(:@flow))
    flow = pkt.flow
    assert_kind_of(Flow, flow)
    assert_equal(2, flow.id)
    assert_not_nil(pkt.instance_variable_get(:@flow))
    flow2 = pkt.flow
    assert_equal(flow.__id__, flow2.__id__)
end

#test_bytesObject



57
58
59
60
61
62
# File 'lib/mu/xtractr/test/tc_packet.rb', line 57

def test_bytes
    pkt = xtractr.packets('pkt.service:HTTP').first
    bytes = pkt.bytes
    assert_equal(412, bytes.size)
    assert_match(/WebObjects/, bytes)
end

#test_eachObject



71
72
73
74
75
76
77
78
79
# File 'lib/mu/xtractr/test/tc_packet.rb', line 71

def test_each
    pkt = xtractr.packets('pkt.service:HTTP').first
    pkt.each { |fv| assert_kind_of(Field::Value, fv) }
    pkt.each(/ip.ttl/) do |fv| 
        assert_kind_of(Field::Value, fv)
        assert_match(/ip\.ttl/, fv.field.name)
    end
    pkt.each_field { |fv| assert_kind_of(Field::Value, fv) }
end

#test_fieldObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mu/xtractr/test/tc_packet.rb', line 81

def test_field
    pkt = xtractr.packets('pkt.service:HTTP').first
    values = pkt['http.request.method']
    assert_kind_of(Array, values)
    assert_equal(1, values.size)
    assert_equal("GET", values[0])
    
    values = pkt.field 'http.request.method'
    assert_kind_of(Array, values)
    assert_equal(1, values.size)
    assert_equal("GET", values[0])
end

#test_inspectObject



104
105
106
# File 'lib/mu/xtractr/test/tc_packet.rb', line 104

def test_inspect
    assert_nothing_raised { xtractr.packets('pkt.service:DNS').first.inspect }
end

#test_PacketObject



28
29
30
# File 'lib/mu/xtractr/test/tc_packet.rb', line 28

def test_Packet
    assert(Packet.ancestors.include?(Enumerable), "Packet doesn't mixin Enumerable")
end

#test_payloadObject



64
65
66
67
68
69
# File 'lib/mu/xtractr/test/tc_packet.rb', line 64

def test_payload
    pkt = xtractr.packets('pkt.service:HTTP').first
    payload = pkt.payload
    assert_equal(346, payload.size)
    assert_match(/^GET/, payload)
end

#test_saveObject



94
95
96
97
98
99
100
101
102
# File 'lib/mu/xtractr/test/tc_packet.rb', line 94

def test_save
    filename = '/tmp/foo.pcap'
    pkt = xtractr.packets('pkt.service:HTTP').first
    pkt.save filename
    assert_equal(true, File.exist?(filename))
    assert_equal(452, File.size(filename))
ensure
    File.unlink filename
end