Skip to content

Commit

Permalink
pdml2json test implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Enteee committed May 3, 2016
1 parent bbadcb1 commit 1247f73
Show file tree
Hide file tree
Showing 5 changed files with 599 additions and 8 deletions.
22 changes: 14 additions & 8 deletions test/pdml2flow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,44 @@
from pdml2flow.conf import Conf
import pdml2flow

TEST_DIR="test/data/"
TEST_DIR_PDML2FLOW="test/pdml2flow_tests/"
TEST_DIR_PDML2JSON="test/pdml2json_tests/"

class TestPdml2Flow(TestCase):

def test_pdml2flow(self):
for test in os.listdir(TEST_DIR):
def system_test(self, run, directory):
for test in os.listdir(directory):
with self.subTest(test=test):
with open('{}/{}/stdin'.format(TEST_DIR, test)) as f_stdin, \
with open('{}/{}/stdin'.format(directory, test)) as f_stdin, \
io.StringIO() as f_stdout, \
io.StringIO() as f_stderr:
# set stdin & stdout
Conf.IN = f_stdin
Conf.OUT = f_stdout
try:
# try to load arguments
with open('{}/{}/args'.format(TEST_DIR, test)) as f:
with open('{}/{}/args'.format(directory, test)) as f:
Conf.ARGS = f.read()
except FileNotFoundError:
Conf.ARGS = ''
# run
pdml2flow.pdml2flow()
run()
# compare stdout
with open('{}/{}/stdout'.format(TEST_DIR, test)) as f:
with open('{}/{}/stdout'.format(directory, test)) as f:
expected = json.loads(f.read())
self.assertEqual(expected, json.loads(f_stdout.getvalue()))
try:
# try compare stderr
with open('{}/{}/stderr'.format(TEST_DIR, test)) as f:
with open('{}/{}/stderr'.format(directory, test)) as f:
expected = c_stdout.read()
self.assertEqual(expected, f_stderr.getvalue())
except FileNotFoundError:
pass

def test_pdml2flow(self):
self.system_test(pdml2flow.pdml2flow, TEST_DIR_PDML2FLOW)

