-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adds integration test bewtween rules transform, assemble, and r…
…egenerate Fixes bug in component definition autosync Update AuthoredComponentsDefinition to AuthoredComponentDefinition Signed-off-by: Jennifer Power <[email protected]>
- Loading branch information
Showing
7 changed files
with
150 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/python | ||
|
||
# Copyright 2023 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
"""Integration tests between different types of tasks classes.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/usr/bin/python | ||
|
||
# Copyright 2023 Red Hat, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
"""Component test the rules transformation workflow.""" | ||
|
||
import os | ||
import pathlib | ||
|
||
from trestle.common.load_validate import load_validate_model_name | ||
from trestle.oscal import component as comp | ||
|
||
import trestlebot.const as const | ||
from tests.testutils import setup_for_profile | ||
from trestlebot.tasks.assemble_task import AssembleTask | ||
from trestlebot.tasks.authored.compdef import AuthoredComponentDefinition | ||
from trestlebot.tasks.authored.types import AuthoredType | ||
from trestlebot.tasks.regenerate_task import RegenerateTask | ||
from trestlebot.tasks.rule_transform_task import RuleTransformTask | ||
from trestlebot.transformers.yaml_transformer import ToRulesYAMLTransformer | ||
|
||
|
||
test_component_definition = "test_component_definition" | ||
test_profile = "simplified_nist_profile" | ||
test_md_path = "md_compdef" | ||
|
||
|
||
def test_rules_transform_workflow(tmp_trestle_dir: str) -> None: | ||
"""Test the rules transformation workflow for component definitions.""" | ||
|
||
trestle_root_path = pathlib.Path(tmp_trestle_dir) | ||
|
||
# Environment setup and initial rule generation | ||
_ = setup_for_profile(trestle_root_path, test_profile, test_profile) | ||
|
||
authored_compdef = AuthoredComponentDefinition(trestle_root=tmp_trestle_dir) | ||
authored_compdef.create_new_default( | ||
profile_name=test_profile, | ||
compdef_name=test_component_definition, | ||
comp_title="Test", | ||
comp_description="Test component definition", | ||
comp_type="service", | ||
) | ||
|
||
# Transform | ||
transform = RuleTransformTask( | ||
tmp_trestle_dir, const.RULES_VIEW_DIR, ToRulesYAMLTransformer() | ||
) | ||
transform.execute() | ||
|
||
# Load the component definition | ||
compdef: comp.ComponentDefinition | ||
compdef, _ = load_validate_model_name( | ||
trestle_root_path, test_component_definition, comp.ComponentDefinition | ||
) | ||
|
||
assert len(compdef.components) == 1 | ||
component = compdef.components[0] | ||
|
||
assert component.title == "Test" | ||
assert component.description == "Test component definition" | ||
assert component.type == "service" | ||
assert len(component.props) == 24 | ||
assert len(component.control_implementations) == 1 | ||
assert ( | ||
component.control_implementations[0].source | ||
== f"trestle://profiles/{test_profile}/profile.json" | ||
) | ||
|
||
last_modified = compdef.metadata.last_modified | ||
|
||
# Run regenerate | ||
regenerate = RegenerateTask( | ||
tmp_trestle_dir, AuthoredType.COMPDEF.value, test_md_path | ||
) | ||
regenerate.execute() | ||
|
||
assert os.path.exists( | ||
os.path.join(trestle_root_path, test_md_path, test_component_definition) | ||
) | ||
|
||
# Run assemble | ||
assemble = AssembleTask(tmp_trestle_dir, AuthoredType.COMPDEF.value, test_md_path) | ||
assemble.execute() | ||
|
||
# Load the component definition | ||
compdef, _ = load_validate_model_name( | ||
trestle_root_path, test_component_definition, comp.ComponentDefinition | ||
) | ||
|
||
assert len(compdef.components) == 1 | ||
component = compdef.components[0] | ||
|
||
# Asset last modified is updated, but all expected information is still present | ||
assert compdef.metadata.last_modified > last_modified | ||
|
||
assert component.title == "Test" | ||
assert component.description == "Test component definition" | ||
assert component.type == "service" | ||
assert len(component.props) == 24 | ||
assert len(component.control_implementations) == 1 | ||
assert ( | ||
component.control_implementations[0].source | ||
== f"trestle://profiles/{test_profile}/profile.json" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters