Procházet zdrojové kódy

Added regression-test

Denis Waßmann před 6 roky
rodič
revize
9e26162d21

+ 103 - 0
test/TestUtil.py

@@ -2,6 +2,9 @@
 
 import scapy.all
 import scapy.packet
+import shlex
+import subprocess
+import os
 
 
 # You could compare pcaps by byte or by hash too, but this class tells you
@@ -44,6 +47,106 @@ class PcapComparator:
         raise AssertionError(message)
 
 
+class ID2TExecution:
+    ID2T_PATH = ".."
+    ID2T_LOCATION = ID2T_PATH + "/" + "id2t"
+
+    OUTPUT_FILES_PREFIX_LINE = "Output files created:"
+
+    def __init__(self, input_filename, id2t_path=ID2T_LOCATION, seed=None):
+        self.input_file = input_filename
+        self.seed = str(seed)
+        self.id2t_path = id2t_path
+
+        self.generated_files = [] # files generated by id2t
+        self.keep_files = []
+        self.return_code = None
+        self.id2t_output = None
+
+    def has_run(self):
+        return self.return_code is not None
+
+    def run(self, parameters):
+        if self.has_run():
+            raise RuntimeError("This instance has already run and can't do it again")
+
+        command = self.get_run_command(parameters)
+        return_code, output = subprocess.getstatusoutput(command)
+        self.return_code = return_code
+        self.id2t_output = output
+
+        self.generated_files = self._parse_files(output)
+
+    def get_run_command(self, parameters):
+        command_args = [self.id2t_path, "-i", self.input_file]
+        if self.seed is not None:
+            command_args.extend(["--seed", self.seed])
+        command_args.extend(["-a", "MembersMgmtCommAttack"])
+        command_args.extend(parameters)
+
+        return " ".join(map(shlex.quote, command_args))
+
+    def _parse_files(self, program_output: str) -> "list[str]":
+        lines = program_output.split(os.linesep)
+
+        if self.OUTPUT_FILES_PREFIX_LINE not in lines:
+            raise AssertionError("The magic string is not in the program output anymore, has the program output structure changed?")
+        index = lines.index(self.OUTPUT_FILES_PREFIX_LINE)
+
+        return lines[index + 1:]
+
+    def get_pcap_filename(self):
+        self._require_run()
+        return self._find_pcap()
+
+    def get_output(self):
+        self._require_run()
+        return self.id2t_output
+
+    def get_return_code(self):
+        self._require_run()
+        return self.return_code
+
+    def keep_file(self, file):
+        self._require_run()
+
+        if file not in self.generated_files:
+            raise ValueError("%s is not generated by id2t" % file)
+        if file not in self.keep_files:
+            self.keep_files.append()
+
+    def get_kept_files(self):
+        self._require_run()
+        return self.keep_files
+
+    def get_generated_files(self):
+        self._require_run()
+        return self.generated_files
+
+    def get_files_for_deletion(self):
+        self._require_run()
+        return [file for file in self.generated_files if file not in self.keep_files]
+
+    def _find_pcap(self) -> str:
+        return next(file for file in self.generated_files if file.endswith(".pcap"))
+
+    def _require_run(self):
+        if not self.has_run():
+            raise RuntimeError("You have to execute run() before you can call this method")
+
+    def cleanup(self):
+        if self.has_run():
+            id2t_relative = os.path.dirname(self.id2t_path)
+
+            for file in self.get_files_for_deletion():
+                try:
+                    os.unlink(id2t_relative + "/" + file)
+                except: pass
+
+    def __del__(self):
+        self.cleanup()
+
+
 if __name__ == "__main__":
     import sys
 

+ 15 - 0
test/regression_files/fileinfo.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<!--
+This file contains the information on how to recreate the files used for
+regression testing. For every file there is a test that contains the file, the
+rng-seed, a name for the test and a list of parameters. The regression test
+will attempt to recreate all of these files via the parameters given and
+compare the newly created files to the existing ones.
+
+Paths are relative to this files location
+-->
+<tests>
+    <test name="first_test" infile="../../resources/telnet-raw.pcap" outfile="telnet_regression.pcap" seed="42">
+        <param key="hidden_mark" value="True"/>
+    </test>
+</tests>

binární
test/regression_files/telnet_regression.pcap


+ 15 - 0
test/regression_files/telnet_regression_labels.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" ?>
+<LABELS version_parser="0.2">
+	<attack>
+		<attack_name>MembersMgmtCommAttack</attack_name>
+		<attack_note></attack_note>
+		<timestamp_start>
+			<timestamp>944192097.145919</timestamp>
+			<timestamp_hr>1999-12-03 04:34:57.145919</timestamp_hr>
+		</timestamp_start>
+		<timestamp_end>
+			<timestamp>944192103.3182914</timestamp>
+			<timestamp_hr>1999-12-03 04:35:03.318291</timestamp_hr>
+		</timestamp_end>
+	</attack>
+</LABELS>

+ 101 - 0
test/regression_files/telnet_regression_mapping.xml

