From 889795691498637e601634a18f2518d94b29092f Mon Sep 17 00:00:00 2001 From: Nick <49166439+nhakmiller@users.noreply.github.com> Date: Fri, 10 Jul 2020 16:49:43 -0700 Subject: [PATCH] Fixed up some unexpected behavior (#35) * fixed occasional error message * removed a test I was doing * added unit test that handles a tags filter --- panther_analysis_tool/main.py | 7 ++++--- tests/unit/panther_analysis_tool/test_main.py | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/panther_analysis_tool/main.py b/panther_analysis_tool/main.py index 6e3f1829..310cadf5 100644 --- a/panther_analysis_tool/main.py +++ b/panther_analysis_tool/main.py @@ -409,10 +409,14 @@ def run_tests(analysis: Dict[str, Any], analysis_funcs: Dict[str, Any], result = analysis_funcs['run'](test_case) except KeyError as err: logging.warning('KeyError: {%s}', err) + failed_tests[analysis.get('PolicyID') or + analysis['RuleID']].append(unit_test['Name']) continue except Exception as err: # pylint: disable=broad-except # Catch arbitrary exceptions raised by user code logging.warning('Unexpected exception: {%s}', err) + failed_tests[analysis.get('PolicyID') or + analysis['RuleID']].append(unit_test['Name']) continue test_result = 'PASS' if result != unit_test['ExpectedResult']: @@ -538,9 +542,6 @@ def run() -> None: if args.filter is not None: args.filter = parse_filter(args.filter) return_code, out = args.func(args) - except AttributeError: - parser.print_help() - sys.exit(1) except Exception as err: # pylint: disable=broad-except # Catch arbitrary exceptions without printing help message logging.warning('Unhandled exception: "%s"', err) diff --git a/tests/unit/panther_analysis_tool/test_main.py b/tests/unit/panther_analysis_tool/test_main.py index ec1b3b6b..b70bd7a0 100644 --- a/tests/unit/panther_analysis_tool/test_main.py +++ b/tests/unit/panther_analysis_tool/test_main.py @@ -62,6 +62,13 @@ def test_with_filters(self): assert_equal(return_code, 0) assert_equal(len(invalid_specs), 0) + def test_with_tag_filters(self): + args = pat.setup_parser().parse_args('test --path tests/fixtures/valid_analysis --filter Tags=AWS,CIS'.split()) + args.filter = pat.parse_filter(args.filter) + return_code, invalid_specs = pat.test_analysis(args) + assert_equal(return_code, 0) + assert_equal(len(invalid_specs), 0) + def test_zip_analysis(self): # Note: This is a workaround for CI try: