Debian Codegraph @

tests/nist/nist_test.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # OpenSCAP test suite
4 # Tests a subset of NIST validation requirements
5 # Author:
6 # Jan Černý <[email protected]>
7
8 . $builddir/tests/test_common.sh
9
10 set -e -o pipefail
11
12 function test_nist {
13 test_dir="$1"
14 # make sure the output dir in builddir exists
15 mkdir -p "${builddir}/tests/nist/$test_dir/"
16 (
17 # workaround for OVAL 5.4 issue where var_ref regex pattern is too
18 # strict and doesnt allow numbers or underscores
19 if [ "x$test_dir" == "xR1100" ]; then
20 unset OSCAP_FULL_VALIDATION
21 fi
22 # workaround for missing idref in <platform> in an internally used
23 # XCCDF. this XCCDF is never exported and only used internally.
24 if [ "x$test_dir" == "xR1200" ]; then
25 unset OSCAP_FULL_VALIDATION
26 fi
27 "$PREFERRED_PYTHON" "${srcdir}/test_worker.py" --scanner "$OSCAP" --outputdir "${builddir}/tests/nist/$test_dir/" "${srcdir}/$test_dir/"
28 )
29 ret_val=$?
30 if [ $ret_val -eq 1 ]; then
31 return 1
32 fi
33 }
34
35 function test_results_directive {
36 test_dir="$1"
37 # make sure the output dir in builddir exists
38 mkdir -p "${builddir}/tests/nist/$test_dir/"
39
40 # Parameters of datastream used for evaluation
41 local datastream="ind_family_test-datastream.xml"
42 local profile="xccdf_gov.nist_profile_family-validation"
43 local n_rules=9
44 local n_tests=8
45
46 local result="${builddir}/tests/nist/${test_dir}/results_directive.results_arf.xml"
47 # the tests of this evaluation dont need to pass, return true
48 $OSCAP xccdf eval --profile ${profile} --results-arf ${result} "${srcdir}/$test_dir/${datastream}" > /dev/null || true
49
50 assert_exists 1 '//collected_objects'
51 assert_exists 1 '//system_data'
52 assert_exists ${n_tests} '//tests/test/tested_item'
53 assert_exists ${n_rules} '//results/system/definitions/definition/criteria'
54 if grep -q 'content="full"' ${result}; then
55 echo "ARF results for Single Machine with System Characteristics: PASS"
56 else
57 echo "ARF results for Single Machine with System Characteristics: FAIL"
58 return 1
59 fi
60
61 local result="${builddir}/tests/nist/${test_dir}/without-syschar-results_directive.results_arf.xml"
62 # the tests of this evaluation dont need to pass, return true
63 $OSCAP xccdf eval --profile ${profile} --without-syschar --results-arf ${result} "${srcdir}/$test_dir/${datastream}" > /dev/null || true
64
65 assert_exists 0 '//collected_objects'
66 assert_exists 0 '//system_data'
67 assert_exists ${n_tests} '//tests/test/tested_item'
68 assert_exists ${n_rules} '//results/system/definitions/definition/criteria'
69 if grep -q 'content="full"' ${result}; then
70 echo "ARF results for Single Machine without System Characteristics: PASS"
71 else
72 echo "ARF results for Single Machine without System Characteristics: FAIL"
73 return 1
74 fi
75
76 local result="${builddir}/tests/nist/${test_dir}/thin-results-results_directive.results_arf.xml"
77 # the tests of this evaluation dont need to pass, return true
78 $OSCAP xccdf eval --profile ${profile} --thin-results --results-arf ${result} "${srcdir}/$test_dir/${datastream}" > /dev/null || true
79
80 assert_exists 0 '//collected_objects'
81 assert_exists 0 '//system_data'
82 assert_exists 0 '//tests/test'
83 assert_exists 0 '//tests/test/tested_item'
84 assert_exists ${n_rules} '//results/system/definitions/definition'
85 assert_exists 0 '//results/system/definitions/definition/criteria'
86 if grep -q 'content="thin"' ${result}; then
87 echo "ARF results for Single Machine with Thin Results: PASS"
88 else
89 echo "ARF results for Single Machine with Thin Results: FAIL"
90 return 1
91 fi
92 }
93
94 # Testing
95 test_init "nist_test.log"
96 test_run "ind_family_test" test_nist "ind_family_test"
97 test_run "ind_unknown_test" test_nist "ind_unknown_test"
98 test_run "ind_variable_test" test_nist "ind_variable_test"
99 test_run "R500" test_nist "R500"
100 test_run "R600" test_nist "R600"
101 test_run "R1100" test_nist "R1100"
102 test_run "R1200" test_nist "R1200"
103 test_run "R2000" test_results_directive "R2000"
104 test_run "R2920" test_nist "R2940"
105 test_run "R3005" test_nist "R3005"
106 test_run "R3010" test_nist "R3010"
107 test_run "R3300" test_nist "R3300"
108 test_exit
109