@@ -0,0 +1,101 @@
+<?xml version="1.0" ?>
+<mappings>
+	<mapping CSV_XML_Time="3712.30121813772" Dst="175" PCAP_Time-Datetime="1999-12-03 04:34:57.145919" PCAP_Time-Relative="8.890388" PCAP_Time-Timestamp="944192097.145919" Src="53" Type="103" id="0" line_number="-1" mapped="true" packet_time="944192097.145919"/>
+	<mapping CSV_XML_Time="3712.30121813772" Dst="285" PCAP_Time-Datetime="1999-12-03 04:34:57.165951" PCAP_Time-Relative="8.910420" PCAP_Time-Timestamp="944192097.1659511" Src="53" Type="103" id="1" line_number="-1" mapped="true" packet_time="944192097.1659511"/>
+	<mapping CSV_XML_Time="3712.30121813772" Dst="239" PCAP_Time-Datetime="1999-12-03 04:34:57.204268" PCAP_Time-Relative="8.948737" PCAP_Time-Timestamp="944192097.2042675" Src="53" Type="103" id="2" line_number="-1" mapped="true" packet_time="944192097.2042675"/>
+	<mapping CSV_XML_Time="3712.30121813772" Dst="32" PCAP_Time-Datetime="1999-12-03 04:34:57.231655" PCAP_Time-Relative="8.976124" PCAP_Time-Timestamp="944192097.231655" Src="53" Type="103" id="3" line_number="-1" mapped="true" packet_time="944192097.231655"/>
+	<mapping CSV_XML_Time="3712.50121813772" Dst="2" PCAP_Time-Datetime="1999-12-03 04:34:57.345248" PCAP_Time-Relative="9.089717" PCAP_Time-Timestamp="944192097.3452476" Src="53" Type="103" id="4" line_number="-1" mapped="true" packet_time="944192097.3452476"/>
+	<mapping CSV_XML_Time="3712.50121813772" Dst="195" PCAP_Time-Datetime="1999-12-03 04:34:57.353921" PCAP_Time-Relative="9.098390" PCAP_Time-Timestamp="944192097.3539209" Src="53" Type="103" id="5" line_number="-1" mapped="true" packet_time="944192097.3539209"/>
+	<mapping CSV_XML_Time="3712.50121813772" Dst="142" PCAP_Time-Datetime="1999-12-03 04:34:57.423774" PCAP_Time-Relative="9.168243" PCAP_Time-Timestamp="944192097.4237738" Src="53" Type="103" id="6" line_number="-1" mapped="true" packet_time="944192097.4237738"/>
+	<mapping CSV_XML_Time="3712.50121813772" Dst="33" PCAP_Time-Datetime="1999-12-03 04:34:57.438819" PCAP_Time-Relative="9.183288" PCAP_Time-Timestamp="944192097.4388188" Src="53" Type="103" id="7" line_number="-1" mapped="true" packet_time="944192097.4388188"/>
+	<mapping CSV_XML_Time="3712.70121813772" Dst="50" PCAP_Time-Datetime="1999-12-03 04:34:57.552026" PCAP_Time-Relative="9.296495" PCAP_Time-Timestamp="944192097.5520264" Src="53" Type="103" id="8" line_number="-1" mapped="true" packet_time="944192097.5520264"/>
+	<mapping CSV_XML_Time="3712.70121813772" Dst="292" PCAP_Time-Datetime="1999-12-03 04:34:57.556997" PCAP_Time-Relative="9.301466" PCAP_Time-Timestamp="944192097.5569972" Src="53" Type="103" id="9" line_number="-1" mapped="true" packet_time="944192097.5569972"/>
+	<mapping CSV_XML_Time="3712.70121813772" Dst="128" PCAP_Time-Datetime="1999-12-03 04:34:57.596930" PCAP_Time-Relative="9.341399" PCAP_Time-Timestamp="944192097.5969297" Src="53" Type="103" id="10" line_number="-1" mapped="true" packet_time="944192097.5969297"/>
+	<mapping CSV_XML_Time="3712.90121813772" Dst="184" PCAP_Time-Datetime="1999-12-03 04:34:57.744442" PCAP_Time-Relative="9.488911" PCAP_Time-Timestamp="944192097.7444419" Src="53" Type="103" id="11" line_number="-1" mapped="true" packet_time="944192097.7444419"/>
+	<mapping CSV_XML_Time="3712.90121813772" Dst="271" PCAP_Time-Datetime="1999-12-03 04:34:57.755744" PCAP_Time-Relative="9.500213" PCAP_Time-Timestamp="944192097.7557445" Src="53" Type="103" id="12" line_number="-1" mapped="true" packet_time="944192097.7557445"/>
+	<mapping CSV_XML_Time="3712.90121813772" Dst="268" PCAP_Time-Datetime="1999-12-03 04:34:57.809941" PCAP_Time-Relative="9.554410" PCAP_Time-Timestamp="944192097.809941" Src="53" Type="103" id="13" line_number="-1" mapped="true" packet_time="944192097.809941"/>
+	<mapping CSV_XML_Time="3712.90121813772" Dst="294" PCAP_Time-Datetime="1999-12-03 04:34:57.835344" PCAP_Time-Relative="9.579813" PCAP_Time-Timestamp="944192097.8353442" Src="53" Type="103" id="14" line_number="-1" mapped="true" packet_time="944192097.8353442"/>
+	<mapping CSV_XML_Time="3713.10121813772" Dst="71" PCAP_Time-Datetime="1999-12-03 04:34:57.945022" PCAP_Time-Relative="9.689491" PCAP_Time-Timestamp="944192097.9450219" Src="53" Type="103" id="15" line_number="-1" mapped="true" packet_time="944192097.9450219"/>
+	<mapping CSV_XML_Time="3713.10121813772" Dst="161" PCAP_Time-Datetime="1999-12-03 04:34:57.977761" PCAP_Time-Relative="9.722230" PCAP_Time-Timestamp="944192097.9777606" Src="53" Type="103" id="16" line_number="-1" mapped="true" packet_time="944192097.9777606"/>
+	<mapping CSV_XML_Time="3713.10121813772" Dst="58" PCAP_Time-Datetime="1999-12-03 04:34:57.983818" PCAP_Time-Relative="9.728287" PCAP_Time-Timestamp="944192097.9838177" Src="53" Type="103" id="17" line_number="-1" mapped="true" packet_time="944192097.9838177"/>
+	<mapping CSV_XML_Time="3713.10121813772" Dst="246" PCAP_Time-Datetime="1999-12-03 04:34:57.996091" PCAP_Time-Relative="9.740560" PCAP_Time-Timestamp="944192097.9960915" Src="53" Type="103" id="18" line_number="-1" mapped="true" packet_time="944192097.9960915"/>
+	<mapping CSV_XML_Time="3713.30121813772" Dst="10" PCAP_Time-Datetime="1999-12-03 04:34:58.144829" PCAP_Time-Relative="9.889298" PCAP_Time-Timestamp="944192098.1448286" Src="53" Type="103" id="19" line_number="-1" mapped="true" packet_time="944192098.1448286"/>
+	<mapping CSV_XML_Time="3713.30121813772" Dst="57" PCAP_Time-Datetime="1999-12-03 04:34:58.177304" PCAP_Time-Relative="9.921773" PCAP_Time-Timestamp="944192098.1773041" Src="53" Type="103" id="20" line_number="-1" mapped="true" packet_time="944192098.1773041"/>
+	<mapping CSV_XML_Time="3713.30121813772" Dst="148" PCAP_Time-Datetime="1999-12-03 04:34:58.234148" PCAP_Time-Relative="9.978617" PCAP_Time-Timestamp="944192098.2341479" Src="53" Type="103" id="21" line_number="-1" mapped="true" packet_time="944192098.2341479"/>
+	<mapping CSV_XML_Time="3713.30121813772" Dst="60" PCAP_Time-Datetime="1999-12-03 04:34:58.238059" PCAP_Time-Relative="9.982528" PCAP_Time-Timestamp="944192098.2380587" Src="53" Type="103" id="22" line_number="-1" mapped="true" packet_time="944192098.2380587"/>
+	<mapping CSV_XML_Time="3712.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:34:58.354494" PCAP_Time-Relative="10.098963" PCAP_Time-Timestamp="944192098.3544942" Src="2" Type="104" id="23" line_number="-1" mapped="true" packet_time="944192098.3544942"/>
+	<mapping CSV_XML_Time="3713.50121813772" Dst="70" PCAP_Time-Datetime="1999-12-03 04:34:58.376207" PCAP_Time-Relative="10.120676" PCAP_Time-Timestamp="944192098.3762069" Src="53" Type="103" id="24" line_number="-1" mapped="true" packet_time="944192098.3762069"/>
+	<mapping CSV_XML_Time="3713.50121813772" Dst="51" PCAP_Time-Datetime="1999-12-03 04:34:58.376620" PCAP_Time-Relative="10.121089" PCAP_Time-Timestamp="944192098.3766199" Src="53" Type="103" id="25" line_number="-1" mapped="true" packet_time="944192098.3766199"/>
+	<mapping CSV_XML_Time="3713.50121813772" Dst="256" PCAP_Time-Datetime="1999-12-03 04:34:58.407532" PCAP_Time-Relative="10.152001" PCAP_Time-Timestamp="944192098.4075323" Src="53" Type="103" id="26" line_number="-1" mapped="true" packet_time="944192098.4075323"/>
+	<mapping CSV_XML_Time="3712.70121813772" Dst="2" PCAP_Time-Datetime="1999-12-03 04:34:58.408678" PCAP_Time-Relative="10.153147" PCAP_Time-Timestamp="944192098.4086777" Src="53" Type="101" id="27" line_number="-1" mapped="true" packet_time="944192098.4086777"/>
+	<mapping CSV_XML_Time="3713.50121813772" Dst="216" PCAP_Time-Datetime="1999-12-03 04:34:58.409046" PCAP_Time-Relative="10.153515" PCAP_Time-Timestamp="944192098.4090457" Src="53" Type="103" id="28" line_number="-1" mapped="true" packet_time="944192098.4090457"/>
+	<mapping CSV_XML_Time="3713.70121813772" Dst="269" PCAP_Time-Datetime="1999-12-03 04:34:58.596827" PCAP_Time-Relative="10.341296" PCAP_Time-Timestamp="944192098.5968274" Src="53" Type="103" id="29" line_number="-1" mapped="true" packet_time="944192098.5968274"/>
+	<mapping CSV_XML_Time="3713.70121813772" Dst="105" PCAP_Time-Datetime="1999-12-03 04:34:58.615787" PCAP_Time-Relative="10.360256" PCAP_Time-Timestamp="944192098.6157868" Src="53" Type="103" id="30" line_number="-1" mapped="true" packet_time="944192098.6157868"/>
+	<mapping CSV_XML_Time="3713.70121813772" Dst="230" PCAP_Time-Datetime="1999-12-03 04:34:58.628310" PCAP_Time-Relative="10.372779" PCAP_Time-Timestamp="944192098.6283103" Src="53" Type="103" id="31" line_number="-1" mapped="true" packet_time="944192098.6283103"/>
+	<mapping CSV_XML_Time="3713.70121813772" Dst="91" PCAP_Time-Datetime="1999-12-03 04:34:58.638223" PCAP_Time-Relative="10.382692" PCAP_Time-Timestamp="944192098.6382227" Src="53" Type="103" id="32" line_number="-1" mapped="true" packet_time="944192098.6382227"/>
+	<mapping CSV_XML_Time="3713.90121813772" Dst="13" PCAP_Time-Datetime="1999-12-03 04:34:58.757089" PCAP_Time-Relative="10.501558" PCAP_Time-Timestamp="944192098.7570893" Src="53" Type="103" id="33" line_number="-1" mapped="true" packet_time="944192098.7570893"/>
+	<mapping CSV_XML_Time="3713.90121813772" Dst="277" PCAP_Time-Datetime="1999-12-03 04:34:58.764513" PCAP_Time-Relative="10.508982" PCAP_Time-Timestamp="944192098.7645128" Src="53" Type="103" id="34" line_number="-1" mapped="true" packet_time="944192098.7645128"/>
+	<mapping CSV_XML_Time="3713.90121813772" Dst="66" PCAP_Time-Datetime="1999-12-03 04:34:58.820828" PCAP_Time-Relative="10.565297" PCAP_Time-Timestamp="944192098.8208277" Src="53" Type="103" id="35" line_number="-1" mapped="true" packet_time="944192098.8208277"/>
+	<mapping CSV_XML_Time="3713.90121813772" Dst="23" PCAP_Time-Datetime="1999-12-03 04:34:58.833416" PCAP_Time-Relative="10.577885" PCAP_Time-Timestamp="944192098.8334155" Src="53" Type="103" id="36" line_number="-1" mapped="true" packet_time="944192098.8334155"/>
+	<mapping CSV_XML_Time="3714.10121813772" Dst="169" PCAP_Time-Datetime="1999-12-03 04:34:58.958544" PCAP_Time-Relative="10.703013" PCAP_Time-Timestamp="944192098.9585443" Src="53" Type="103" id="37" line_number="-1" mapped="true" packet_time="944192098.9585443"/>
+	<mapping CSV_XML_Time="3714.10121813772" Dst="52" PCAP_Time-Datetime="1999-12-03 04:34:58.958775" PCAP_Time-Relative="10.703244" PCAP_Time-Timestamp="944192098.958775" Src="53" Type="103" id="38" line_number="-1" mapped="true" packet_time="944192098.958775"/>
+	<mapping CSV_XML_Time="3714.10121813772" Dst="129" PCAP_Time-Datetime="1999-12-03 04:34:58.982068" PCAP_Time-Relative="10.726537" PCAP_Time-Timestamp="944192098.9820684" Src="53" Type="103" id="39" line_number="-1" mapped="true" packet_time="944192098.9820684"/>
+	<mapping CSV_XML_Time="3714.10121813772" Dst="14" PCAP_Time-Datetime="1999-12-03 04:34:59.33288" PCAP_Time-Relative="10.777757" PCAP_Time-Timestamp="944192099.0332878" Src="53" Type="103" id="40" line_number="-1" mapped="true" packet_time="944192099.0332878"/>
+	<mapping CSV_XML_Time="3714.30121813772" Dst="73" PCAP_Time-Datetime="1999-12-03 04:34:59.182010" PCAP_Time-Relative="10.926479" PCAP_Time-Timestamp="944192099.1820104" Src="53" Type="103" id="41" line_number="-1" mapped="true" packet_time="944192099.1820104"/>
+	<mapping CSV_XML_Time="3714.30121813772" Dst="108" PCAP_Time-Datetime="1999-12-03 04:34:59.207830" PCAP_Time-Relative="10.952299" PCAP_Time-Timestamp="944192099.2078297" Src="53" Type="103" id="42" line_number="-1" mapped="true" packet_time="944192099.2078297"/>
+	<mapping CSV_XML_Time="3714.30121813772" Dst="49" PCAP_Time-Datetime="1999-12-03 04:34:59.214345" PCAP_Time-Relative="10.958814" PCAP_Time-Timestamp="944192099.2143449" Src="53" Type="103" id="43" line_number="-1" mapped="true" packet_time="944192099.2143449"/>
+	<mapping CSV_XML_Time="3714.30121813772" Dst="135" PCAP_Time-Datetime="1999-12-03 04:34:59.219078" PCAP_Time-Relative="10.963547" PCAP_Time-Timestamp="944192099.2190777" Src="53" Type="103" id="44" line_number="-1" mapped="true" packet_time="944192099.2190777"/>
+	<mapping CSV_XML_Time="3714.50121813772" Dst="249" PCAP_Time-Datetime="1999-12-03 04:34:59.344711" PCAP_Time-Relative="11.089180" PCAP_Time-Timestamp="944192099.3447114" Src="53" Type="103" id="45" line_number="-1" mapped="true" packet_time="944192099.3447114"/>
+	<mapping CSV_XML_Time="3714.50121813772" Dst="4" PCAP_Time-Datetime="1999-12-03 04:34:59.365656" PCAP_Time-Relative="11.110125" PCAP_Time-Timestamp="944192099.3656557" Src="53" Type="103" id="46" line_number="-1" mapped="true" packet_time="944192099.3656557"/>
+	<mapping CSV_XML_Time="3714.50121813772" Dst="144" PCAP_Time-Datetime="1999-12-03 04:34:59.379093" PCAP_Time-Relative="11.123562" PCAP_Time-Timestamp="944192099.3790932" Src="53" Type="103" id="47" line_number="-1" mapped="true" packet_time="944192099.3790932"/>
+	<mapping CSV_XML_Time="3714.50121813772" Dst="16" PCAP_Time-Datetime="1999-12-03 04:34:59.410967" PCAP_Time-Relative="11.155436" PCAP_Time-Timestamp="944192099.4109668" Src="53" Type="103" id="48" line_number="-1" mapped="true" packet_time="944192099.4109668"/>
+	<mapping CSV_XML_Time="3712.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:34:59.495621" PCAP_Time-Relative="11.240090" PCAP_Time-Timestamp="944192099.4956211" Src="2" Type="102" id="49" line_number="-1" mapped="true" packet_time="944192099.4956211"/>
+	<mapping CSV_XML_Time="3714.70121813772" Dst="258" PCAP_Time-Datetime="1999-12-03 04:34:59.575805" PCAP_Time-Relative="11.320274" PCAP_Time-Timestamp="944192099.5758048" Src="53" Type="103" id="50" line_number="-1" mapped="true" packet_time="944192099.5758048"/>
+	<mapping CSV_XML_Time="3714.70121813772" Dst="185" PCAP_Time-Datetime="1999-12-03 04:34:59.622893" PCAP_Time-Relative="11.367362" PCAP_Time-Timestamp="944192099.6228926" Src="53" Type="103" id="51" line_number="-1" mapped="true" packet_time="944192099.6228926"/>
+	<mapping CSV_XML_Time="3714.70121813772" Dst="182" PCAP_Time-Datetime="1999-12-03 04:34:59.632684" PCAP_Time-Relative="11.377153" PCAP_Time-Timestamp="944192099.6326842" Src="53" Type="103" id="52" line_number="-1" mapped="true" packet_time="944192099.6326842"/>
+	<mapping CSV_XML_Time="3714.90121813772" Dst="278" PCAP_Time-Datetime="1999-12-03 04:34:59.763131" PCAP_Time-Relative="11.507600" PCAP_Time-Timestamp="944192099.7631314" Src="53" Type="103" id="53" line_number="-1" mapped="true" packet_time="944192099.7631314"/>
+	<mapping CSV_XML_Time="3714.90121813772" Dst="177" PCAP_Time-Datetime="1999-12-03 04:34:59.780686" PCAP_Time-Relative="11.525155" PCAP_Time-Timestamp="944192099.7806857" Src="53" Type="103" id="54" line_number="-1" mapped="true" packet_time="944192099.7806857"/>
+	<mapping CSV_XML_Time="3714.90121813772" Dst="155" PCAP_Time-Datetime="1999-12-03 04:34:59.806842" PCAP_Time-Relative="11.551311" PCAP_Time-Timestamp="944192099.8068424" Src="53" Type="103" id="55" line_number="-1" mapped="true" packet_time="944192099.8068424"/>
+	<mapping CSV_XML_Time="3714.90121813772" Dst="156" PCAP_Time-Datetime="1999-12-03 04:34:59.827971" PCAP_Time-Relative="11.572440" PCAP_Time-Timestamp="944192099.8279713" Src="53" Type="103" id="56" line_number="-1" mapped="true" packet_time="944192099.8279713"/>
+	<mapping CSV_XML_Time="3715.10121813772" Dst="260" PCAP_Time-Datetime="1999-12-03 04:34:59.968699" PCAP_Time-Relative="11.713168" PCAP_Time-Timestamp="944192099.9686993" Src="53" Type="103" id="57" line_number="-1" mapped="true" packet_time="944192099.9686993"/>
+	<mapping CSV_XML_Time="3715.10121813772" Dst="222" PCAP_Time-Datetime="1999-12-03 04:34:59.975954" PCAP_Time-Relative="11.720423" PCAP_Time-Timestamp="944192099.9759536" Src="53" Type="103" id="58" line_number="-1" mapped="true" packet_time="944192099.9759536"/>
+	<mapping CSV_XML_Time="3715.10121813772" Dst="202" PCAP_Time-Datetime="1999-12-03 04:35:00.8791" PCAP_Time-Relative="11.753260" PCAP_Time-Timestamp="944192100.0087909" Src="53" Type="103" id="59" line_number="-1" mapped="true" packet_time="944192100.0087909"/>
+	<mapping CSV_XML_Time="3715.10121813772" Dst="217" PCAP_Time-Datetime="1999-12-03 04:35:00.18172" PCAP_Time-Relative="11.762641" PCAP_Time-Timestamp="944192100.0181717" Src="53" Type="103" id="60" line_number="-1" mapped="true" packet_time="944192100.0181717"/>
+	<mapping CSV_XML_Time="3715.30121813772" Dst="194" PCAP_Time-Datetime="1999-12-03 04:35:00.143599" PCAP_Time-Relative="11.888068" PCAP_Time-Timestamp="944192100.1435992" Src="53" Type="103" id="61" line_number="-1" mapped="true" packet_time="944192100.1435992"/>
+	<mapping CSV_XML_Time="3715.30121813772" Dst="76" PCAP_Time-Datetime="1999-12-03 04:35:00.198898" PCAP_Time-Relative="11.943367" PCAP_Time-Timestamp="944192100.1988981" Src="53" Type="103" id="62" line_number="-1" mapped="true" packet_time="944192100.1988981"/>
+	<mapping CSV_XML_Time="3714.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:00.338496" PCAP_Time-Relative="12.082965" PCAP_Time-Timestamp="944192100.3384962" Src="4" Type="104" id="63" line_number="-1" mapped="true" packet_time="944192100.3384962"/>
+	<mapping CSV_XML_Time="3715.50121813772" Dst="250" PCAP_Time-Datetime="1999-12-03 04:35:00.344665" PCAP_Time-Relative="12.089134" PCAP_Time-Timestamp="944192100.3446647" Src="53" Type="103" id="64" line_number="-1" mapped="true" packet_time="944192100.3446647"/>
+	<mapping CSV_XML_Time="3714.70121813772" Dst="4" PCAP_Time-Datetime="1999-12-03 04:35:00.395565" PCAP_Time-Relative="12.140034" PCAP_Time-Timestamp="944192100.3955652" Src="53" Type="101" id="65" line_number="-1" mapped="true" packet_time="944192100.3955652"/>
+	<mapping CSV_XML_Time="3715.50121813772" Dst="178" PCAP_Time-Datetime="1999-12-03 04:35:00.400496" PCAP_Time-Relative="12.144965" PCAP_Time-Timestamp="944192100.4004961" Src="53" Type="103" id="66" line_number="-1" mapped="true" packet_time="944192100.4004961"/>
+	<mapping CSV_XML_Time="3715.50121813772" Dst="109" PCAP_Time-Datetime="1999-12-03 04:35:00.419482" PCAP_Time-Relative="12.163951" PCAP_Time-Timestamp="944192100.4194818" Src="53" Type="103" id="67" line_number="-1" mapped="true" packet_time="944192100.4194818"/>
+	<mapping CSV_XML_Time="3715.50121813772" Dst="137" PCAP_Time-Datetime="1999-12-03 04:35:00.439194" PCAP_Time-Relative="12.183663" PCAP_Time-Timestamp="944192100.4391941" Src="53" Type="103" id="68" line_number="-1" mapped="true" packet_time="944192100.4391941"/>
+	<mapping CSV_XML_Time="3715.70121813772" Dst="1" PCAP_Time-Datetime="1999-12-03 04:35:00.630790" PCAP_Time-Relative="12.375259" PCAP_Time-Timestamp="944192100.6307895" Src="53" Type="103" id="69" line_number="-1" mapped="true" packet_time="944192100.6307895"/>
+	<mapping CSV_XML_Time="3715.70121813772" Dst="225" PCAP_Time-Datetime="1999-12-03 04:35:00.639263" PCAP_Time-Relative="12.383732" PCAP_Time-Timestamp="944192100.6392626" Src="53" Type="103" id="70" line_number="-1" mapped="true" packet_time="944192100.6392626"/>
+	<mapping CSV_XML_Time="3715.90121813772" Dst="3" PCAP_Time-Datetime="1999-12-03 04:35:00.783969" PCAP_Time-Relative="12.528438" PCAP_Time-Timestamp="944192100.7839688" Src="53" Type="103" id="71" line_number="-1" mapped="true" packet_time="944192100.7839688"/>
+	<mapping CSV_XML_Time="3715.20121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:00.922794" PCAP_Time-Relative="12.667263" PCAP_Time-Timestamp="944192100.9227945" Src="260" Type="104" id="72" line_number="-1" mapped="true" packet_time="944192100.9227945"/>
+	<mapping CSV_XML_Time="3715.30121813772" Dst="260" PCAP_Time-Datetime="1999-12-03 04:35:01.17161" PCAP_Time-Relative="12.761630" PCAP_Time-Timestamp="944192101.0171605" Src="53" Type="101" id="73" line_number="-1" mapped="true" packet_time="944192101.0171605"/>
+	<mapping CSV_XML_Time="3715.20121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.21917" PCAP_Time-Relative="12.766386" PCAP_Time-Timestamp="944192101.0219175" Src="222" Type="104" id="74" line_number="-1" mapped="true" packet_time="944192101.0219175"/>
+	<mapping CSV_XML_Time="3715.30121813772" Dst="222" PCAP_Time-Datetime="1999-12-03 04:35:01.119621" PCAP_Time-Relative="12.864090" PCAP_Time-Timestamp="944192101.1196213" Src="53" Type="101" id="75" line_number="-1" mapped="true" packet_time="944192101.1196213"/>
+	<mapping CSV_XML_Time="3716.30121813772" Dst="95" PCAP_Time-Datetime="1999-12-03 04:35:01.207178" PCAP_Time-Relative="12.951647" PCAP_Time-Timestamp="944192101.2071778" Src="53" Type="103" id="76" line_number="-1" mapped="true" packet_time="944192101.2071778"/>
+	<mapping CSV_XML_Time="3714.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.376836" PCAP_Time-Relative="13.121305" PCAP_Time-Timestamp="944192101.376836" Src="4" Type="102" id="77" line_number="-1" mapped="true" packet_time="944192101.376836"/>
+	<mapping CSV_XML_Time="3715.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.412276" PCAP_Time-Relative="13.156745" PCAP_Time-Timestamp="944192101.4122757" Src="178" Type="104" id="78" line_number="-1" mapped="true" packet_time="944192101.4122757"/>
+	<mapping CSV_XML_Time="3715.70121813772" Dst="178" PCAP_Time-Datetime="1999-12-03 04:35:01.426714" PCAP_Time-Relative="13.171183" PCAP_Time-Timestamp="944192101.4267143" Src="53" Type="101" id="79" line_number="-1" mapped="true" packet_time="944192101.4267143"/>
+	<mapping CSV_XML_Time="3715.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.450201" PCAP_Time-Relative="13.194670" PCAP_Time-Timestamp="944192101.4502008" Src="109" Type="104" id="80" line_number="-1" mapped="true" packet_time="944192101.4502008"/>
+	<mapping CSV_XML_Time="3715.70121813772" Dst="109" PCAP_Time-Datetime="1999-12-03 04:35:01.512193" PCAP_Time-Relative="13.256662" PCAP_Time-Timestamp="944192101.5121927" Src="53" Type="101" id="81" line_number="-1" mapped="true" packet_time="944192101.5121927"/>
+	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.603009" PCAP_Time-Relative="13.347478" PCAP_Time-Timestamp="944192101.6030095" Src="225" Type="104" id="82" line_number="-1" mapped="true" packet_time="944192101.6030095"/>
+	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.610078" PCAP_Time-Relative="13.354547" PCAP_Time-Timestamp="944192101.610078" Src="1" Type="104" id="83" line_number="-1" mapped="true" packet_time="944192101.610078"/>
+	<mapping CSV_XML_Time="3715.90121813772" Dst="225" PCAP_Time-Datetime="1999-12-03 04:35:01.681695" PCAP_Time-Relative="13.426164" PCAP_Time-Timestamp="944192101.6816951" Src="53" Type="101" id="84" line_number="-1" mapped="true" packet_time="944192101.6816951"/>
+	<mapping CSV_XML_Time="3715.90121813772" Dst="1" PCAP_Time-Datetime="1999-12-03 04:35:01.693782" PCAP_Time-Relative="13.438251" PCAP_Time-Timestamp="944192101.6937817" Src="53" Type="101" id="85" line_number="-1" mapped="true" packet_time="944192101.6937817"/>
+	<mapping CSV_XML_Time="3716.00121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:01.921694" PCAP_Time-Relative="13.666163" PCAP_Time-Timestamp="944192101.9216938" Src="3" Type="104" id="86" line_number="-1" mapped="true" packet_time="944192101.9216938"/>
+	<mapping CSV_XML_Time="3716.10121813772" Dst="3" PCAP_Time-Datetime="1999-12-03 04:35:02.23771" PCAP_Time-Relative="13.768240" PCAP_Time-Timestamp="944192102.0237708" Src="53" Type="101" id="87" line_number="-1" mapped="true" packet_time="944192102.0237708"/>
+	<mapping CSV_XML_Time="3715.40121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.25905" PCAP_Time-Relative="13.770374" PCAP_Time-Timestamp="944192102.0259047" Src="260" Type="102" id="88" line_number="-1" mapped="true" packet_time="944192102.0259047"/>
+	<mapping CSV_XML_Time="3715.40121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.113763" PCAP_Time-Relative="13.858232" PCAP_Time-Timestamp="944192102.1137631" Src="222" Type="102" id="89" line_number="-1" mapped="true" packet_time="944192102.1137631"/>
+	<mapping CSV_XML_Time="3716.40121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.172800" PCAP_Time-Relative="13.917269" PCAP_Time-Timestamp="944192102.1727996" Src="95" Type="104" id="90" line_number="-1" mapped="true" packet_time="944192102.1727996"/>
+	<mapping CSV_XML_Time="3716.50121813772" Dst="95" PCAP_Time-Datetime="1999-12-03 04:35:02.272804" PCAP_Time-Relative="14.017273" PCAP_Time-Timestamp="944192102.2728043" Src="53" Type="101" id="91" line_number="-1" mapped="true" packet_time="944192102.2728043"/>
+	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.457363" PCAP_Time-Relative="14.201832" PCAP_Time-Timestamp="944192102.4573631" Src="178" Type="102" id="92" line_number="-1" mapped="true" packet_time="944192102.4573631"/>
+	<mapping CSV_XML_Time="3715.80121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.620192" PCAP_Time-Relative="14.364661" PCAP_Time-Timestamp="944192102.6201922" Src="109" Type="102" id="93" line_number="-1" mapped="true" packet_time="944192102.6201922"/>
+	<mapping CSV_XML_Time="3716.00121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.674523" PCAP_Time-Relative="14.418992" PCAP_Time-Timestamp="944192102.6745228" Src="1" Type="102" id="94" line_number="-1" mapped="true" packet_time="944192102.6745228"/>
+	<mapping CSV_XML_Time="3716.00121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:02.817622" PCAP_Time-Relative="14.562091" PCAP_Time-Timestamp="944192102.8176221" Src="225" Type="102" id="95" line_number="-1" mapped="true" packet_time="944192102.8176221"/>
+	<mapping CSV_XML_Time="3716.20121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:03.93486" PCAP_Time-Relative="14.837955" PCAP_Time-Timestamp="944192103.0934857" Src="3" Type="102" id="96" line_number="-1" mapped="true" packet_time="944192103.0934857"/>
+	<mapping CSV_XML_Time="3716.60121813772" Dst="53" PCAP_Time-Datetime="1999-12-03 04:35:03.318291" PCAP_Time-Relative="15.062760" PCAP_Time-Timestamp="944192103.3182914" Src="95" Type="102" id="97" line_number="-1" mapped="true" packet_time="944192103.3182914"/>
+</mappings>

