Compare commits

...
Author SHA1 Message Date
chainsx a2250c56a4 fix(security): correct openscap cis eval and fix test execution 2026-09-17 05:33:35 +08:00
4 changed files with 18 additions and 16 deletions
@@ -1,10 +1,11 @@
summary: Security test - OpenSCAP CIS - andreport
framework: beakerlib
test: ./test.sh
tag:
- security
- openscap
- cis
duration: 10m
duration: 30m
tier: 2
path: /tests/security/openscap/cis/test_openscap_cis_eval_report
require:
@@ -16,21 +16,21 @@ rlJournalStart
if [ ! -f "$CIS_DS" ]; then
rlFail "Data stream not found"
else
local out=/tmp/cis_eval_$$
local xml=/tmp/cis_result_$$.xml
local html=/tmp/cis_report_$$.html
out=/tmp/cis_eval_$$
xml=/tmp/cis_result_$$.xml
html=/tmp/cis_report_$$.html
oscap xccdf eval --profile "$CIS_PROFILE" --results-arf "$xml" --report "$html" "$CIS_DS" 2>&1 | tee $out
local rc=${PIPESTATUS[0]}
if [ $rc -ne 0 ]; then
rc=${PIPESTATUS[0]}
if [ $rc -ne 0 ] && [ $rc -ne 2 ]; then
rlFail "oscap eval failed (exit=$rc)"
elif [ ! -f "$xml" ]; then
rlFail "ARF result file not generated"
elif [ ! -f "$html" ]; then
rlFail "HTML report not generated"
else
local pass=$(grep -c '<result>pass</result>' "$xml" 2>/dev/null || echo 0)
local fail=$(grep -c '<result>fail</result>' "$xml" 2>/dev/null || echo 0)
local na=$(grep -c '<result>notapplicable</result>' "$xml" 2>/dev/null || echo 0)
pass=$(grep -c '<result>pass</result>' "$xml" 2>/dev/null || echo 0)
fail=$(grep -c '<result>fail</result>' "$xml" 2>/dev/null || echo 0)
na=$(grep -c '<result>notapplicable</result>' "$xml" 2>/dev/null || echo 0)
rlPass "CIS eval complete: pass=$pass fail=$fail notapplicable=$na"
fi
rm -f $out $xml $html
@@ -1,10 +1,11 @@
summary: Security test - OpenSCAP CIS - scriptGenerate
framework: beakerlib
test: ./test.sh
tag:
- security
- openscap
- cis
duration: 10m
duration: 30m
tier: 2
path: /tests/security/openscap/cis/test_openscap_cis_fix
require:
@@ -16,15 +16,15 @@ rlJournalStart
if [ ! -f "$CIS_DS" ]; then
rlFail "Data stream not found"
else
local out=/tmp/cis_fix_$$
local xml=/tmp/cis_fix_xml_$$.xml
local fix=/tmp/cis_fix_$$.sh
out=/tmp/cis_fix_$$
xml=/tmp/cis_fix_xml_$$.xml
fix=/tmp/cis_fix_$$.sh
oscap xccdf eval --profile "$CIS_PROFILE" --results "$xml" "$CIS_DS" 2>&1 | tee $out
local rc=${PIPESTATUS[0]}
if [ $rc -ne 0 ] || [ ! -f "$xml" ]; then
rc=${PIPESTATUS[0]}
if { [ $rc -ne 0 ] && [ $rc -ne 2 ]; } || [ ! -f "$xml" ]; then
rlFail "oscap eval failed (exit=$rc)"
else
local rid=$(grep -oP 'id="\K[^"]+' "$xml" | head -1)
rid=$(grep -oP '<TestResult[^>]*\bid="\K[^"]+' "$xml" | head -1)
if [ -z "$rid" ]; then
rlFail "Cannot extract TestResult id"
else