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: updates CSVTransformer to separate controls with spaces instead of commas #183

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def test_rule() -> TrestleRule:
),
check=Check(name="test_check", description="test check"),
profile=Profile(
description="test", href="test", include_controls=[Control(id="ac-1")]
description="test",
href="test",
include_controls=[Control(id="ac-1"), Control(id="ac-2")],
),
)
return test_trestle_rule
Expand Down
21 changes: 21 additions & 0 deletions tests/data/yaml/test_complete_rule_multiple_controls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
x-trestle-rule-info:
name: example_rule_3
description: My rule description for example rule 3
parameter:
name: prm_1
description: prm_1 description
alternative-values: {'default': '5%', '5pc': '5%', '10pc': '10%', '15pc': '15%', '20pc': '20%'}
default-value: '5%'
check:
name: my_check
description: My check description
profile:
description: Simple NIST Profile
href: profiles/simplified_nist_profile/profile.json
include-controls:
- id: ac-1
- id: ac-1_smt.a
x-trestle-component-info:
name: Component 1
description: Component 1 description
type: service
2 changes: 2 additions & 0 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def setup_rules_view(
load_from_yaml(comp_dir, "test_complete_rule")
# Load a complete rule with only required fields
load_from_yaml(comp_dir, "test_complete_rule_no_params")
# Load a complete rule with multiple controls
load_from_yaml(comp_dir, "test_complete_rule_multiple_controls")


def replace_string_in_file(file_path: str, old_string: str, new_string: str) -> None:
Expand Down
14 changes: 9 additions & 5 deletions tests/trestlebot/tasks/test_rule_transform_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ def test_rule_transform_task(tmp_trestle_dir: str) -> None:

assert component is not None
assert component.props is not None
assert len(component.props) == 7
assert component.props[0].name == RULE_ID
assert component.props[0].value == "example_rule_1"
assert component.props[1].name == RULE_DESCRIPTION
assert component.props[1].value == "My rule description for example rule 1"
assert len(component.props) == 14

prop_values = [prop.value for prop in component.props]
assert "example_rule_1" in prop_values
assert "My rule description for example rule 1" in prop_values
assert "example_rule_3" in prop_values
assert "My rule description for example rule 3" in prop_values
assert "my_check" in prop_values
assert "My check description" in prop_values


def test_rule_transform_task_with_no_rules(tmp_trestle_dir: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/trestlebot/transformers/test_csv_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_csv_builder(test_rule: TrestleRule, tmp_trestle_dir: str) -> None:
assert row["Component_Title"] == test_rule.component.name
assert row["Component_Type"] == test_rule.component.type
assert row["Component_Description"] == test_rule.component.description
assert row["Control_Id_List"] == "ac-1"
assert row["Control_Id_List"] == "ac-1 ac-2"
assert row["Parameter_Id"] == test_rule.parameter.name # type: ignore
assert row["Parameter_Description"] == test_rule.parameter.description # type: ignore
assert row["Parameter_Value_Alternatives"] == "{}"
Expand Down
4 changes: 2 additions & 2 deletions trestlebot/transformers/csv_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _extract_rule_info(self, row: Dict[str, str]) -> Dict[str, str]:

def _extract_profile(self, row: Dict[str, str]) -> Profile:
"""Extract profile information from a CSV row."""
controls_list = row.get(csv_to_oscal_cd.CONTROL_ID_LIST, "").split(", ")
controls_list = row.get(csv_to_oscal_cd.CONTROL_ID_LIST, "").split(" ")
return Profile(
description=row.get(csv_to_oscal_cd.PROFILE_DESCRIPTION, ""),
href=row.get(csv_to_oscal_cd.PROFILE_SOURCE, ""),
Expand Down Expand Up @@ -170,7 +170,7 @@ def _add_profile(self, profile: Profile) -> Dict[str, str]:
profile_dict: Dict[str, str] = {
PROFILE_DESCRIPTION: profile.description,
PROFILE_SOURCE: profile.href,
CONTROL_ID_LIST: ", ".join(controls_list),
CONTROL_ID_LIST: " ".join(controls_list),
}
return profile_dict

Expand Down
Loading