+ 24 - 32
test/test_pcap_comparator.py

@@ -7,7 +7,7 @@ import unittest
 import random
 
 import scapy.all
-from TestUtil import PcapComparator
+from TestUtil import PcapComparator, ID2TExecution
 
 # this dictionary holds the generators (functions) for the parameters
 # that will be passed to the MembershipMgmtCommAttack
@@ -35,9 +35,11 @@ ID2T_PARAMETER_GENERATORS = {
     "ttl.from.caida": _random_bool,
 }
 
+
 class PcapComparison(unittest.TestCase):
     ID2T_PATH = ".."
     ID2T_LOCATION = ID2T_PATH + "/" + "id2t"
+
     NUM_ITERATIONS_PER_PARAMS = 3
     NUM_ITERATIONS = 5
 
@@ -47,8 +49,6 @@ class PcapComparison(unittest.TestCase):
     DEFAULT_PCAP = "resources/telnet-raw.pcap"
     DEFAULT_SEED = "42"
 
-    OUTPUT_FILES_PREFIX_LINE = "Output files created:"
-
     def __init__(self, *args, **kwargs):
         unittest.TestCase.__init__(self, *args, **kwargs)
 
@@ -61,8 +61,7 @@ class PcapComparison(unittest.TestCase):
         self.id2t_params = params
 
     def setUp(self):
