Skip to content

Commit

Permalink
Add unitest for populate cac product nameto component title
Browse files Browse the repository at this point in the history
Signed-off-by: Sophia Wang <huiwang@redhat.com>
  • Loading branch information
huiwangredhat committed Dec 26, 2024
1 parent 2ae3bb7 commit 0b7c587
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 0 deletions.
132 changes: 132 additions & 0 deletions tests/data/content/products/ocp4/product.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
product: ocp4
full_name: Red Hat OpenShift Container Platform 4
type: platform

benchmark_id: OCP-4
benchmark_root: "../../applications"

profiles_root: "./profiles"

pkg_system: "rpm"

init_system: "systemd"

reference_uris:
cis: 'https://www.cisecurity.org/benchmark/kubernetes/'
stigid: 'https://public.cyber.mil/stigs/downloads/?_dl_facet_stigs=container-platform'

cpes_root: "../../shared/applicability"
cpes:
- ocp4:
name: "cpe:/a:redhat:openshift_container_platform:4.1"
title: "Red Hat OpenShift Container Platform 4"
check_id: installed_app_is_ocp4

- ocp4-node:
name: "cpe:/o:redhat:openshift_container_platform_node:4"
title: "Red Hat OpenShift Container Platform 4 Node"
check_id: installed_app_is_ocp4_node

- ocp4-node-on-ovn:
name: "cpe:/a:redhat:openshift_container_platform_node_on_ovn:4"
title: "Red Hat OpenShift Container Platform 4 Node on OVN"
check_id: installed_app_is_ocp4_node_on_openshift-ovn

- ocp4-node-on-sdn:
name: "cpe:/a:redhat:openshift_container_platform_node_on_sdn:4"
title: "Red Hat OpenShift Container Platform 4 Node on SDN"
check_id: installed_app_is_ocp4_node_on_openshift-sdn

- ocp4.6:
name: "cpe:/a:redhat:openshift_container_platform:4.6"
title: "Red Hat OpenShift Container Platform 4.6"
check_id: installed_app_is_ocp4_6

- ocp4.7:
name: "cpe:/a:redhat:openshift_container_platform:4.7"
title: "Red Hat OpenShift Container Platform 4.7"
check_id: installed_app_is_ocp4_7

- ocp4.8:
name: "cpe:/a:redhat:openshift_container_platform:4.8"
title: "Red Hat OpenShift Container Platform 4.8"
check_id: installed_app_is_ocp4_8

- ocp4.9:
name: "cpe:/a:redhat:openshift_container_platform:4.9"
title: "Red Hat OpenShift Container Platform 4.9"
check_id: installed_app_is_ocp4_9

- ocp4.10:
name: "cpe:/a:redhat:openshift_container_platform:4.10"
title: "Red Hat OpenShift Container Platform 4.10"
check_id: installed_app_is_ocp4_10

- ocp4.11:
name: "cpe:/a:redhat:openshift_container_platform:4.11"
title: "Red Hat OpenShift Container Platform 4.11"
check_id: installed_app_is_ocp4_11

- ocp4.12:
name: "cpe:/a:redhat:openshift_container_platform:4.12"
title: "Red Hat OpenShift Container Platform 4.12"
check_id: installed_app_is_ocp4_12

- ocp4.13:
name: "cpe:/a:redhat:openshift_container_platform:4.13"
title: "Red Hat OpenShift Container Platform 4.13"
check_id: installed_app_is_ocp4_13

- ocp4.14:
name: "cpe:/a:redhat:openshift_container_platform:4.14"
title: "Red Hat OpenShift Container Platform 4.14"
check_id: installed_app_is_ocp4_14

- ocp4.15:
name: "cpe:/a:redhat:openshift_container_platform:4.15"
title: "Red Hat OpenShift Container Platform 4.15"
check_id: installed_app_is_ocp4_15

- ocp4.16:
name: "cpe:/a:redhat:openshift_container_platform:4.16"
title: "Red Hat OpenShift Container Platform 4.16"
check_id: installed_app_is_ocp4_16

