Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(arm): Fix arm report resource naming #6876

Merged
merged 16 commits into from
Nov 26, 2024
11 changes: 7 additions & 4 deletions checkov/arm/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ def add_python_check_results(self, report: Report, runner_filter: RunnerFilter,
logging.debug(f"Could not determine 'resource_id' of Resource {resource}")
continue

report.add_resource(f"{arm_file}:{resource_id}")
cleaned_path = clean_file_path(Path(arm_file))

report.add_resource(f"{cleaned_path}:{resource_id}")
entity_lines_range, entity_code_lines = arm_context_parser.extract_arm_resource_code_lines(
resource
)
Expand All @@ -187,7 +189,7 @@ def add_python_check_results(self, report: Report, runner_filter: RunnerFilter,
check_name=check.name,
check_result=check_result,
code_block=entity_code_lines,
file_path=arm_file,
file_path=self.extract_file_path_from_abs_path(cleaned_path),
file_line_range=entity_lines_range,
resource=resource_id,
evaluations=variable_evaluations,
Expand All @@ -202,7 +204,7 @@ def add_python_check_results(self, report: Report, runner_filter: RunnerFilter,
report.extra_resources.add(
ExtraResource(
file_abs_path=file_abs_path,
file_path=arm_file,
file_path=self.extract_file_path_from_abs_path(cleaned_path),
resource=resource_id,
)
)
Expand Down Expand Up @@ -232,12 +234,13 @@ def add_python_check_results(self, report: Report, runner_filter: RunnerFilter,
entity_config=parameter_details,
resource_attributes_to_omit=runner_filter.resource_attr_to_omit,
)
cleaned_path = clean_file_path(Path(arm_file))
self.build_record(
report=report,
check=check,
check_result=check_result,
code_block=censored_code_lines,
file_path=arm_file,
file_path=self.extract_file_path_from_abs_path(cleaned_path),
file_abs_path=file_abs_path,
file_line_range=entity_lines_range,
resource_id=resource_id,
Expand Down
5 changes: 2 additions & 3 deletions tests/arm/runner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_record_relative_path_with_relative_dir(self):
self.assertGreater(len(all_checks), 0) # ensure that the assertions below are going to do something
for record in all_checks:
# no need to join with a '/' because the CFN runner adds it to the start of the file path
self.assertEqual(record.repo_file_path, f'/{record.file_path}')
self.assertEqual(record.repo_file_path, f'/{dir_rel_path}{record.file_path}')

def test_record_relative_path_with_abs_dir(self):

Expand All @@ -88,8 +88,7 @@ def test_record_relative_path_with_abs_dir(self):
all_checks = report.failed_checks + report.passed_checks
self.assertGreater(len(all_checks), 0) # ensure that the assertions below are going to do something
for record in all_checks:
file_name = record.file_path.split('/')[-1]
self.assertEqual(record.repo_file_path, f'/{dir_rel_path}/{file_name}')
self.assertEqual(record.repo_file_path, f'/{dir_rel_path}{record.file_path}')

def test_record_relative_path_with_relative_file(self):
# test whether the record's repo_file_path is correct, relative to the CWD (with a / at the start).
Expand Down
Loading