-        self.generated_files = []
-        self.keep_files = []
+        self.executions = []
 
     def test_determinism(self):
         input_pcap = os.environ.get(self.PCAP_ENVIRONMENT_VALUE, self.DEFAULT_PCAP)
@@ -75,26 +74,28 @@ class PcapComparison(unittest.TestCase):
             self.do_test_round(input_pcap, seed, params)
 
     def do_test_round(self, input_pcap, seed, additional_params):
-        command_args = [self.ID2T_LOCATION, "-i", input_pcap, "--seed", seed, "-a", "MembersMgmtCommAttack"] + additional_params
-        command = " ".join(map(shlex.quote, command_args))
-        self.print_warning("The command that gets executed is:", command)
-
         generated_pcap = None
         for i in range(self.NUM_ITERATIONS_PER_PARAMS):
-            retcode, output = subprocess.getstatusoutput(command)
+            execution = ID2TExecution(input_pcap, seed=seed)
+            self.print_warning("The command that gets executed is:", execution.get_run_command(additional_params))
+            self.executions.append(execution)
 
-            self.print_warning(output)
-            self.assertEqual(retcode, 0, "For some reason id2t completed with an error")
+            try:
+                execution.run(additional_params)
+            except AssertionError as e:
+                self.print_warning(execution.get_output())
+                self.assertEqual(execution.get_return_code(), 0, "For some reason id2t completed with an error")
+                raise e
 
