-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10048 from jan-cerny/refactor_build_ovals
Refactor ssg.build_ovals module
- Loading branch information
Showing
8 changed files
with
352 additions
and
105 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import pytest | ||
import tempfile | ||
import xml.etree.ElementTree as ET | ||
|
||
import ssg.build_ovals | ||
|
||
PROJECT_ROOT = os.path.join(os.path.dirname(__file__), "..", "..", "..", ) | ||
DATADIR = os.path.abspath( | ||
os.path.join(os.path.dirname(__file__), "test_build_ovals_data")) | ||
PRODUCT_YAML = os.path.join(DATADIR, "product.yml") | ||
SHARED_OVALS = os.path.join(DATADIR, "shared_ovals") | ||
BUILD_OVALS_DIR = tempfile.mkdtemp() | ||
|
||
shared_oval_1_def_tag = '<definition class="compliance" ' \ | ||
'id="tmux_conf_readable_by_others" version="1">' | ||
benchmark_oval_1_def_tag = '<definition class="compliance" ' \ | ||
'id="selinux_state" version="1">' | ||
|
||
|
||
def test_build_ovals(): | ||
env_yaml = { | ||
"product": "rhel9", | ||
"target_oval_version_str": "5.11", | ||
} | ||
obuilder = ssg.build_ovals.OVALBuilder( | ||
env_yaml, PRODUCT_YAML, [SHARED_OVALS], BUILD_OVALS_DIR) | ||
shorthand = obuilder.build_shorthand(include_benchmark=False) | ||
assert shared_oval_1_def_tag in shorthand | ||
assert benchmark_oval_1_def_tag not in shorthand | ||
|
||
|
||
def test_build_ovals_include_benchmark(): | ||
env_yaml = { | ||
"benchmark_root": "./guide", | ||
"product": "rhel9", | ||
"target_oval_version_str": "5.11", | ||
} | ||
obuilder = ssg.build_ovals.OVALBuilder( | ||
env_yaml, PRODUCT_YAML, [SHARED_OVALS], BUILD_OVALS_DIR) | ||
shorthand = obuilder.build_shorthand(include_benchmark=True) | ||
assert shared_oval_1_def_tag in shorthand | ||
assert benchmark_oval_1_def_tag in shorthand |
27 changes: 27 additions & 0 deletions
27
tests/unit/ssg-module/test_build_ovals_data/guide/selinux_state/oval/shared.xml
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,27 @@ | ||
<def-group> | ||
<definition class="compliance" id="selinux_state" version="1"> | ||
{{{ oval_metadata("The SELinux state should be enforcing the local policy.") }}} | ||
<criteria operator="AND"> | ||
<criterion comment="enforce is disabled" test_ref="test_etc_selinux_config" /> | ||
</criteria> | ||
</definition> | ||
|
||
<ind:textfilecontent54_test check="all" check_existence="all_exist" | ||
comment="/selinux/enforce is 1" id="test_etc_selinux_config" version="1"> | ||
<ind:object object_ref="object_etc_selinux_config" /> | ||
<ind:state state_ref="state_etc_selinux_config" /> | ||
</ind:textfilecontent54_test> | ||
|
||
<ind:textfilecontent54_object id="object_etc_selinux_config" version="1"> | ||
<ind:filepath>/etc/selinux/config</ind:filepath> | ||
<ind:pattern operation="pattern match">^SELINUX=(.*)$</ind:pattern> | ||
<ind:instance datatype="int">1</ind:instance> | ||
</ind:textfilecontent54_object> | ||
|
||
<ind:textfilecontent54_state id="state_etc_selinux_config" version="1"> | ||
<ind:subexpression datatype="string" operation="equals" var_check="all" var_ref="var_selinux_state" /> | ||
</ind:textfilecontent54_state> | ||
|
||
<external_variable comment="external variable for selinux state" | ||
datatype="string" id="var_selinux_state" version="1" /> | ||
</def-group> |
Oops, something went wrong.