Debian Codegraph @

tests/API/XCCDF/applicability/test_remediate_fix_processing_ds.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 sds=$srcdir/test_remediate_fix_processing.xccdf.xml
9 stderr=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.out)
10 resultx=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.xccdf)
11 arf=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.arf)
12 echoscip-shell system . . echo. "sds file: $sds"
13 echoscip-shell system . . echo. "stderr file: $stderr"
14 echoscip-shell system . . echo. "results file: $result"
15 rmscip-shell system . . rm. -f test_file test_file_cpe_na wrong_test_file
16
17 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]
18 $OSCAP ds sds-validate $sds
19
20 # First, try to apply a wrong fix due to missing CPE.
21 ret=0
22 $OSCAP xccdf eval --remediate --results $resultx --results-arf $arf $sds 2> $stderr || ret=$?
23 [scip-shell system . . `[`. $ret -eq 2 ]
24 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]
25 [scip-shell system . . `[`. ! -f test_file ]
26 [scip-shell system . . `[`. ! -f wrong_test_file ]
27 [scip-shell system . . `[`. -f test_file_cpe_na ]; rmscip-shell system . . rm. test_file_cpe_na
28
29 $OSCAP xccdf validate --skip-schematron $resultx
30 $OSCAP ds rds-validate $arf
31
32 result=$resultx
33 assert_exists 2 '//TestResult'
34 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
35 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result'
36 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result'
37 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="error"]'
38 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix'
39 assert_exists 2 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@*'
40 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@system'
41 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@system="urn:xccdf:fix:script:sh"]'
42 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@reboot'
43 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@reboot="true"]'
44 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/text()[contains(., "touch test_file_cpe_na")]'
45 assert_exists 2 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message'
46 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message[text()="Fix execution completed and returned: 0"]'
47 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message[text()="Failed to verify applied fix: Checking engine returns: fail"]'
48 result=$arf
49 assert_exists 3 '//TestResult'
50 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
51 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result'
52 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result'
53 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="error"]'
54
55 :> $result
56 :> $arf
57 $OSCAP xccdf eval --cpe $srcdir/cpe-dict.xml --remediate --results $resultx --results-arf $arf $sds 2> $stderr
58 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
59 [scip-shell system . . `[`. -f test_file ]; rmscip-shell system . . rm. test_file
60 [scip-shell system . . `[`. ! -f wrong_test_file ]
61 [scip-shell system . . `[`. ! -f test_file_cpe_na ]
62
63 $OSCAP xccdf validate --skip-schematron $resultx
64 $OSCAP ds rds-validate $arf
65
66 result=$resultx
67 assert_exists 2 '//TestResult'
68 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
69 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result'
70 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result'
71 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="fixed"]'
72 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix'
73 assert_exists 3 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@*'
74 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@system'
75 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@system="urn:xccdf:fix:script:sh"]'
76 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@disruption'
77 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@disruption="low"]'
78 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/@platform'
79 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix[@platform="cpe:/o:example:applicable:5"]'
80 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/fix/text()[contains(., "touch test_file")]'
81 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message'
82 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/message[text()="Fix execution completed and returned: 0"]'
83 result=$arf
84 assert_exists 3 '//TestResult'
85 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]'
86 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result'
87 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result'
88 assert_exists 1 '//TestResult[@id="xccdf_org.open-scap_testresult_default-profile001"]/rule-result/result[text()="fixed"]'
89
90 rmscip-shell system . . rm. $resultx $arf