-            files = self.parse_files(output)
-            self.generated_files.extend(files)
+            self.print_warning(execution.get_output())
 
-            pcap = self.find_pcap(files)
+            pcap = execution.get_pcap_filename()
             if generated_pcap is not None:
                 try:
                     self.compare_pcaps(generated_pcap, pcap)
                 except AssertionError as e:
-                    self.keep_files = [generated_pcap, pcap]
+                    execution.keep_file(pcap)
+                    self.executions[-2].keep_file(generated_pcap)
                     raise e
             else:
                 generated_pcap = pcap
@@ -104,25 +105,16 @@ class PcapComparison(unittest.TestCase):
 
     def tearDown(self):
         self.print_warning("Cleaning up files generated by the test-calls...")
-        for file in self.generated_files:
-            if file in self.keep_files: continue
+        for id2t_run in self.executions:
+            for file in id2t_run.get_files_for_deletion():
+                self.print_warning(file)
 
-            self.print_warning(file)
-            os.remove(self.ID2T_PATH + os.path.sep + file)
-        self.print_warning("Done")
-        self.print_warning("The following files have been kept: " + ", ".join(self.keep_files))
-
-    def parse_files(self, program_output: str) -> "list[str]":
-        lines = program_output.split(os.linesep)
+            id2t_run.cleanup()
 
