From: Jason Ish Date: Wed, 29 Dec 2021 17:09:11 +0000 (-0600) Subject: integration tests: format X-Git-Tag: 1.3.0rc1~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2e08c36d3799ffcffdf21c482a887984c89fbedb;p=thirdparty%2Fsuricata-update.git integration tests: format --- diff --git a/tests/integration_tests.py b/tests/integration_tests.py index 878134a..a15b419 100755 --- a/tests/integration_tests.py +++ b/tests/integration_tests.py @@ -5,22 +5,24 @@ import shutil DATA_DIR = "./tests/tmp" + def run(args): subprocess.check_call(args) + def delete(path): if os.path.isdir(path): shutil.rmtree(path) else: os.unlink(path) + print("Python executable: %s" % sys.executable) print("Python version: %s" % str(sys.version)) print("Current directory: %s" % os.getcwd()) # Override the default source index URL to avoid hitting the network. -os.environ["SOURCE_INDEX_URL"] = "file://%s/tests/index.yaml" % ( - os.getcwd()) +os.environ["SOURCE_INDEX_URL"] = "file://%s/tests/index.yaml" % (os.getcwd()) os.environ["ETOPEN_URL"] = "file://%s/tests/emerging.rules.tar.gz" % ( os.getcwd()) @@ -31,76 +33,86 @@ if os.path.exists(DATA_DIR): common_args = [ sys.executable, "./bin/suricata-update", - "-D", DATA_DIR, - "-c", "./tests/empty", + "-D", + DATA_DIR, + "-c", + "./tests/empty", ] common_update_args = [ "--no-test", "--no-reload", - "--suricata-conf", "./tests/suricata.yaml", - "--disable-conf", "./tests/disable.conf", - "--enable-conf", "./tests/empty", - "--drop-conf", "./tests/empty", - "--modify-conf", "./tests/empty", + "--suricata-conf", + "./tests/suricata.yaml", + "--disable-conf", + "./tests/disable.conf", + "--enable-conf", + "./tests/empty", + "--drop-conf", + "./tests/empty", + "--modify-conf", + "./tests/empty", ] # Default run with data directory. run(common_args + common_update_args) -assert(os.path.exists(DATA_DIR)) -assert(os.path.exists(os.path.join(DATA_DIR, "update", "cache"))) -assert(os.path.exists(os.path.join(DATA_DIR, "rules", "suricata.rules"))) +assert (os.path.exists(DATA_DIR)) +assert (os.path.exists(os.path.join(DATA_DIR, "update", "cache"))) +assert (os.path.exists(os.path.join(DATA_DIR, "rules", "suricata.rules"))) # Default run with data directory and --no-merge run(common_args + common_update_args + ["--no-merge"]) -assert(os.path.exists(DATA_DIR)) -assert(os.path.exists(os.path.join(DATA_DIR, "update", "cache"))) -assert(os.path.exists(os.path.join(DATA_DIR, "rules", "emerging-deleted.rules"))) -assert(os.path.exists(os.path.join(DATA_DIR, "rules", "emerging-current_events.rules"))) +assert (os.path.exists(DATA_DIR)) +assert (os.path.exists(os.path.join(DATA_DIR, "update", "cache"))) +assert (os.path.exists( + os.path.join(DATA_DIR, "rules", "emerging-deleted.rules"))) +assert (os.path.exists( + os.path.join(DATA_DIR, "rules", "emerging-current_events.rules"))) # Still a default run, but set --output to an alternate location." run(common_args + common_update_args + ["--output", "./tests/tmp/_rules"]) -assert(os.path.exists(os.path.join(DATA_DIR, "_rules"))) +assert (os.path.exists(os.path.join(DATA_DIR, "_rules"))) # Update sources. run(common_args + ["update-sources"]) -assert(os.path.exists(os.path.join(DATA_DIR, "update", "cache", "index.yaml"))) +assert (os.path.exists(os.path.join(DATA_DIR, "update", "cache", + "index.yaml"))) # Now delete the index and run lists-sources to see if it downloads # the index. delete(os.path.join(DATA_DIR, "update", "cache", "index.yaml")) run(common_args + ["list-sources"]) -assert(os.path.exists(os.path.join(DATA_DIR, "update", "cache", "index.yaml"))) +assert (os.path.exists(os.path.join(DATA_DIR, "update", "cache", + "index.yaml"))) # Enable a source. run(common_args + ["enable-source", "oisf/trafficid"]) -assert(os.path.exists( +assert (os.path.exists( os.path.join(DATA_DIR, "update", "sources", "oisf-trafficid.yaml"))) # Disable the source. run(common_args + ["disable-source", "oisf/trafficid"]) -assert(not os.path.exists( - os.path.join( - DATA_DIR, "update", "sources", "oisf-trafficid.yaml"))) -assert(os.path.exists( - os.path.join( - DATA_DIR, "update", "sources", "oisf-trafficid.yaml.disabled"))) +assert (not os.path.exists( + os.path.join(DATA_DIR, "update", "sources", "oisf-trafficid.yaml"))) +assert (os.path.exists( + os.path.join(DATA_DIR, "update", "sources", + "oisf-trafficid.yaml.disabled"))) # Remove the source. run(common_args + ["remove-source", "oisf/trafficid"]) -assert(not os.path.exists( - os.path.join( - DATA_DIR, "update", "sources", "oisf-trafficid.yaml.disabled"))) +assert (not os.path.exists( + os.path.join(DATA_DIR, "update", "sources", + "oisf-trafficid.yaml.disabled"))) # Add a source with a custom header. run(common_args + [ "add-source", "--http-header", "Header: NoSpaces", - "testing-header-nospaces", - "file:///doesnotexist"]) + "testing-header-nospaces", "file:///doesnotexist" +]) # Add a source with a custom header with spaces in the value # (https://redmine.openinfosecfoundation.org/issues/4362) run(common_args + [ - "add-source", - "--http-header", "Authorization: Basic dXNlcjE6cGFzc3dvcmQx", - "testing-header-with-spaces", "file:///doesnotexist"]) + "add-source", "--http-header", "Authorization: Basic dXNlcjE6cGFzc3dvcmQx", + "testing-header-with-spaces", "file:///doesnotexist" +])