From: Jason Ish Date: Fri, 16 Feb 2018 20:37:48 +0000 (-0600) Subject: runner: pre-check script X-Git-Tag: suricata-6.0.4~501 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93ac1a3597f32ecdc4f67919bb818afb9c19ccda;p=thirdparty%2Fsuricata-verify.git runner: pre-check script 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. --- diff --git a/README.md b/README.md index e7ddc8c7b..da8fa2633 100644 --- 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 e329d177d..e9c92072f 100755 --- 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: