Skip to content

Commit

Permalink
Merge pull request OpenSCAP#1730 from evgenyz/schematron-default
Browse files Browse the repository at this point in the history
utils: Make schematron-based validation enabled by default for validate command of oval and xccdf modules
  • Loading branch information
jan-cerny authored Apr 15, 2021
2 parents 4bdb5ba + e17cb56 commit f4b4975
Show file tree
Hide file tree
Showing 65 changed files with 145 additions and 146 deletions.
6 changes: 3 additions & 3 deletions dist/bash_completion.d/oscap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# returns number of params
function _oscap_noarg {
case "$1" in
--definitions|--syschar|--results|--schematron|-f|--force|-q|--quiet|--oval-results) return 0 ;;
--definitions|--syschar|--results|--skip-schematron|-f|--force|-q|--quiet|--oval-results) return 0 ;;
--version|--help|-V|-h) return 256 ;; # stop cmdline processing
*) return 1 ;;
esac
Expand All @@ -26,13 +26,13 @@ function _oscap {
# command options
local -A opts=()
opts[oscap]="--version --quiet --help -V -q -h"
opts[oscap:oval:validate]="--version --definitions --variables --syschar --results --directives --schematron"
opts[oscap:oval:validate]="--version --definitions --variables --syschar --results --directives --skip-schematron"
opts[oscap:oval:eval]="--datastream-id --oval-id --id --variables --directives --without-syschar --results --report --skip-valid --skip-validation --fetch-remote-resources --verbose --verbose-log-file"
opts[oscap:oval:analyse]="--variables --directives --verbose --verbose-log-file --skip-valid --skip-validation"
opts[oscap:oval:collect]="--id --syschar --skip-valid --skip-validation --variables --verbose --verbose-log-file"
opts[oscap:oval:generate:report]="-o --output"
opts[oscap:xccdf:eval]="--benchmark-id --check-engine-results --cpe --datastream-id --enforce-signature --export-variables --fetch-remote-resources --oval-results --profile --progress --remediate --report --results --results-arf --rule --skip-valid --skip-validation --skip-signature-validation --stig-viewer --tailoring-file --tailoring-id --thin-results --verbose --verbose-log-file --without-syschar --xccdf-id"
opts[oscap:xccdf:validate]="--schematron"
opts[oscap:xccdf:validate]="--skip-schematron"
opts[oscap:xccdf:export-oval-variables]="--datastream-id --xccdf-id --profile --skip-valid --skip-validation --fetch-remote-resources --cpe"
opts[oscap:xccdf:remediate]="--result-id --skip-valid --skip-validation --fetch-remote-resources --results --results-arf --report --oval-results --export-variables --cpe --check-engine-results --progress"
opts[oscap:xccdf:resolve]="-o --output -f --force"
Expand Down
18 changes: 12 additions & 6 deletions docs/manual/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -915,20 +915,26 @@ $ oscap ds sds-validate scap-ds.xml
NOTE: Note that all SCAP components within the given data stream are validated
automatically and none of the components is specified separately.

You can also enable extra Schematron-based validation if you validate OVAL
specification. This validation method is slower but it provides deeper analysis.
Run the following command to validate an OVAL document using Schematron:
There is an extra Schematron-based validation enabled when you validate OVAL or
XCCDF specification. This validation method is slower but it provides deeper analysis.

Run one of the following commands to validate an OVAL or XCCDF document without
Schematron checks:

----
$ oscap xccdf validate --skip-schematron xccdf-file.xml
----

----
$ oscap oval validate --schematron oval-file.xml
$ oscap oval validate --skip-schematron oval-file.xml
----

The results of validation are printed to standard error stream (stderr).

NOTE: Please note that for the rest of `oscap` functionality, unless you specify
--skip-validation (--skip-valid), validation will automatically occur before
files are used. Therefore, you do not need to explicitly validate a datastream
before use.
files are used. Therefore, you do not need to explicitly validate a data stream
before use. Though it will not include the Schematron-based validation step.

=== Validating digital signature in SCAP source data stream

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $OSCAP xccdf remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr ||
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr
[ ! -f test_file ]

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 2 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
Expand All @@ -34,14 +34,16 @@ assert_exists 0 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profil
# one message expected signalling no suitable fix found.
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message'


#
# Second, make sure that the fix is applied, when CPE is recognized as appplicable
#
:> $result
$OSCAP xccdf remediate --cpe $srcdir/cpe-dict.xml --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr
[ -f test_file ]; rm test_file
$OSCAP xccdf validate $result

$OSCAP xccdf validate --skip-schematron $result
assert_exists 2 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $OSCAP xccdf remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr ||
[ ! -f wrong_test_file ]
[ -f test_file_cpe_na ]

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 2 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile"]'
Expand Down Expand Up @@ -54,7 +54,7 @@ $OSCAP xccdf remediate --cpe $srcdir/cpe-dict.xml --results $result $srcdir/${na
[ -f test_file ]; rm test_file
[ ! -f test_file_cpe_na ]
[ ! -f wrong_test_file ]
$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 2 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $OSCAP xccdf eval --remediate --results $resultx --results-arf $arf $sds 2> $std
[ ! -f wrong_test_file ]
[ -f test_file_cpe_na ]; rm test_file_cpe_na

$OSCAP xccdf validate $resultx
$OSCAP xccdf validate --skip-schematron $resultx
$OSCAP ds rds-validate $arf

result=$resultx
Expand Down Expand Up @@ -62,7 +62,7 @@ $OSCAP xccdf eval --cpe $srcdir/cpe-dict.xml --remediate --results $resultx --re
[ ! -f wrong_test_file ]
[ ! -f test_file_cpe_na ]

$OSCAP xccdf validate $resultx
$OSCAP xccdf validate --skip-schematron $resultx
$OSCAP ds rds-validate $arf

result=$resultx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 8 '//rule-result'
assert_exists 8 '//rule-result/result'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 2 '//rule-result'
assert_exists 2 '//rule-result/result'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 8 '//rule-result'
assert_exists 8 '//rule-result/result'
Expand Down
2 changes: 1 addition & 1 deletion tests/API/XCCDF/unittests/test_empty_variable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '//rule-result'
assert_exists 1 '//rule-result/result'
Expand Down
4 changes: 2 additions & 2 deletions tests/API/XCCDF/unittests/test_fix_instance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rm -f test_file

$OSCAP xccdf eval --results $result $srcdir/${name}.xccdf.xml 2> $stderr || ret=$?

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule/fix/instance'
assert_exists 3 '//rule-result'
Expand All @@ -27,7 +27,7 @@ rm $result

$OSCAP xccdf remediate --result-id xccdf_org.open-scap_testresult_default-profile --results $result $srcdir/${name}.xccdf.xml 2> $stderr || ret=$?

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule/fix/instance'
assert_exists 4 '//rule-result'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 8 '//rule-result'
assert_exists 8 '//rule-result/result'
Expand Down Expand Up @@ -89,7 +89,7 @@ done
rmdir $split/oval

mangle="scap_org.open-scap_cref_"
$OSCAP xccdf validate $split/${mangle}${name}.xccdf.xml 2> $stderr
$OSCAP xccdf validate --skip-schematron $split/${mangle}${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
rm $split/${mangle}${name}.xccdf.xml
rmdir $split
Expand Down
2 changes: 1 addition & 1 deletion tests/API/XCCDF/unittests/test_oval_without_definition.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Result file = $result"
[ $ret -eq 2 ]
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '//rule-result'
assert_exists 1 '//rule-result/result'
Expand Down
2 changes: 1 addition & 1 deletion tests/API/XCCDF/unittests/test_remediate_perl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rm -f test_file
$OSCAP xccdf remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
[ -f test_file ]; rm test_file
$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 2 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result'
Expand Down
2 changes: 1 addition & 1 deletion tests/API/XCCDF/unittests/test_remediate_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rm -f test_file
$OSCAP xccdf remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
[ -f test_file ]; rm test_file
$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 2 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result'
Expand Down
8 changes: 4 additions & 4 deletions tests/API/XCCDF/unittests/test_remediate_simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $OSCAP xccdf remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
daytime="$(date +%Y-%m-%d)T$(date +%H:%M)" # Format like '2013-02-27T15:01:57'
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr
[ ! -f test_file ]
$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 4 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile002001"]'
starttime=`$XPATH 'string(//TestResult[@id="xccdf_org.open-scap_testresult_default-profile002001"]/@start-time)' < $result 2>/dev/null`
Expand All @@ -59,7 +59,7 @@ $OSCAP xccdf remediate --result-id xccdf_org.open-scap_testresult_default-profil
daytime="$(date +%Y-%m-%d)T$(date +%H:%M)" # Format like '2013-02-27T15:01:57'
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr
[ ! -f test_file ]
$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 5 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile002002"]'
starttime=`$XPATH 'string(//TestResult[@id="xccdf_org.open-scap_testresult_default-profile002002"]/@start-time)' < $result 2>/dev/null`
Expand All @@ -77,7 +77,7 @@ daytime="$(date +%Y-%m-%d)T$(date +%H:%M)" # Format like '2013-02-27T15:01:57'
[ $ret -eq 2 ]
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr
[ -f test_file ]; rm test_file
$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 6 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001001"]'
starttime=`$XPATH 'string(//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001001"]/@start-time)' < $result 2>/dev/null`
Expand All @@ -97,7 +97,7 @@ $OSCAP xccdf remediate --result-id xccdf_org.open-scap_testresult_default-profil
daytime="$(date +%Y-%m-%d)T$(date +%H:%M)" # Format like '2013-02-27T15:01:57'
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
[ -f test_file ]; rm test_file
$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result
assert_exists 7 '//TestResult'
assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile003"]'
starttime=`$XPATH 'string(//TestResult[@id="xccdf_org.open-scap_testresult_default-profile003"]/@start-time)' < $result 2>/dev/null`
Expand Down
4 changes: 2 additions & 2 deletions tests/API/XCCDF/unittests/test_remediation_amp_escaping.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule'
assert_exists 1 '/Benchmark/Rule/fix'
Expand All @@ -34,7 +34,7 @@ assert_exists 1 '//score[text()="0.000000"]'
$OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule'
assert_exists 1 '/Benchmark/Rule/fix'
Expand Down
4 changes: 2 additions & 2 deletions tests/API/XCCDF/unittests/test_remediation_bad_fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '//rule-result'
assert_exists 1 '//rule-result/result'
Expand All @@ -33,7 +33,7 @@ $OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $st
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
[ ! -f test_file ]

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '//rule-result'
assert_exists 1 '//rule-result/result'
Expand Down
4 changes: 2 additions & 2 deletions tests/API/XCCDF/unittests/test_remediation_cdata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule'
assert_exists 1 '/Benchmark/Rule/fix'
Expand All @@ -34,7 +34,7 @@ assert_exists 1 '//score[text()="0.000000"]'
$OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule'
assert_exists 1 '/Benchmark/Rule/fix'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $st
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr
[ ! -f test_file ]

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '//rule-result'
assert_exists 1 '//rule-result/result'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
[ -f $result ]; [ -s $result ]

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 "//message[contains(text(),'<tag>')]"

Expand Down
4 changes: 2 additions & 2 deletions tests/API/XCCDF/unittests/test_remediation_simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '//rule-result'
assert_exists 1 '//rule-result/result'
Expand All @@ -31,7 +31,7 @@ assert_exists 1 '//score[text()="0.000000"]'
$OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '//rule-result'
assert_exists 1 '//rule-result/result'
Expand Down
4 changes: 2 additions & 2 deletions tests/API/XCCDF/unittests/test_remediation_subs_plain_text.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/plain-text'
assert_exists 1 '/Benchmark/Rule'
Expand All @@ -35,7 +35,7 @@ assert_exists 1 '//score[text()="0.000000"]'
$OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/plain-text'
assert_exists 1 '/Benchmark/Rule'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/plain-text'
assert_exists 1 '/Benchmark/Rule'
Expand All @@ -35,7 +35,7 @@ assert_exists 1 '//score[text()="0.000000"]'
$OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/plain-text'
assert_exists 1 '/Benchmark/Rule'
Expand Down
4 changes: 2 additions & 2 deletions tests/API/XCCDF/unittests/test_remediation_subs_unresolved.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ echo "Stderr file = $stderr"
echo "Result file = $result"
[ -f $stderr ]; [ ! -s $stderr ]; :> $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule'
assert_exists 1 '/Benchmark/Rule/fix'
Expand All @@ -40,7 +40,7 @@ $OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $st
sed -i -E "/^W: oscap: The xccdf:rule-result\/xccdf:instance element was not found./d" "$stderr"
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

$OSCAP xccdf validate $result
$OSCAP xccdf validate --skip-schematron $result

assert_exists 1 '/Benchmark/Rule'
assert_exists 1 '/Benchmark/Rule/fix'
Expand Down
Loading

0 comments on commit f4b4975

Please sign in to comment.