- ocp4.17:
name: "cpe:/a:redhat:openshift_container_platform:4.17"
title: "Red Hat OpenShift Container Platform 4.17"
check_id: installed_app_is_ocp4_17

- ocp4.18:
name: "cpe:/a:redhat:openshift_container_platform:4.18"
title: "Red Hat OpenShift Container Platform 4.18"
check_id: installed_app_is_ocp4_18

- ocp4-on-aws:
name: "cpe:/a:redhat:openshift_container_platform_on_aws:4"
title: "Red Hat OpenShift Container Platform 4 on AWS"
check_id: installed_app_is_ocp4_on_aws

- ocp4-on-azure:
name: "cpe:/a:redhat:openshift_container_platform_on_azure:4"
title: "Red Hat OpenShift Container Platform 4 on Azure"
check_id: installed_app_is_ocp4_on_azure

- ocp4-on-gcp:
name: "cpe:/a:redhat:openshift_container_platform_on_gcp:4"
title: "Red Hat OpenShift Container Platform 4 on GCP"
check_id: installed_app_is_ocp4_on_gcp

- ocp4-on-ovn:
name: "cpe:/a:redhat:openshift_container_platform_on_ovn:4"
title: "Red Hat OpenShift Container Platform 4 on OVN"
check_id: installed_app_is_ocp4_on_openshiftovn

- ocp4-on-sdn:
name: "cpe:/a:redhat:openshift_container_platform_on_sdn:4"
title: "Red Hat OpenShift Container Platform 4 on SDN"
check_id: installed_app_is_ocp4_on_openshiftsdn


# Requirement string, see: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#requirements-parsing
# requires: "openscap>=1.3.4"
53 changes: 53 additions & 0 deletions tests/trestlebot/cli/test_sync_cac_content_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,20 @@
from click.testing import CliRunner
from git import Repo

from tests.testutils import setup_for_catalog, setup_for_profile
from trestlebot.cli.commands.sync_cac_content import sync_cac_content_cmd


test_product = "ocp4"
cac_content_test_data = pathlib.Path("tests/data/content").resolve()
test_prof_path = pathlib.Path("tests/data/json/").resolve()
test_prof = "simplified_nist_profile"
test_cat = "simplified_nist_catalog"
test_comp_path = {
"component-definitions",
"cac-components",
"component-definition.json",
}


def test_missing_required_option(tmp_repo: Tuple[str, Repo]) -> None:
Expand All @@ -37,3 +47,46 @@ def test_missing_required_option(tmp_repo: Tuple[str, Repo]) -> None:
],
)
assert result.exit_code == 2


def test_sync_product_name(tmp_repo: Tuple[str, Repo]) -> None:
"""Tests sync Cac content product name to OSCAL component title ."""
repo_dir, _ = tmp_repo
repo_path = pathlib.Path(repo_dir)
setup_for_catalog(repo_path, test_cat, "catalog")
setup_for_profile(repo_path, test_prof, "profile")

runner = CliRunner()
result = runner.invoke(
sync_cac_content_cmd,
[
"--product",
test_product,
"--repo-path",
str(repo_path.resolve()),
"--cac-content-root",
cac_content_test_data,
"--cac-profile",
"cac-profile",
"--oscal-profile",
test_prof,
"--committer-email",
"test@email.com",
"--committer-name",
"test name",
"--markdown-dir",
"markdown",
"--branch",
"test",
"--dry-run",
],
)
# Check the CLI sync-cac-content is successful
assert result.exit_code == 0
# Check if the component definition is created
component_definition = repo_path.joinpath(next(iter(test_comp_path)))
assert component_definition.exists()
# Check if it populates the product name as the component title
with open(component_definition, "r", encoding="utf-8") as file:
content = file.read()
assert '"title": "ocp4"' in content

0 comments on commit 0b7c587

Please sign in to comment.