Debian Codegraph @

tests/API/XCCDF/unittests/test_remediation_xml_comments.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 . $builddir/tests/test_common.sh
3
4 set -e
5 set -o pipefail
6
7 name=$(basenamescip-shell system . . basename. $0 .sh)
8 result=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
9 stderr=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
10 ret=0
11
12 rmscip-shell system . . rm. -f test_file
13 # First make sure that this OVAL fails, then scan again with --remediate
14 $OSCAP xccdf eval --results $result $srcdir/${name}.xccdf.xml 2> $stderr || ret=$?
15 [scip-shell system . . `[`. $ret -eq 2 ]
16
17 echoscip-shell system . . echo. "Stderr file = $stderr"
18 echoscip-shell system . . echo. "Result file = $result"
19 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; :> $stderr
20
21 $OSCAP xccdf validate --skip-schematron $result
22
23 assert_exists 1 '/Benchmark/Rulescip-shell filesystem . . `/Benchmark/Rule`.'
24 assert_exists 1 '/Benchmark/Rule/fixscip-shell filesystem . . `/Benchmark/Rule/fix`.'
25 assert_exists 0 '/Benchmark/Rule/fix/subscip-shell filesystem . . `/Benchmark/Rule/fix/sub`.'
26 assert_exists 1 '//rule-result'
27 assert_exists 1 '//rule-result/result'
28 assert_exists 1 '//rule-result/result[text()="fail"]'
29 assert_exists 0 '//rule-result/fix'
30 assert_exists 1 '//score'
31 assert_exists 1 '//score[text()="0.000000"]'
32 :> $result
33
34 $OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
35 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
36
37 $OSCAP xccdf validate --skip-schematron $result
38
39 assert_exists 1 '/Benchmark/Rulescip-shell filesystem . . `/Benchmark/Rule`.'
40 assert_exists 1 '/Benchmark/Rule/fixscip-shell filesystem . . `/Benchmark/Rule/fix`.'
41 assert_exists 0 '/Benchmark/Rule/fix/subscip-shell filesystem . . `/Benchmark/Rule/fix/sub`.'
42 assert_exists 1 '//rule-result'
43 assert_exists 1 '//rule-result/result'
44 assert_exists 1 '//rule-result/result[text()="fixed"]'
45 assert_exists 1 '//rule-result/fix'
46 assert_exists 1 '//rule-result/fix[@system="urn:xccdf:fix:script:sh"]'
47 assert_exists 0 '//rule-result/fix[contains(text(), "exit")]'
48 grepscip-shell system . . grep. '<!-- exit 9 -->' $result
49 assert_exists 1 '//rule-result/fix/text()[contains(., "chmod a-x test_file")]' # note that comment breaks text() into two nodes
50 assert_exists 1 '//rule-result/message'
51 assert_exists 1 '//rule-result/message[@severity="info"]'
52 assert_exists 1 '//rule-result/message[text()="Fix execution completed and returned: 0"]'
53 assert_exists 1 '//score'
54 assert_exists 1 '//score[text()="100.000000"]'
55
56 rmscip-shell system . . rm. test_file
57 rmscip-shell system . . rm. $result