def test_pdml2json(self):
self.system_test(pdml2flow.pdml2flow, TEST_DIR_PDML2FLOW)
if __name__ == '__main__':
unittest.main()
File renamed without changes.
File renamed without changes.
132 changes: 132 additions & 0 deletions test/pdml2json_tests/first/stdin
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="pdml2html.xsl"?>
<!-- You can find pdml2html.xsl in /usr/share/wireshark or at https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=pdml2html.xsl. -->
<pdml version="0" creator="wireshark/2.0.3" time="Tue May 3 12:08:03 2016" capture_file="">
<packet>
<proto name="geninfo" pos="0" showname="General information" size="66">
<field name="num" pos="0" show="1" showname="Number" value="1" size="66"/>
<field name="len" pos="0" show="66" showname="Frame Length" value="42" size="66"/>
<field name="caplen" pos="0" show="66" showname="Captured Length" value="42" size="66"/>
<field name="timestamp" pos="0" show="May 3, 2016 12:08:03.644608216 CEST" showname="Captured Time" value="1462270083.644608216" size="66"/>
</proto>
<proto name="frame" showname="Frame 1: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0" size="66" pos="0">
<field name="frame.interface_id" showname="Interface id: 0 (eth0)" size="0" pos="0" show="0"/>
<field name="frame.encap_type" showname="Encapsulation type: Ethernet (1)" size="0" pos="0" show="1"/>
<field name="frame.time" showname="Arrival Time: May 3, 2016 12:08:03.644608216 CEST" size="0" pos="0" show="May 3, 2016 12:08:03.644608216 CEST"/>
<field name="frame.offset_shift" showname="Time shift for this packet: 0.000000000 seconds" size="0" pos="0" show="0.000000000"/>
<field name="frame.time_epoch" showname="Epoch Time: 1462270083.644608216 seconds" size="0" pos="0" show="1462270083.644608216"/>
<field name="frame.time_delta" showname="Time delta from previous captured frame: 0.000000000 seconds" size="0" pos="0" show="0.000000000"/>
<field name="frame.time_delta_displayed" showname="Time delta from previous displayed frame: 0.000000000 seconds" size="0" pos="0" show="0.000000000"/>
<field name="frame.time_relative" showname="Time since reference or first frame: 0.000000000 seconds" size="0" pos="0" show="0.000000000"/>
<field name="frame.number" showname="Frame Number: 1" size="0" pos="0" show="1"/>
<field name="frame.len" showname="Frame Length: 66 bytes (528 bits)" size="0" pos="0" show="66"/>
<field name="frame.cap_len" showname="Capture Length: 66 bytes (528 bits)" size="0" pos="0" show="66"/>
<field name="frame.marked" showname="Frame is marked: False" size="0" pos="0" show="0"/>
<field name="frame.ignored" showname="Frame is ignored: False" size="0" pos="0" show="0"/>
<field name="frame.protocols" showname="Protocols in frame: eth:ethertype:ip:tcp" size="0" pos="0" show="eth:ethertype:ip:tcp"/>
</proto>
<proto name="eth" showname="Ethernet II, Src: AsustekC_ba:a3:9f (10:bf:48:ba:a3:9f), Dst: IETF-VRRP-VRID_11 (00:00:5e:00:01:11)" size="14" pos="0">
<field name="eth.dst" showname="Destination: IETF-VRRP-VRID_11 (00:00:5e:00:01:11)" size="6" pos="0" show="00:00:5e:00:01:11" value="00005e000111">
<field name="eth.dst_resolved" showname="Destination (resolved): IETF-VRRP-VRID_11" hide="yes" size="6" pos="0" show="IETF-VRRP-VRID_11" value="00005e000111"/>
<field name="eth.addr" showname="Address: IETF-VRRP-VRID_11 (00:00:5e:00:01:11)" size="6" pos="0" show="00:00:5e:00:01:11" value="00005e000111"/>
<field name="eth.addr_resolved" showname="Address (resolved): IETF-VRRP-VRID_11" hide="yes" size="6" pos="0" show="IETF-VRRP-VRID_11" value="00005e000111"/>
<field name="eth.lg" showname=".... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)" size="3" pos="0" show="0" value="0" unmaskedvalue="00005e"/>
<field name="eth.ig" showname=".... ...0 .... .... .... .... = IG bit: Individual address (unicast)" size="3" pos="0" show="0" value="0" unmaskedvalue="00005e"/>
</field>
<field name="eth.src" showname="Source: AsustekC_ba:a3:9f (10:bf:48:ba:a3:9f)" size="6" pos="6" show="10:bf:48:ba:a3:9f" value="10bf48baa39f">
<field name="eth.src_resolved" showname="Source (resolved): AsustekC_ba:a3:9f" hide="yes" size="6" pos="6" show="AsustekC_ba:a3:9f" value="10bf48baa39f"/>
<field name="eth.addr" showname="Address: AsustekC_ba:a3:9f (10:bf:48:ba:a3:9f)" size="6" pos="6" show="10:bf:48:ba:a3:9f" value="10bf48baa39f"/>
<field name="eth.addr_resolved" showname="Address (resolved): AsustekC_ba:a3:9f" hide="yes" size="6" pos="6" show="AsustekC_ba:a3:9f" value="10bf48baa39f"/>
<field name="eth.lg" showname=".... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)" size="3" pos="6" show="0" value="0" unmaskedvalue="10bf48"/>
<field name="eth.ig" showname=".... ...0 .... .... .... .... = IG bit: Individual address (unicast)" size="3" pos="6" show="0" value="0" unmaskedvalue="10bf48"/>
</field>
<field name="eth.type" showname="Type: IPv4 (0x0800)" size="2" pos="12" show="0x00000800" value="0800"/>
</proto>
<proto name="ip" showname="Internet Protocol Version 4, Src: 10.20.5.161, Dst: 71.19.149.209" size="20" pos="14">
<field name="ip.version" showname="0100 .... = Version: 4" size="1" pos="14" show="4" value="4" unmaskedvalue="45"/>
<field name="ip.hdr_len" showname=".... 0101 = Header Length: 20 bytes" size="1" pos="14" show="5" value="5" unmaskedvalue="45"/>
<field name="ip.dsfield" showname="Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)" size="1" pos="15" show="0x00000000" value="00">
<field name="ip.dsfield.dscp" showname="0000 00.. = Differentiated Services Codepoint: Default (0)" size="1" pos="15" show="0" value="0" unmaskedvalue="00"/>
<field name="ip.dsfield.ecn" showname=".... ..00 = Explicit Congestion Notification: Not ECN-Capable Transport (0)" size="1" pos="15" show="0" value="0" unmaskedvalue="00"/>
</field>
<field name="ip.len" showname="Total Length: 52" size="2" pos="16" show="52" value="0034"/>
<field name="ip.id" showname="Identification: 0x96ab (38571)" size="2" pos="18" show="0x000096ab" value="96ab"/>
<field name="ip.flags" showname="Flags: 0x02 (Don&#x27;t Fragment)" size="1" pos="20" show="0x00000002" value="40">
<field name="ip.flags.rb" showname="0... .... = Reserved bit: Not set" size="1" pos="20" show="0" value="40"/>
<field name="ip.flags.df" showname=".1.. .... = Don&#x27;t fragment: Set" size="1" pos="20" show="1" value="40"/>
<field name="ip.flags.mf" showname="..0. .... = More fragments: Not set" size="1" pos="20" show="0" value="40"/>
</field>
<field name="ip.frag_offset" showname="Fragment offset: 0" size="2" pos="20" show="0" value="4000"/>
<field name="ip.ttl" showname="Time to live: 64" size="1" pos="22" show="64" value="40"/>
<field name="ip.proto" showname="Protocol: TCP (6)" size="1" pos="23" show="6" value="06"/>
<field name="ip.checksum" showname="Header checksum: 0xb77f [validation disabled]" size="2" pos="24" show="0x0000b77f" value="b77f">
<field name="ip.checksum_good" showname="Good: False" size="2" pos="24" show="0" value="b77f"/>
<field name="ip.checksum_bad" showname="Bad: False" size="2" pos="24" show="0" value="b77f"/>
</field>
<field name="ip.src" showname="Source: 10.20.5.161" size="4" pos="26" show="10.20.5.161" value="0a1405a1"/>
<field name="ip.addr" showname="Source or Destination Address: 10.20.5.161" hide="yes" size="4" pos="26" show="10.20.5.161" value="0a1405a1"/>
<field name="ip.src_host" showname="Source Host: 10.20.5.161" hide="yes" size="4" pos="26" show="10.20.5.161" value="0a1405a1"/>
<field name="ip.host" showname="Source or Destination Host: 10.20.5.161" hide="yes" size="4" pos="26" show="10.20.5.161" value="0a1405a1"/>
<field name="ip.dst" showname="Destination: 71.19.149.209" size="4" pos="30" show="71.19.149.209" value="471395d1"/>
<field name="ip.addr" showname="Source or Destination Address: 71.19.149.209" hide="yes" size="4" pos="30" show="71.19.149.209" value="471395d1"/>
<field name="ip.dst_host" showname="Destination Host: 71.19.149.209" hide="yes" size="4" pos="30" show="71.19.149.209" value="471395d1"/>
<field name="ip.host" showname="Source or Destination Host: 71.19.149.209" hide="yes" size="4" pos="30" show="71.19.149.209" value="471395d1"/>
<field name="" show="Source GeoIP: Unknown" size="4" pos="26" value="0a1405a1"/>
<field name="" show="Destination GeoIP: Unknown" size="4" pos="30" value="471395d1"/>
</proto>
<proto name="tcp" showname="Transmission Control Protocol, Src Port: 42852 (42852), Dst Port: 9630 (9630), Seq: 1, Ack: 1, Len: 0" size="32" pos="34">
<field name="tcp.srcport" showname="Source Port: 42852" size="2" pos="34" show="42852" value="a764"/>
<field name="tcp.dstport" showname="Destination Port: 9630" size="2" pos="36" show="9630" value="259e"/>
<field name="tcp.port" showname="Source or Destination Port: 42852" hide="yes" size="2" pos="34" show="42852" value="a764"/>
<field name="tcp.port" showname="Source or Destination Port: 9630" hide="yes" size="2" pos="36" show="9630" value="259e"/>
<field name="tcp.stream" showname="Stream index: 0" size="0" pos="34" show="0"/>
<field name="tcp.len" showname="TCP Segment Len: 0" size="1" pos="46" show="0" value="80"/>
<field name="tcp.seq" showname="Sequence number: 1 (relative sequence number)" size="4" pos="38" show="1" value="c3f5a291"/>
<field name="tcp.ack" showname="Acknowledgment number: 1 (relative ack number)" size="4" pos="42" show="1" value="c9a7a7f5"/>
<field name="tcp.hdr_len" showname="Header Length: 32 bytes" size="1" pos="46" show="32" value="80"/>
<field name="tcp.flags" showname="Flags: 0x010 (ACK)" size="2" pos="46" show="0x00000010" value="10" unmaskedvalue="8010">
<field name="tcp.flags.res" showname="000. .... .... = Reserved: Not set" size="1" pos="46" show="0" value="0" unmaskedvalue="80"/>
<field name="tcp.flags.ns" showname="...0 .... .... = Nonce: Not set" size="1" pos="46" show="0" value="0" unmaskedvalue="80"/>
<field name="tcp.flags.cwr" showname=".... 0... .... = Congestion Window Reduced (CWR): Not set" size="1" pos="47" show="0" value="0" unmaskedvalue="10"/>
<field name="tcp.flags.ecn" showname=".... .0.. .... = ECN-Echo: Not set" size="1" pos="47" show="0" value="0" unmaskedvalue="10"/>
<field name="tcp.flags.urg" showname=".... ..0. .... = Urgent: Not set" size="1" pos="47" show="0" value="0" unmaskedvalue="10"/>
<field name="tcp.flags.ack" showname=".... ...1 .... = Acknowledgment: Set" size="1" pos="47" show="1" value="FFFFFFFFFFFFFFFF" unmaskedvalue="10"/>
<field name="tcp.flags.push" showname=".... .... 0... = Push: Not set" size="1" pos="47" show="0" value="0" unmaskedvalue="10"/>
<field name="tcp.flags.reset" showname=".... .... .0.. = Reset: Not set" size="1" pos="47" show="0" value="0" unmaskedvalue="10"/>
<field name="tcp.flags.syn" showname=".... .... ..0. = Syn: Not set" size="1" pos="47" show="0" value="0" unmaskedvalue="10"/>
<field name="tcp.flags.fin" showname=".... .... ...0 = Fin: Not set" size="1" pos="47" show="0" value="0" unmaskedvalue="10"/>
<field name="tcp.flags.str" showname="TCP Flags: *******A****" size="2" pos="46" show="*******A****" value="8010"/>
</field>
<field name="tcp.window_size_value" showname="Window size value: 360" size="2" pos="48" show="360" value="0168"/>
<field name="tcp.window_size" showname="Calculated window size: 360" size="2" pos="48" show="360" value="0168"/>
<field name="tcp.window_size_scalefactor" showname="Window size scaling factor: -1 (unknown)" size="2" pos="48" show="-1" value="0168"/>
<field name="tcp.checksum" showname="Checksum: 0x7c69 [validation disabled]" size="2" pos="50" show="0x00007c69" value="7c69">
<field name="tcp.checksum_good" showname="Good Checksum: False" size="2" pos="50" show="0" value="7c69"/>
<field name="tcp.checksum_bad" showname="Bad Checksum: False" size="2" pos="50" show="0" value="7c69"/>
</field>
<field name="tcp.urgent_pointer" showname="Urgent pointer: 0" size="2" pos="52" show="0" value="0000"/>
<field name="tcp.options" showname="Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps" size="12" pos="54" show="01:01:08:0a:01:7a:e6:87:d9:e9:a5:3f" value="0101080a017ae687d9e9a53f">
<field name="" show="No-Operation (NOP)" size="1" pos="54" value="01">
<field name="tcp.options.type" showname="Type: 1" size="1" pos="54" show="1" value="01">
<field name="tcp.options.type.copy" showname="0... .... = Copy on fragmentation: No" size="1" pos="54" show="0" value="0" unmaskedvalue="01"/>
<field name="tcp.options.type.class" showname=".00. .... = Class: Control (0)" size="1" pos="54" show="0" value="0" unmaskedvalue="01"/>
<field name="tcp.options.type.number" showname="...0 0001 = Number: No-Operation (NOP) (1)" size="1" pos="54" show="1" value="1" unmaskedvalue="01"/>
</field>
</field>
<field name="" show="No-Operation (NOP)" size="1" pos="55" value="01">
<field name="tcp.options.type" showname="Type: 1" size="1" pos="55" show="1" value="01">
<field name="tcp.options.type.copy" showname="0... .... = Copy on fragmentation: No" size="1" pos="55" show="0" value="0" unmaskedvalue="01"/>
<field name="tcp.options.type.class" showname=".00. .... = Class: Control (0)" size="1" pos="55" show="0" value="0" unmaskedvalue="01"/>
<field name="tcp.options.type.number" showname="...0 0001 = Number: No-Operation (NOP) (1)" size="1" pos="55" show="1" value="1" unmaskedvalue="01"/>
</field>
</field>
<field name="" show="Timestamps: TSval 24831623, TSecr 3655968063" size="10" pos="56" value="080a017ae687d9e9a53f">
<field name="tcp.option_kind" showname="Kind: Time Stamp Option (8)" size="1" pos="56" show="8" value="08"/>
<field name="tcp.option_len" showname="Length: 10" size="1" pos="57" show="10" value="0a"/>
<field name="tcp.options.timestamp.tsval" showname="Timestamp value: 24831623" size="4" pos="58" show="24831623" value="017ae687"/>
<field name="tcp.options.timestamp.tsecr" showname="Timestamp echo reply: 3655968063" size="4" pos="62" show="3655968063" value="d9e9a53f"/>
</field>
</field>
</proto>
</packet>
</pdml>
Loading

0 comments on commit 1247f73

Please sign in to comment.