-        self.assertIn(self.OUTPUT_FILES_PREFIX_LINE, lines,
-                "The magic string is not in the program output anymore, has the program output structure changed?")
-        index = lines.index(self.OUTPUT_FILES_PREFIX_LINE)
-
-        return lines[index + 1:]
+        self.print_warning("Done")
 
-    def find_pcap(self, files: "list[str]") -> str:
-        return next(file for file in files if file.endswith(".pcap"))
+        kept = [file for file in id2t_run.get_kept_files() for id2t_run in self.executions]
+        self.print_warning("The following files have been kept: " + ", ".join(kept))
 
     def compare_pcaps(self, one: str, other: str):
         PcapComparator().compare_files(self.ID2T_PATH + "/" + one, self.ID2T_PATH + "/" + other)

+ 57 - 0
test/test_regression.py

@@ -0,0 +1,57 @@
+import unittest
+import xml.etree.ElementTree
+import os.path
+import sys
+
+from TestUtil import PcapComparator, ID2TExecution
+
+
+class RegressionTest(unittest.TestCase):
+    REGRESSION_DIRECTORY = "../test/regression_files"
+    REGRESSION_DIRECTORY_ID2T_RELATIVE = "test/regression_files"
+    ID2T_RELATIVE_TO_LOCAL_PREFIX = "../"
+
+    META_FILE = "fileinfo.xml"
+
+    def test_regression(self):
+        config_location = self.REGRESSION_DIRECTORY + os.sep + self.META_FILE
+        xml_root = xml.etree.ElementTree.parse(config_location).getroot()
+        comparator = PcapComparator()
+
+        for test in xml_root.getchildren():
+            self.assertXMLTagHasAttribute(test, "seed", "<test>s needs a seed-attribute")
+            self.assertXMLTagHasAttribute(test, "outfile", "<test>s needs a outfile-attribute")
+            self.assertXMLTagHasAttribute(test, "infile", "<test>s needs a infile-attribute")
+            self.assertXMLTagHasAttribute(test, "name", "<test>s needs a name-attribute")
+
+            params = []
+            for param in test.getchildren():
+                self.assertEqual(param.tag, "param", "<test>-children must be <params>s")
+                self.assertIsNotNone(param.get("key"), "<param> needs a key-attribute")
+                self.assertIsNotNone(param.get("value"), "<param> needs a value-attribute")
+
+                params.append("%s=%s" % (param.get("key"), param.get("value")))
+
+            infile = os.path.join(self.REGRESSION_DIRECTORY_ID2T_RELATIVE, test.get("infile"))
+            outfile = os.path.join(self.REGRESSION_DIRECTORY, test.get("outfile"))
+
+            execution = ID2TExecution(infile, seed=test.get("seed"))
+            self.print_warning(execution.get_run_command(params))
+            execution.run(params)
+
+            new_file = self.ID2T_RELATIVE_TO_LOCAL_PREFIX + os.sep + execution.get_pcap_filename()
+            old_file = outfile
+
+            try:
+                comparator.compare_files(new_file, old_file)
+            except AssertionError as e:
+                execution.cleanup()
+                raise AssertionError("Test %s failed" % test.get("name")) from e
+
+            self.print_warning("Regression-test %s passed" % test.get("name"))
+
+    def assertXMLTagHasAttribute(self, tag, attribute, msg=None):
+        self.assertIsNotNone(tag.get(attribute), msg)
+
+    def print_warning(self, *text):
+        print(*text, file=sys.stderr)