Skip to content

Commit 0b7c587

Browse files
committed
Add unitest for populate cac product nameto component title
Signed-off-by: Sophia Wang <huiwang@redhat.com>
1 parent 2ae3bb7 commit 0b7c587

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
product: ocp4
2+
full_name: Red Hat OpenShift Container Platform 4
3+
type: platform
4+
5+
benchmark_id: OCP-4
6+
benchmark_root: "../../applications"
7+
8+
profiles_root: "./profiles"
9+
10+
pkg_system: "rpm"
11+
12+
init_system: "systemd"
13+
14+
reference_uris:
15+
cis: 'https://www.cisecurity.org/benchmark/kubernetes/'
16+
stigid: 'https://public.cyber.mil/stigs/downloads/?_dl_facet_stigs=container-platform'
17+
18+
cpes_root: "../../shared/applicability"
19+
cpes:
20+
- ocp4:
21+
name: "cpe:/a:redhat:openshift_container_platform:4.1"
22+
title: "Red Hat OpenShift Container Platform 4"
23+
check_id: installed_app_is_ocp4
24+
25+
- ocp4-node:
26+
name: "cpe:/o:redhat:openshift_container_platform_node:4"
27+
title: "Red Hat OpenShift Container Platform 4 Node"
28+
check_id: installed_app_is_ocp4_node
29+
30+
- ocp4-node-on-ovn:
31+
name: "cpe:/a:redhat:openshift_container_platform_node_on_ovn:4"
32+
title: "Red Hat OpenShift Container Platform 4 Node on OVN"
33+
check_id: installed_app_is_ocp4_node_on_openshift-ovn
34+
35+
- ocp4-node-on-sdn:
36+
name: "cpe:/a:redhat:openshift_container_platform_node_on_sdn:4"
37+
title: "Red Hat OpenShift Container Platform 4 Node on SDN"
38+
check_id: installed_app_is_ocp4_node_on_openshift-sdn
39+
40+
- ocp4.6:
41+
name: "cpe:/a:redhat:openshift_container_platform:4.6"
42+
title: "Red Hat OpenShift Container Platform 4.6"
43+
check_id: installed_app_is_ocp4_6
44+
45+
- ocp4.7:
46+
name: "cpe:/a:redhat:openshift_container_platform:4.7"
47+
title: "Red Hat OpenShift Container Platform 4.7"
48+
check_id: installed_app_is_ocp4_7
49+
50+
- ocp4.8:
51+
name: "cpe:/a:redhat:openshift_container_platform:4.8"
52+
title: "Red Hat OpenShift Container Platform 4.8"
53+
check_id: installed_app_is_ocp4_8
54+
55+
- ocp4.9:
56+
name: "cpe:/a:redhat:openshift_container_platform:4.9"
57+
title: "Red Hat OpenShift Container Platform 4.9"
58+
check_id: installed_app_is_ocp4_9
59+
60+
- ocp4.10:
61+
name: "cpe:/a:redhat:openshift_container_platform:4.10"
62+
title: "Red Hat OpenShift Container Platform 4.10"
63+
check_id: installed_app_is_ocp4_10
64+
65+
- ocp4.11:
66+
name: "cpe:/a:redhat:openshift_container_platform:4.11"
67+
title: "Red Hat OpenShift Container Platform 4.11"
68+
check_id: installed_app_is_ocp4_11
69+
70+
- ocp4.12:
71+
name: "cpe:/a:redhat:openshift_container_platform:4.12"
72+
title: "Red Hat OpenShift Container Platform 4.12"
73+
check_id: installed_app_is_ocp4_12
74+
75+
- ocp4.13:
76+
name: "cpe:/a:redhat:openshift_container_platform:4.13"
77+
title: "Red Hat OpenShift Container Platform 4.13"
78+
check_id: installed_app_is_ocp4_13
79+
80+
- ocp4.14:
81+
name: "cpe:/a:redhat:openshift_container_platform:4.14"
82+
title: "Red Hat OpenShift Container Platform 4.14"
83+
check_id: installed_app_is_ocp4_14
84+
85+
- ocp4.15:
86+
name: "cpe:/a:redhat:openshift_container_platform:4.15"
87+
title: "Red Hat OpenShift Container Platform 4.15"
88+
check_id: installed_app_is_ocp4_15
89+
90+
- ocp4.16:
91+
name: "cpe:/a:redhat:openshift_container_platform:4.16"
92+
title: "Red Hat OpenShift Container Platform 4.16"
93+
check_id: installed_app_is_ocp4_16
94+
95+
- ocp4.17:
96+
name: "cpe:/a:redhat:openshift_container_platform:4.17"
97+
title: "Red Hat OpenShift Container Platform 4.17"
98+
check_id: installed_app_is_ocp4_17
99+
100+
- ocp4.18:
101+
name: "cpe:/a:redhat:openshift_container_platform:4.18"
102+
title: "Red Hat OpenShift Container Platform 4.18"
103+
check_id: installed_app_is_ocp4_18
104+
105+
- ocp4-on-aws:
106+
name: "cpe:/a:redhat:openshift_container_platform_on_aws:4"
107+
title: "Red Hat OpenShift Container Platform 4 on AWS"
108+
check_id: installed_app_is_ocp4_on_aws
109+
110+
- ocp4-on-azure:
111+
name: "cpe:/a:redhat:openshift_container_platform_on_azure:4"
112+
title: "Red Hat OpenShift Container Platform 4 on Azure"
113+
check_id: installed_app_is_ocp4_on_azure
114+
115+
- ocp4-on-gcp:
116+
name: "cpe:/a:redhat:openshift_container_platform_on_gcp:4"
117+
title: "Red Hat OpenShift Container Platform 4 on GCP"
118+
check_id: installed_app_is_ocp4_on_gcp
119+
120+
- ocp4-on-ovn:
121+
name: "cpe:/a:redhat:openshift_container_platform_on_ovn:4"
122+
title: "Red Hat OpenShift Container Platform 4 on OVN"
123+
check_id: installed_app_is_ocp4_on_openshiftovn
124+
125+
- ocp4-on-sdn:
126+
name: "cpe:/a:redhat:openshift_container_platform_on_sdn:4"
127+
title: "Red Hat OpenShift Container Platform 4 on SDN"
128+
check_id: installed_app_is_ocp4_on_openshiftsdn
129+
130+
131+
# Requirement string, see: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#requirements-parsing
132+
# requires: "openscap>=1.3.4"

