def test_loading_external_checks_python_and_yaml(self): runner = Runner() from tests.terraform.runner.extra_checks.S3EnvironmentCheck import scanner current_dir = os.path.dirname(os.path.realpath(__file__)) extra_checks_dir_paths = [ current_dir + "/extra_checks", current_dir + "/extra_yaml_checks" ] runner.load_external_checks(extra_checks_dir_paths) found = 0 for resource_type in scanner.supported_resources: checks = resource_registry.checks[resource_type] self.assertIn(scanner, checks) found += 1 self.assertEqual(found, len(scanner.supported_resources)) self.assertEqual( len( list( filter(lambda c: c.id == CUSTOM_GRAPH_CHECK_ID, graph_registry.checks))), 1) self.assertEqual(graph_registry.checks[-1].id, CUSTOM_GRAPH_CHECK_ID) self.assertEqual(graph_registry.checks[-1].name, 'Ensure bucket has versioning and owner tag') graph_registry.checks = list( filter(lambda c: c.id != CUSTOM_GRAPH_CHECK_ID, graph_registry.checks))
def test_loading_external_checks_yaml(self): runner = Runner() graph_registry.load_checks() base_len = len(graph_registry.checks) current_dir = os.path.dirname(os.path.realpath(__file__)) extra_checks_dir_path = current_dir + "/extra_yaml_checks" runner.load_external_checks([extra_checks_dir_path]) self.assertEqual(len(graph_registry.checks), base_len + 1) self.assertEqual(graph_registry.checks[base_len].id, CUSTOM_GRAPH_CHECK_ID) self.assertEqual(graph_registry.checks[base_len].name, 'Ensure bucket has versioning and owner tag') graph_registry.checks = list(filter(lambda c: c.id != CUSTOM_GRAPH_CHECK_ID, graph_registry.checks))
def test_loading_external_checks_python(self): runner = Runner() from tests.terraform.runner.extra_checks.S3EnvironmentCheck import scanner current_dir = os.path.dirname(os.path.realpath(__file__)) extra_checks_dir_paths = [current_dir + "/extra_checks"] runner.load_external_checks(extra_checks_dir_paths) found = 0 for resource_type in scanner.supported_resources: checks = resource_registry.checks[resource_type] self.assertIn(scanner, checks) found += 1 self.assertEqual(found, len(scanner.supported_resources))
def test_external_graph_check_load(self): runner = Runner() current_dir = os.path.dirname(os.path.realpath(__file__)) runner.graph_registry.checks = [] extra_checks_dir_path = [current_dir + "/extra_yaml_checks"] runner.load_external_checks(extra_checks_dir_path) self.assertEqual(len(runner.graph_registry.checks), 1) runner_filter = RunnerFilter() for check in runner.graph_registry.checks: self.assertTrue(runner_filter.is_external_check(check.id)) runner.graph_registry.checks[:] = [ check for check in runner.graph_registry.checks if "CUSTOM_GRAPH_AWS_1" not in check.id ]