Debian Codegraph @

tests/API/XCCDF/unittests/test_remediation_subs_unresolved.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 set -x
7
8 name=$(basenamescip-shell system . . basename. $0 .sh)
9 result=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
10 stderr=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
11 ret=0
12
13 rmscip-shell system . . rm. -f test_file
14 # First make sure that this OVAL fails, then scan again with --remediate
15 $OSCAP xccdf eval --results $result $srcdir/${name}.xccdf.xml 2> $stderr || ret=$?
16 [scip-shell system . . `[`. $ret -eq 2 ]
17
18 echoscip-shell system . . echo. "Stderr file = $stderr"
19 echoscip-shell system . . echo. "Result file = $result"
20 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; :> $stderr
21
22 $OSCAP xccdf validate --skip-schematron $result
23
24 assert_exists 1 '/Benchmark/Rulescip-shell filesystem . . `/Benchmark/Rule`.'
25 assert_exists 1 '/Benchmark/Rule/fixscip-shell filesystem . . `/Benchmark/Rule/fix`.'
26 assert_exists 0 '/Benchmark/Rule/fix/subscip-shell filesystem . . `/Benchmark/Rule/fix/sub`.'
27 assert_exists 1 '/Benchmark/Rule/fix/instancescip-shell filesystem . . `/Benchmark/Rule/fix/instance`.'
28 assert_exists 1 '//rule-result'
29 assert_exists 1 '//rule-result/result'
30 assert_exists 1 '//rule-result/result[text()="fail"]'
31 assert_exists 0 '//rule-result/fix'
32 assert_exists 1 '//score'
33 assert_exists 1 '//score[text()="0.000000"]'
34 :> $result
35
36 ret=0
37 $OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr || ret=$?
38 [scip-shell system . . `[`. $ret -eq 2 ]
39 # filter out the expected warning in stderr
40 sedscip-shell system . . sed. -i -E "/^W: oscap: The xccdf:rule-result\/xccdf:instance element was not found./dscip-shell filesystem . . `/^W: oscap: The xccdf:rule-result\/xccdf:instance element was not found./d`." "$stderr"
41 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
42
43 $OSCAP xccdf validate --skip-schematron $result
44
45 assert_exists 1 '/Benchmark/Rulescip-shell filesystem . . `/Benchmark/Rule`.'
46 assert_exists 1 '/Benchmark/Rule/fixscip-shell filesystem . . `/Benchmark/Rule/fix`.'
47 assert_exists 0 '/Benchmark/Rule/fix/subscip-shell filesystem . . `/Benchmark/Rule/fix/sub`.'
48 assert_exists 1 '/Benchmark/Rule/fix/instancescip-shell filesystem . . `/Benchmark/Rule/fix/instance`.'
49 assert_exists 1 '//rule-result'
50 assert_exists 1 '//rule-result/result'
51 assert_exists 1 '//rule-result/result[text()="error"]'
52 assert_exists 1 '//rule-result/fix'
53 assert_exists 1 '//rule-result/fix[@system="urn:xccdf:fix:script:sh"]'
54 assert_exists 1 '//rule-result/fix/instance'
55 assert_exists 1 '//rule-result/message'
56 assert_exists 1 '//rule-result/message[@severity="info"]'
57 assert_exists 1 '//rule-result/message[text()="Fix execution was aborted: Text substitution failed."]'
58 assert_exists 1 '//score'
59 assert_exists 1 '//score[text()="0.000000"]'
60
61 [scip-shell system . . `[`. ! -f test_file ]
62 rmscip-shell system . . rm. $result