Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergargar committed Mar 26, 2024
1 parent ee6fb10 commit 6aaca36
Showing 1 changed file with 64 additions and 62 deletions.
126 changes: 64 additions & 62 deletions tests/lib/cli/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

# capsys
# https://docs.pytest.org/en/7.1.x/how-to/capture-stdout-stderr.html
prowler_default_usage_error = "usage: prowler [-h] [-v] {aws,azure,gcp,kubernetes} ..."
prowler_default_usage_error = (
"usage: prowler [-h] [--version] {aws,azure,gcp,kubernetes} ..."
)


def mock_get_available_providers():
Expand Down Expand Up @@ -54,15 +56,15 @@ def test_default_parser_no_arguments_aws(self):
assert parsed.log_level == "CRITICAL"
assert not parsed.log_file
assert not parsed.only_logs
assert not parsed.checks
assert not parsed.check
assert not parsed.checks_file
assert not parsed.checks_folder
assert not parsed.services
assert not parsed.service
assert not parsed.severity
assert not parsed.compliance
assert len(parsed.categories) == 0
assert not parsed.excluded_checks
assert not parsed.excluded_services
assert len(parsed.category) == 0
assert not parsed.excluded_check
assert not parsed.excluded_service
assert not parsed.list_checks
assert not parsed.list_services
assert not parsed.list_compliance
Expand All @@ -79,7 +81,7 @@ def test_default_parser_no_arguments_aws(self):
assert not parsed.output_bucket
assert not parsed.output_bucket_no_assume
assert not parsed.shodan
assert not parsed.resource_tags
assert not parsed.resource_tag
assert not parsed.scan_unused_services

def test_default_parser_no_arguments_azure(self):
Expand All @@ -100,15 +102,15 @@ def test_default_parser_no_arguments_azure(self):
assert parsed.log_level == "CRITICAL"
assert not parsed.log_file
assert not parsed.only_logs
assert not parsed.checks
assert not parsed.check
assert not parsed.checks_file
assert not parsed.checks_folder
assert not parsed.services
assert not parsed.service
assert not parsed.severity
assert not parsed.compliance
assert len(parsed.categories) == 0
assert not parsed.excluded_checks
assert not parsed.excluded_services
assert len(parsed.category) == 0
assert not parsed.excluded_check
assert not parsed.excluded_service
assert not parsed.list_checks
assert not parsed.list_services
assert not parsed.list_compliance
Expand Down Expand Up @@ -139,15 +141,15 @@ def test_default_parser_no_arguments_gcp(self):
assert parsed.log_level == "CRITICAL"
assert not parsed.log_file
assert not parsed.only_logs
assert not parsed.checks
assert not parsed.check
assert not parsed.checks_file
assert not parsed.checks_folder
assert not parsed.services
assert not parsed.service
assert not parsed.severity
assert not parsed.compliance
assert len(parsed.categories) == 0
assert not parsed.excluded_checks
assert not parsed.excluded_services
assert len(parsed.category) == 0
assert not parsed.excluded_check
assert not parsed.excluded_service
assert not parsed.list_checks
assert not parsed.list_services
assert not parsed.list_compliance
Expand All @@ -173,15 +175,15 @@ def test_default_parser_no_arguments_kubernetes(self):
assert parsed.log_level == "CRITICAL"
assert not parsed.log_file
assert not parsed.only_logs
assert not parsed.checks
assert not parsed.check
assert not parsed.checks_file
assert not parsed.checks_folder
assert not parsed.services
assert not parsed.service
assert not parsed.severity
assert not parsed.compliance
assert len(parsed.categories) == 0
assert not parsed.excluded_checks
assert not parsed.excluded_services
assert len(parsed.category) == 0
assert not parsed.excluded_check
assert not parsed.excluded_service
assert not parsed.list_checks
assert not parsed.list_services
assert not parsed.list_compliance
Expand Down Expand Up @@ -402,22 +404,22 @@ def test_exclude_checks_parser_excluded_checks_short(self):
excluded_checks = "check_test"
command = [prowler_command, "-e", excluded_checks]
parsed = self.parser.parse(command)
assert excluded_checks in parsed.excluded_checks
assert excluded_checks in parsed.excluded_check

def test_exclude_checks_parser_excluded_checks_short_two(self):
excluded_checks_1 = "check_test_1"
excluded_checks_2 = "check_test_2"
command = [prowler_command, "-e", excluded_checks_1, excluded_checks_2]
parsed = self.parser.parse(command)
assert len(parsed.excluded_checks) == 2
assert excluded_checks_1 in parsed.excluded_checks
assert excluded_checks_2 in parsed.excluded_checks
assert len(parsed.excluded_check) == 2
assert excluded_checks_1 in parsed.excluded_check
assert excluded_checks_2 in parsed.excluded_check

def test_exclude_checks_parser_excluded_checks_long(self):
excluded_check = "check_test"
command = [prowler_command, "--excluded-checks", excluded_check]
parsed = self.parser.parse(command)
assert excluded_check in parsed.excluded_checks
assert excluded_check in parsed.excluded_check

def test_exclude_checks_parser_excluded_checks_long_two(self):
excluded_checks_1 = "check_test_1"
Expand All @@ -429,15 +431,15 @@ def test_exclude_checks_parser_excluded_checks_long_two(self):
excluded_checks_2,
]
parsed = self.parser.parse(command)
assert len(parsed.excluded_checks) == 2
assert excluded_checks_1 in parsed.excluded_checks
assert excluded_checks_2 in parsed.excluded_checks
assert len(parsed.excluded_check) == 2
assert excluded_checks_1 in parsed.excluded_check
assert excluded_checks_2 in parsed.excluded_check

