]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
runner: pre-check script
authorJason Ish <ish@unx.ca>
Fri, 16 Feb 2018 20:37:48 +0000 (14:37 -0600)
committerJason Ish <ish@unx.ca>
Fri, 16 Feb 2018 20:38:57 +0000 (14:38 -0600)
Allow a script to be defined, "pre-check" that is run before the
checks are run. For example, a new test converts unified2 to
json before running filter checks.

Also allow the eve.json filename to be changed, useful for doing
filter checks on arbitrary json output.

README.md
run.py

index e7ddc8c7b1f05cbfc59379ac6367221d15891595..da8fa26336cdafb904edebe96fdcd5a1af8b8398 100644 (file)
--- a/README.md
+++ b/README.md
@@ -66,6 +66,13 @@ requires:
   # command is provided.
   pcap: false
 
+  # Run the script and only continue with the test if the script exists
+  # successfully.
+  script:
+       - command1
+       - command2
+       - ...
+
 # Add additional arguments to Suricata.
 args:
   - --set stream.reassembly.depth=0
@@ -81,6 +88,10 @@ command: |
 # done after each iteration.
 count: 10
 
+pre-check: |
+  # Some script to run before running checks.
+  cp eve.json eve.json.bak
+
 checks:
 
   # A verification filter that is run over the eve.json. Multiple
diff --git a/run.py b/run.py
index e329d177d81ded736946fe063a382d4ae3ee1852..e9c92072fe42949133f231205defcba444268feb 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -247,12 +247,15 @@ class FilterCheck:
         self.outdir = outdir
 
     def run(self):
-        eve_json_path = "eve.json"
-        if not os.path.exists(eve_json_path):
-            raise TestError("%s does not exist" % (eve_json_path))
+        if "filename" in self.config:
+            json_filename = self.config["filename"]
+        else:
+            json_filename = "eve.json"
+        if not os.path.exists(json_filename):
+            raise TestError("%s does not exist" % (json_filename))
 
         count = 0
-        with open(eve_json_path, "r") as fileobj:
+        with open(json_filename, "r") as fileobj:
             for line in fileobj:
                 event = json.loads(line)
                 if self.match(event):
@@ -469,11 +472,16 @@ class TestRunner:
         print("OK%s" % (" (%dx)" % count if count > 1 else ""))
         return True
 
+    def pre_check(self):
+        if "pre-check" in self.config:
+            subprocess.call(self.config["pre-check"], shell=True)
+
     def check(self):
 
         pdir = os.getcwd()
         os.chdir(self.output)
         try:
+            self.pre_check()
             if "checks" in self.config:
                 for check in self.config["checks"]:
                     for key in check: