Skip to content

Commit

Permalink
simplify & improve test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Lou DeGenaro <[email protected]>
  • Loading branch information
degenaro committed Jan 3, 2025
1 parent be67c3e commit cc5eda9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/trestle/tasks/cis_xlsx_to_oscal_cd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ def test_cis_xlsx_to_oscal_cd_execute_control_prefix(tmp_path: pathlib.Path):
_validate_db2(tmp_path)


def test_cis_xlsx_to_oscal_cd_execute_control_bad(tmp_path: pathlib.Path):
"""Test execute call - control bad."""
section = _get_section(tmp_path, db2_config)
section['benchmark-file'
] = 'tests/data/tasks/cis-xlsx-to-oscal-cd/CIS_IBM_Db2_11_Benchmark_v1.1.0.snippet_bad_control.xlsx'
tgt = cis_xlsx_to_oscal_cd.CisXlsxToOscalCd(section)
retval = tgt.execute()
assert retval == TaskOutcome.FAILURE


def test_cis_xlsx_to_oscal_cd_execute_columns_exclude(tmp_path: pathlib.Path):
"""Test execute call - control prefix."""
section = _get_section(tmp_path, db2_config)
section['columns-exclude'] = '"Recommendation #", "Profile", "Description"'
tgt = cis_xlsx_to_oscal_cd.CisXlsxToOscalCd(section)
retval = tgt.execute()
assert retval == TaskOutcome.SUCCESS
_validate_db2(tmp_path)


def _validate_db2(tmp_path: pathlib.Path):
"""Validate produced OSCAL for db2 cd."""
# read catalog
Expand Down
9 changes: 5 additions & 4 deletions trestle/tasks/cis_xlsx_to_oscal_cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,10 +645,11 @@ def get_ctl_list(self, ctl_pfx: str, profile_version: List[str]) -> List[str]:
if ctl['control-version'] not in profile_version:
continue
ctl_id = ctl['control-id']
if not ctl_id:
continue
if not float(ctl_id):
continue
try:
float(ctl_id)
except Exception:
text = f'missing or invalid control-id: "{ctl_id}"'
raise RuntimeError(text)
ctl_list.append(f'{ctl_pfx}{ctl_id}')
return ctl_list

Expand Down

0 comments on commit cc5eda9

Please sign in to comment.