]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
require specific suricata config settings...
authorJason Ish <ish@unx.ca>
Tue, 13 Mar 2018 17:31:54 +0000 (11:31 -0600)
committerJason Ish <ish@unx.ca>
Tue, 13 Mar 2018 17:31:54 +0000 (11:31 -0600)
specific as a regex pattern on the key, for example:

requires:
  config:
    outputs.\d.eve-log.types.\d.dns.version: 2

To require version 2 of the eve dns logger without needing
to know exactly which list item its at.

Uses --dump-config to load the config.

run.py
tests/dns-tcp-ts-gap/test.yaml
tests/dns-udp-dig-a-www-suricata-ids-org/test.yaml
tests/dns-udp-eve-log-txt/test.yaml

diff --git a/run.py b/run.py
index e9c92072fe42949133f231205defcba444268feb..407c6402e55de13de967482571ca49fb3a81d958 100755 (executable)
--- a/run.py
+++ b/run.py
@@ -163,7 +163,7 @@ class SuricataConfig:
     def __init__(self, version):
         self.version = version
         self.features = set()
-
+        self.config = {}
         self.load_build_info()
 
     def load_build_info(self):
@@ -172,6 +172,21 @@ class SuricataConfig:
             if line.decode().startswith("Features:"):
                 self.features = set(line.decode().split()[1:])
 
+    def load_config(self, config_filename):
+        output = subprocess.check_output([
+            "./src/suricata",
+            "-c", config_filename,
+            "--dump-config"])
+        self.config = {}
+        for line in output.split("\n"):
+            parts = [p.strip() for p in line.split("=", 1)]
+            if parts and parts[0]:
+                if len(parts) > 1:
+                    val = parts[1]
+                else:
+                    val = ""
+                self.config[parts[0]] = val
+
     def has_feature(self, feature):
         return feature in self.features
 
@@ -302,6 +317,8 @@ class TestRunner:
         # Load the test configuration.
         self.load_config()
 
+        self.suricata_config.load_config(self.get_suricata_yaml_path())
+
     def load_config(self):
         if os.path.exists(os.path.join(self.directory, "test.yaml")):
             self.config = yaml.safe_load(
@@ -348,6 +365,15 @@ class TestRunner:
         else:
             requires = {}
 
+        if "config" in requires:
+            for key_pattern, need_val in requires["config"].items():
+                for key, val in self.suricata_config.config.items():
+                    if re.match(key_pattern, key):
+                        if need_val != val:
+                            raise UnsatisfiedRequirementError(
+                                "requires %s = %s" % (
+                                    key, need_val))
+
         if "min-version" in requires:
             min_version = parse_suricata_version(requires["min-version"])
             suri_version = self.suricata_config.version
@@ -554,10 +580,7 @@ class TestRunner:
         if "ips" in self.name:
             args.append("--simulate-ips")
 
-        if os.path.exists(os.path.join(self.directory, "suricata.yaml")):
-            args += ["-c", os.path.join(self.directory, "suricata.yaml")]
-        else:
-            args += ["-c", os.path.join(self.cwd, "suricata.yaml")]
+        args += ["-c", self.get_suricata_yaml_path()]
 
         # Find pcaps.
         if "pcap" in self.config:
@@ -581,6 +604,13 @@ class TestRunner:
 
         return args
 
+    def get_suricata_yaml_path(self):
+        """Return the path to the suricata.yaml that will be used for this
+        test."""
+        if os.path.exists(os.path.join(self.directory, "suricata.yaml")):
+            return os.path.join(self.directory, "suricata.yaml")
+        return os.path.join(self.cwd, "suricata.yaml")
+
     def start_reader(self, input, output):
         t = threading.Thread(
             target=pipe_reader, args=(input, output, self.verbose))
index b0b1bef18be162eb871c1e3256e48fcf2e1767f1..544265bf3589b2381b636eb4eef36b0cee84d01e 100644 (file)
@@ -3,3 +3,7 @@ requires:
   min-version: 4.0.0
   features:
     - HAVE_LIBJANSSON
+  config:
+    # Requires eve dns version 2.
+    outputs.\d.eve-log.types.\d.dns.version: 2
+    
index 23a2d9671cedfdf80adfebd3aa377f31e5da433b..43ff38d8e9eb80ad0b0574bb4e1b64049a6340c0 100644 (file)
@@ -1,6 +1,9 @@
 requires:
   features:
     - HAVE_LIBJANSSON
+  config:
+    # Requires eve dns version 2.
+    outputs.\d.eve-log.types.\d.dns.version: 2
 
 checks:
 
index 56ea9b0d57173b93569d9c72c9b1372ce9234d13..b491dab1c09c335ef46b8350ec321df838cb7efd 100644 (file)
@@ -1,3 +1,6 @@
 requires:
   features:
     - HAVE_LIBJANSSON
+  config:
+    # Requires eve dns version 2.
+    outputs.\d.eve-log.types.\d.dns.version: 2