def test_exclude_checks_parser_excluded_services_long(self):
excluded_service = "accessanalyzer"
command = [prowler_command, "--excluded-services", excluded_service]
parsed = self.parser.parse(command)
assert excluded_service in parsed.excluded_services
assert excluded_service in parsed.excluded_service

def test_exclude_checks_parser_excluded_services_long_two(self):
excluded_service_1 = "accessanalyzer"
Expand All @@ -449,45 +451,45 @@ def test_exclude_checks_parser_excluded_services_long_two(self):
excluded_service_2,
]
parsed = self.parser.parse(command)
assert len(parsed.excluded_services) == 2
assert excluded_service_1 in parsed.excluded_services
assert excluded_service_2 in parsed.excluded_services
assert len(parsed.excluded_service) == 2
assert excluded_service_1 in parsed.excluded_service
assert excluded_service_2 in parsed.excluded_service

def test_checks_parser_checks_short(self):
check = "check_test_1"
argument = "-c"
command = [prowler_command, argument, check]
parsed = self.parser.parse(command)
assert len(parsed.checks) == 1
assert check in parsed.checks
assert len(parsed.check) == 1
assert check in parsed.check

def test_checks_parser_checks_short_two(self):
check_1 = "check_test_1"
check_2 = "check_test_2"
argument = "-c"
command = [prowler_command, argument, check_1, check_2]
parsed = self.parser.parse(command)
assert len(parsed.checks) == 2
assert check_1 in parsed.checks
assert check_2 in parsed.checks
assert len(parsed.check) == 2
assert check_1 in parsed.check
assert check_2 in parsed.check

def test_checks_parser_checks_long(self):
check = "check_test_1"
argument = "--checks"
command = [prowler_command, argument, check]
parsed = self.parser.parse(command)
assert len(parsed.checks) == 1
assert check in parsed.checks
assert len(parsed.check) == 1
assert check in parsed.check

def test_checks_parser_checks_long_two(self):
check_1 = "check_test_1"
check_2 = "check_test_2"
argument = "--checks"
command = [prowler_command, argument, check_1, check_2]
parsed = self.parser.parse(command)
assert len(parsed.checks) == 2
assert check_1 in parsed.checks
assert check_2 in parsed.checks
assert len(parsed.check) == 2
assert check_1 in parsed.check
assert check_2 in parsed.check

def test_checks_parser_checks_file_short(self):
argument = "-C"
Expand Down Expand Up @@ -522,34 +524,34 @@ def test_checks_parser_services_short(self):
service_1 = "iam"
command = [prowler_command, argument, service_1]
parsed = self.parser.parse(command)
assert service_1 in parsed.services
assert service_1 in parsed.service

def test_checks_parser_services_short_two(self):
argument = "-s"
service_1 = "iam"
service_2 = "s3"
command = [prowler_command, argument, service_1, service_2]
parsed = self.parser.parse(command)
assert len(parsed.services) == 2
assert service_1 in parsed.services
assert service_2 in parsed.services
assert len(parsed.service) == 2
assert service_1 in parsed.service
assert service_2 in parsed.service

def test_checks_parser_services_long(self):
argument = "--services"
service_1 = "iam"
command = [prowler_command, argument, service_1]
parsed = self.parser.parse(command)
assert service_1 in parsed.services
assert service_1 in parsed.service

def test_checks_parser_services_long_two(self):
argument = "--services"
service_1 = "iam"
service_2 = "s3"
command = [prowler_command, argument, service_1, service_2]
parsed = self.parser.parse(command)
assert len(parsed.services) == 2
assert service_1 in parsed.services
assert service_2 in parsed.services
assert len(parsed.service) == 2
assert service_1 in parsed.service
assert service_2 in parsed.service

def test_checks_parser_services_with_severity(self):
argument1 = "--services"
Expand All @@ -558,8 +560,8 @@ def test_checks_parser_services_with_severity(self):
severity = "low"
command = [prowler_command, argument1, service_1, argument2, severity]
parsed = self.parser.parse(command)
assert len(parsed.services) == 1
assert service_1 in parsed.services
assert len(parsed.service) == 1
assert service_1 in parsed.service
assert len(parsed.severity) == 1
assert severity in parsed.severity

Expand Down Expand Up @@ -654,18 +656,18 @@ def test_checks_parser_categories(self):
category = "secrets"
command = [prowler_command, argument, category]
parsed = self.parser.parse(command)
assert len(parsed.categories) == 1
assert category in parsed.categories
assert len(parsed.category) == 1
assert category in parsed.category

def test_checks_parser_categories_two(self):
argument = "--categories"
category_1 = "secrets"
category_2 = "forensics"
command = [prowler_command, argument, category_1, category_2]
parsed = self.parser.parse(command)
assert len(parsed.categories) == 2
assert category_1 in parsed.categories
assert category_2 in parsed.categories
assert len(parsed.category) == 2
assert category_1 in parsed.category
assert category_2 in parsed.category

def test_list_checks_parser_list_checks_short(self):
argument = "-l"
Expand Down Expand Up @@ -1011,9 +1013,9 @@ def test_aws_parser_resource_tags(self):
scan_tag2 = "Key2=Value2"
command = [prowler_command, argument, scan_tag1, scan_tag2]
parsed = self.parser.parse(command)
assert len(parsed.resource_tags) == 2
assert scan_tag1 in parsed.resource_tags
assert scan_tag2 in parsed.resource_tags
assert len(parsed.resource_tag) == 2
assert scan_tag1 in parsed.resource_tag
assert scan_tag2 in parsed.resource_tag

def test_aws_parser_resource_arn(self):
argument = "--resource-arn"
Expand Down

0 comments on commit 6aaca36

Please sign in to comment.