From 28b6f75836d7d77a0c7a88a0ff1d6b09395b3666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ervin=20Heged=C3=BCs?= Date: Tue, 7 Dec 2021 11:37:10 +0100 Subject: [PATCH] Removed unnecessary .BAK file --- .../find_rules_without_test.py.BAK | 124 ------------------ 1 file changed, 124 deletions(-) delete mode 100755 util/find-rules-without-test/find_rules_without_test.py.BAK diff --git a/util/find-rules-without-test/find_rules_without_test.py.BAK b/util/find-rules-without-test/find_rules_without_test.py.BAK deleted file mode 100755 index 0e1fe01f0..000000000 --- a/util/find-rules-without-test/find_rules_without_test.py.BAK +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python3 - -# This file helps to find the rules which does not have any test cases. -# -# You just have to pass the CORERULESET_ROOT as argument. -# -# At the end, the script will print the list of rules without any tests. -# -# Please note, that there are some exclusions: -# * only REQUEST-NNN rules are checked -# * there are some hardcoded exlucions: -# * REQUEST-900- -# * REQUEST-901- -# * REQUEST-905- -# * REQUEST-910- -# * REQUEST-912. -# * REQUEST-949- - - -import sys -import glob -import msc_pyparser -import argparse - -oformat = "native" - -def find_ids(s, test_cases): - """ - s: the parsed structure - test_cases: all avaliable test cases - """ - for i in s: - rids = [] - # only SecRule counts - if i['type'] == "SecRule": - for a in i['actions']: - # find the `id` action - if a['act_name'] == "id": - # get the argument of the action - rid = int(a['act_arg']) # int - srid = a['act_arg'] # string - if (rid%1000) >= 100: # skip the PL controll rules - # also skip these hardcoded rules - if srid[:3] not in ["900", "901", "905", "910", "912", "949"]: - # if there is no test cases, just print it - if rid not in test_cases: - rids.append(rid) - return rids - -if __name__ == "__main__": - - desc = """This script helps to find the rules without test cases. It needs a mandatory -argument where you pass the path to your coreruleset. The tool collects the -tests with name REQUEST-*, but not with RESPONSE-*. Then reads the rule id's, -and check which rule does not have any test. Some rules does not need test -case, these are hardcoded as exclusions: 900NNN, 901NNN, 905NNN, 910NNN, -912NNN, 949NNN.""" - - parser = argparse.ArgumentParser(description=desc, formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument("--output", dest="output", help="Output format native[default]|github", required=False) - parser.add_argument('crspath', metavar='/path/to/coreruleset', type=str, - help='Directory path to CRS') - args = parser.parse_args() - - test_cases = {} - - if args.output is not None: - if args.output not in ["native", "github"]: - print("--output can be one of the 'native' or 'github'. Default value is 'native'") - sys.exit(1) - oformat = args.output - - # from argument, build the rules path and regression test paths - crspath = args.crspath.rstrip("/") + "/rules/*.conf" - testpath = args.crspath.rstrip("/") + "/tests/regression/tests/*" - retval = 0 - # collect rules - flist = glob.glob(crspath) - flist.sort() - if len(flist) == 0: - print("Can't open files in given path!") - sys.exit(1) - - # collect test cases - tlist = glob.glob(testpath) - tlist.sort() - if len(tlist) == 0: - print("Can't open files in given path (%s)!" % (testpath)) - sys.exit(1) - # find the yaml files with name REQUEST at the begin - # collect them in a dictionary - for t in tlist: - tname = t.split("/")[-1] - if tname[:7] == "REQUEST": - testlist = glob.glob(t + "/*.yaml") - testlist.sort() - for tc in testlist: - tcname = tc.split("/")[-1].split(".")[0] - test_cases[int(tcname)] = 1 - - # iterate the rule files - for f in flist: - fname = f.split("/")[-1] - if fname[:7] == "REQUEST": - try: - with open(f, 'r') as inputfile: - data = inputfile.read() - except: - print("Can't open file: %s" % f) - print(sys.exc_info()) - sys.exit(1) - - try: - # make a structure - mparser = msc_pyparser.MSCParser() - mparser.parser.parse(data) - # add the parsed structure to a function, which finds the 'id'-s, - # and the collected test cases - find_ids(mparser.configlines, test_cases) - except: - print("Can't parse config file: %s" % (f)) - print(sys.exc_info()[1]) - sys.exit(1) - sys.exit(retval)