Beispiel #1
0
    def test(self):
        runner = Runner()
        current_dir = os.path.dirname(os.path.realpath(__file__))

        test_files_dir = current_dir + "/example_ReferenceLatestTag"
        report = runner.run(root_folder=test_files_dir,
                            runner_filter=RunnerFilter(checks=[check.id]))
        summary = report.get_summary()

        passing_resources = {
            "/success/Dockerfile.", "/success_multi_stage/Dockerfile.",
            "/success_multi_stage_capital/Dockerfile."
        }
        failing_resources = {
            "/failure_default_version_tag/Dockerfile.FROM",
            "/failure_latest_version_tag/Dockerfile.FROM",
        }

        passed_check_resources = set(
            [c.resource for c in report.passed_checks])
        failed_check_resources = set(
            [c.resource for c in report.failed_checks])

        self.assertEqual(summary["passed"], 3)
        self.assertEqual(summary["failed"], 2)
        self.assertEqual(summary["skipped"], 0)
        self.assertEqual(summary["parsing_errors"], 0)

        self.assertEqual(passing_resources, passed_check_resources)
        self.assertEqual(failing_resources, failed_check_resources)
Beispiel #2
0
 def test_runner_name_variations(self):
     current_dir = os.path.dirname(os.path.realpath(__file__))
     valid_dir_path = current_dir + "/resources/name_variations"
     runner = Runner()
     report = runner.run(root_folder=valid_dir_path, external_checks_dir=None,
                         runner_filter=RunnerFilter(framework='all'))
     self.assertEqual(len(report.resources), 2)
     self.assertEqual(len([file for file in report.resources if 'Dockerfile.prod' in file]), 1)
     self.assertEqual(len([file for file in report.resources if 'prod.dockerfile' in file]), 1)
     report.print_console()
Beispiel #3
0
 def test_runner_skip_check(self):
     current_dir = os.path.dirname(os.path.realpath(__file__))
     valid_dir_path = current_dir + "/resources/expose_port/skip"
     runner = Runner()
     report = runner.run(root_folder=valid_dir_path, external_checks_dir=None,
                         runner_filter=RunnerFilter(framework='all',checks=['CKV_DOCKER_1']))
     self.assertEqual(len(report.skipped_checks), 1)
     self.assertEqual(report.parsing_errors, [])
     self.assertEqual(report.failed_checks, [])
     self.assertEqual(report.passed_checks, [])
     report.print_console()
Beispiel #4
0
 def test_runner_empty_dockerfile(self):
     current_dir = os.path.dirname(os.path.realpath(__file__))
     valid_dir_path = current_dir + "/resources/empty_dockerfile"
     runner = Runner()
     report = runner.run(root_folder=valid_dir_path, external_checks_dir=None,
                         runner_filter=RunnerFilter(framework='all'))
     self.assertEqual(report.failed_checks, [])
     self.assertEqual(report.parsing_errors, [])
     self.assertEqual(report.passed_checks, [])
     self.assertEqual(report.skipped_checks, [])
     report.print_console()
Beispiel #5
0
 def test_skip_wildcard_check(self):
     current_dir = os.path.dirname(os.path.realpath(__file__))
     valid_dir_path = current_dir + "/resources/wildcard_skip"
     runner = Runner()
     report = runner.run(
         root_folder=valid_dir_path,
         external_checks_dir=None,
         runner_filter=RunnerFilter(framework=['dockerfile']))
     self.assertEqual(len(report.skipped_checks), 1)
     self.assertGreaterEqual(len(report.passed_checks), 1)
     self.assertGreaterEqual(len(report.failed_checks), 2)
Beispiel #6
0
 def test_runner_failing_check_with_file_path(self):
     current_dir = os.path.dirname(os.path.realpath(__file__))
     valid_file_path = current_dir + "/resources/expose_port/fail/Dockerfile"
     runner = Runner()
     report = runner.run(
         files=[valid_file_path],
         external_checks_dir=None,
         runner_filter=RunnerFilter(framework="all", checks=["CKV_DOCKER_1"]),
     )
     self.assertEqual(len(report.failed_checks), 1)
     self.assertEqual(report.parsing_errors, [])
     self.assertEqual(report.passed_checks, [])
     self.assertEqual(report.skipped_checks, [])
     report.print_console()
    def test(self):
        runner = Runner()
        current_dir = os.path.dirname(os.path.realpath(__file__))

        test_files_dir = current_dir + "/example_MaintainerExists"
        report = runner.run(root_folder=test_files_dir,
                            runner_filter=RunnerFilter(checks=[check.id]))
        summary = report.get_summary()

        failing_resources = {"/failure/Dockerfile.MAINTAINER"}

        failed_check_resources = set(
            [c.resource for c in report.failed_checks])

        self.assertEqual(summary["passed"], 0)
        self.assertEqual(summary["failed"], 1)
        self.assertEqual(summary["skipped"], 0)
        self.assertEqual(summary["parsing_errors"], 0)

        self.assertEqual(failing_resources, failed_check_resources)
    def test(self):
        runner = Runner()
        current_dir = os.path.dirname(os.path.realpath(__file__))

        test_files_dir = current_dir + "/example_UpdateNotAlone"
        report = runner.run(root_folder=test_files_dir,
                            runner_filter=RunnerFilter(checks=[check.id]))
        summary = report.get_summary()

        passing_resources = {"/success/Dockerfile."}
        failing_resources = {"/failure/Dockerfile.RUN"}

        passed_check_resources = set(
            [c.resource for c in report.passed_checks])
        failed_check_resources = set(
            [c.resource for c in report.failed_checks])

        self.assertEqual(summary["passed"], 1)
        self.assertEqual(summary["failed"], 1)
        self.assertEqual(summary["skipped"], 0)
        self.assertEqual(summary["parsing_errors"], 0)

        self.assertEqual(passing_resources, passed_check_resources)
        self.assertEqual(failing_resources, failed_check_resources)