Skip to content

Commit

Permalink
fix: main cli invocation and test
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
  • Loading branch information
fzipi committed Jan 22, 2025
1 parent ef41e02 commit 577c887
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/crs_linter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ def parse_args(argv):

return parser.parse_args(argv)

def main(argv):
def main():
retval = 0
args = parse_args(argv)
args = parse_args(sys.argv)

files = glob.glob(args.crs_rules[0])

Expand Down Expand Up @@ -456,4 +456,5 @@ def main(argv):


if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
sys.argv[0] = re.sub(r"(-script\.pyw|\.exe)?$", "", sys.argv[0])
sys.exit(main())
9 changes: 5 additions & 4 deletions src/crs_linter/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ def __init__(self, data, filename=None, txvars={}):

def is_error(self):
""" Returns True if any error is found """
return len(self.caseerror) > 0 or len(self.orderacts) > 0 or len(self.auditlogparts) > 0 or len(
self.undef_txvars) > 0 or len(self.pltags) > 0 or len(self.plscores) > 0 or len(self.dupes) > 0 or len(
self.ids) > 0 or len(self.newtags) > 0 or len(self.ignorecase) > 0 or len(self.nocrstags) > 0 or len(
self.noveract) > 0 or len(self.nocaptact) > 0
error_vars = [self.caseerror, self.orderacts, self.auditlogparts,
self.undef_txvars, self.pltags, self.plscores, self.dupes,
self.ids, self.newtags, self.ignorecase, self.nocrstags,
self.noveract, self.nocaptact]
return any([len(var) > 0 for var in error_vars])

def store_error(self, msg):
# store the error msg in the list
Expand Down
8 changes: 7 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from pytest import mocker

from crs_linter.cli import main


def test_cli():
ret = main(["-v", "4.10.0", "-r", "../examples/*.conf", "-t", "./APPROVED_TAGS", "-d", "."])
mocker.patch(
"sys.argv",
["-v", "4.10.0", "-r", "../examples/*.conf", "-t", "./APPROVED_TAGS", "-d", "."]
)
ret = main()

assert ret == 0

0 comments on commit 577c887

Please sign in to comment.