Skip to content

Commit

Permalink
test: adds inheritance view testing for ssp-assemble
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
  • Loading branch information
jpower432 committed Sep 1, 2023
1 parent 01a5a33 commit 3e1ce19
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@ def replace_line_in_file_after_tag(file_path: pathlib.Path, tag: str, new_line:
return False


def replace_in_file(file_path: pathlib.Path, search_text: str, replace_text: str) -> None:
"""Replace all occurrences of search_text with replace_text in file_path."""
if not file_path.exists():
raise TrestleError(f'Test file {file_path} not found.')

with open(file_path, 'r') as file:
file_content = file.read()

updated_content = file_content.replace(search_text, replace_text)

with open(file_path, 'w') as file:
file.write(updated_content)


def substitute_text_in_file(file_path: pathlib.Path, tag: str, new_str: str) -> bool:
"""Substitute first match of string with new string in file."""
if not file_path.exists():
Expand Down
23 changes: 21 additions & 2 deletions tests/trestle/core/commands/author/ssp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,15 +548,23 @@ def test_ssp_generate_resolved_catalog(tmp_trestle_dir: pathlib.Path) -> None:
resolved_catalog.oscal_write(new_catalog_path)


def test_ssp_assemble_w_inhert(tmp_trestle_dir: pathlib.Path) -> None:
"""Test ssp assemble from cli."""
def test_ssp_assemble_with_inheritance(tmp_trestle_dir: pathlib.Path) -> None:
"""Test ssp assemble from cli with inheritance view."""
gen_args, _ = setup_for_ssp(tmp_trestle_dir, prof_name, ssp_name, False, 'leveraged_ssp')
args_compdefs = gen_args.compdefs

# first create the markdown
ssp_gen = SSPGenerate()
assert ssp_gen._run(gen_args) == 0

this_system_dir = tmp_trestle_dir / ssp_name / const.INHERITANCE_VIEW_DIR / 'This System'

expected_uuid = '11111111-0000-4000-9009-001001002001'
ac_21 = this_system_dir / 'ac-2.1'
test_provided = ac_21 / f'{expected_uuid}.md'

test_utils.replace_in_file(test_provided, 'REPLACE_ME', 'comp_aa')

# now assemble the edited controls into json ssp
ssp_assemble = SSPAssemble()
args = argparse.Namespace(
Expand All @@ -571,6 +579,17 @@ def test_ssp_assemble_w_inhert(tmp_trestle_dir: pathlib.Path) -> None:
)
assert ssp_assemble._run(args) == 0

ssp, _ = ModelUtils.load_model_for_class(tmp_trestle_dir, ssp_name, ossp.SystemSecurityPlan, FileContentType.JSON)

imp_reqs = ssp.control_implementation.implemented_requirements
imp_req = next((i_req for i_req in imp_reqs if i_req.control_id == 'ac-2.1'), None)
inherited = imp_req.by_components[1].inherited[0] # type: ignore
assert inherited.description == (
'Consumer-appropriate description of what may be inherited.\n\n\
In the context of the application component in satisfaction of AC-2.1.'
)
assert inherited.provided_uuid == expected_uuid


def test_ssp_filter(tmp_trestle_dir: pathlib.Path) -> None:
"""Test the ssp filter."""
Expand Down

0 comments on commit 3e1ce19

Please sign in to comment.