Skip to content

Commit

Permalink
Merge pull request OpenSCAP#1441 from evgenyz/test_offline_remediations
Browse files Browse the repository at this point in the history
Add test that ensures there is no remediation attempt in the "offline" mode
  • Loading branch information
jan-cerny authored Jan 3, 2020
2 parents 936a806 + 1191724 commit 02c7831
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/API/XCCDF/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_oscap_test("test_xccdf_transformation.sh")
add_oscap_test("test_single_rule.sh")
add_oscap_test("test_single_rule_stigw.sh")
add_oscap_test("test_remediation_simple.sh")
add_oscap_test("test_remediation_offline.sh")
add_oscap_test("test_remediation_metadata.sh")
add_oscap_test("test_remediation_bad_fix.sh")
add_oscap_test("test_remediation_subs_plain_text.sh")
Expand Down
21 changes: 21 additions & 0 deletions tests/API/XCCDF/unittests/test_remediation_offline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
. $builddir/tests/test_common.sh

set -e -o pipefail

name=$(basename $0 .sh)
result=$(mktemp -t ${name}.res.XXXXXX)
stderr=$(mktemp -t ${name}.err.XXXXXX)
stdout=$(mktemp -t ${name}.out.XXXXXX)
root=$(mktemp -d -t ${name}.root.XXXXXX)

set_chroot_offline_test_mode "$root"

$OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr 1> $stdout || echo "Scanner returned non-zero code (OK)"
rm $result

grep "remediation in offline mode: not implemented" $stderr > /dev/null

rm -rf $stderr $stdout $root

unset_chroot_offline_test_mode
15 changes: 15 additions & 0 deletions tests/API/XCCDF/unittests/test_remediation_offline.xccdf.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_moc.elpmaxe.www_benchmark_test">
<status>accepted</status>
<version>1.0</version>
<Rule selected="true" id="xccdf_moc.elpmaxe.www_rule_1">
<title>Ensure that file exists and it is not executable</title>
<fix system="urn:xccdf:fix:script:sh">
touch test_file
chmod a-x test_file
</fix>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref href="test_remediation_simple.oval.xml" name="oval:moc.elpmaxe.www:def:1"/>
</check>
</Rule>
</Benchmark>

0 comments on commit 02c7831

Please sign in to comment.