tests/trestlebot/cli/test_sync_cac_content_cmd.py

+53
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@
88
from click.testing import CliRunner
99
from git import Repo
1010

11+
from tests.testutils import setup_for_catalog, setup_for_profile
1112
from trestlebot.cli.commands.sync_cac_content import sync_cac_content_cmd
1213

1314

1415
test_product = "ocp4"
16+
cac_content_test_data = pathlib.Path("tests/data/content").resolve()
17+
test_prof_path = pathlib.Path("tests/data/json/").resolve()
18+
test_prof = "simplified_nist_profile"
19+
test_cat = "simplified_nist_catalog"
20+
test_comp_path = {
21+
"component-definitions",
22+
"cac-components",
23+
"component-definition.json",
24+
}
1525

1626

1727
def test_missing_required_option(tmp_repo: Tuple[str, Repo]) -> None:
@@ -37,3 +47,46 @@ def test_missing_required_option(tmp_repo: Tuple[str, Repo]) -> None:
3747
],
3848
)
3949
assert result.exit_code == 2
50+
51+
52+
def test_sync_product_name(tmp_repo: Tuple[str, Repo]) -> None:
53+
"""Tests sync Cac content product name to OSCAL component title ."""
54+
repo_dir, _ = tmp_repo
55+
repo_path = pathlib.Path(repo_dir)
56+
setup_for_catalog(repo_path, test_cat, "catalog")
57+
setup_for_profile(repo_path, test_prof, "profile")
58+
59+
runner = CliRunner()
60+
result = runner.invoke(
61+
sync_cac_content_cmd,
62+
[
63+
"--product",
64+
test_product,
65+
"--repo-path",
66+
str(repo_path.resolve()),
67+
"--cac-content-root",
68+
cac_content_test_data,
69+
"--cac-profile",
70+
"cac-profile",
71+
"--oscal-profile",
72+
test_prof,
73+
"--committer-email",
74+
"test@email.com",
75+
"--committer-name",
76+
"test name",
77+
"--markdown-dir",
78+
"markdown",
79+
"--branch",
80+
"test",
81+
"--dry-run",
82+
],
83+
)
84+
# Check the CLI sync-cac-content is successful
85+
assert result.exit_code == 0
86+
# Check if the component definition is created
87+
component_definition = repo_path.joinpath(next(iter(test_comp_path)))
88+
assert component_definition.exists()
89+
# Check if it populates the product name as the component title
90+
with open(component_definition, "r", encoding="utf-8") as file:
91+
content = file.read()
92+
assert '"title": "ocp4"' in content

0 commit comments

Comments
 (0)