Debian Codegraph @

tests/API/XCCDF/unittests/test_remediation_subs_value_take_first.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 '//Value'
24 assert_exists 3 '//Value/value'
25 assert_exists 0 '//Value/value[not(@selector)]'
26 assert_exists 1 '/Benchmark/Rulescip-shell filesystem . . `/Benchmark/Rule`.'
27 assert_exists 1 '/Benchmark/Rule/fixscip-shell filesystem . . `/Benchmark/Rule/fix`.'
28 assert_exists 2 '/Benchmark/Rule/fix/subscip-shell filesystem . . `/Benchmark/Rule/fix/sub`.'
29 assert_exists 1 '//rule-result'
30 assert_exists 1 '//rule-result/result'
31 assert_exists 1 '//rule-result/result[text()="fail"]'
32 assert_exists 0 '//rule-result/fix'
33 assert_exists 1 '//score'
34 assert_exists 1 '//score[text()="0.000000"]'
35 :> $result
36
37 $OSCAP xccdf eval --remediate --results $result $srcdir/${name}.xccdf.xml 2> $stderr
38 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
39
40 $OSCAP xccdf validate --skip-schematron $result
41
42 assert_exists 1 '//Value'
43 assert_exists 3 '//Value/value'
44 assert_exists 0 '//Value/value[not(@selector)]'
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 2 '/Benchmark/Rule/fix/subscip-shell filesystem . . `/Benchmark/Rule/fix/sub`.'
48 assert_exists 1 '//TestResult'
49 assert_exists 0 '//TestResult/profile'
50 assert_exists 1 '//rule-result'
51 assert_exists 1 '//rule-result/result'
52 assert_exists 1 '//rule-result/result[text()="fixed"]'
53 assert_exists 1 '//rule-result/fix'
54 assert_exists 1 '//rule-result/fix[@system="urn:xccdf:fix:script:sh"]'
55 assert_exists 1 '//rule-result/fix[contains(text(), "touch test_file")]'
56 assert_exists 1 '//rule-result/fix[contains(text(), "chmod a-x test_file")]'
57 assert_exists 0 '//rule-result/fix/sub'
58 assert_exists 1 '//rule-result/message'
59 assert_exists 1 '//rule-result/message[@severity="info"]'
60 assert_exists 1 '//rule-result/message[text()="Fix execution completed and returned: 0"]'
61 assert_exists 1 '//score'
62 assert_exists 1 '//score[text()="100.000000"]'
63
64 rmscip-shell system . . rm. test_file
65 rmscip-shell system . . rm. $result