Debian Codegraph @

tests/API/XCCDF/unittests/test_xccdf_oval_absolute_path.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2 . $builddir/tests/test_common.sh
3
4 # Test loading of OVAL results files located referenced absolutely
5
6 set -e
7 set -o pipefail
8
9 # cd to directory and run test
10 function testInDirectory(){
11 local directory="$1"
12 local xccdf="$2"
13
14 pushd "$directory"
15
16 local result=$(make_temp_file /tmp ${name}.out.result)
17 local report=$(make_temp_file /tmp ${name}.out.report)
18 local stderr=$(make_temp_file /tmp ${name}.err)
19
20 echo "Stderr file = $stderr"
21 echo "Result file = $result"
22 echo "Report file = $report"
23
24 $OSCAP xccdf eval --oval-results --results $result --report $report "$xccdf" 2> $stderr
25
26 # Check existence of oval-results
27 [ -f $directory/*oval*always-fail*oval.xml.result.xml ]
28
29 [ -f $stderr ]; [ ! -s $stderr ]; rm $stderr
30
31 # Check result
32 assert_exists 2 '//rule-result/result'
33 assert_exists 2 '//rule-result/result[text()="pass" or text()="fail"]'
34
35 # Check report
36 grep "Testing permissions on /not_executable" "$report" --quiet
37
38 rm -f $result $report
39
40 popd
41 }
42
43 name=$(basename $0 .sh)
44 ORIGINAL_XCCDF="$(readlink -f "$srcdir/${name}.xccdf.xml")"
45
46 ### test in XCCDF's directory
47
48 # We don't have write access to directory with XCCDF (after make distcheck),
49 # so we have to copy required files to directory with right access and do tests there
50
51 # there are two possible ways to define absolute path
52 # simple abs path /a/b/c
53 for prefix in "" "file://";do
54 testDir=$(make_temp_dir /tmp tmp)
55 mkdir -p "$testDir/oval/always-fail"
56
57 cp "$ORIGINAL_XCCDF" "$srcdir/test_default_selector.oval.xml" "$testDir"
58 cp "$srcdir/oval/always-fail/oval.xml" "$testDir/oval/always-fail"
59 XCCDF="$(readlink -f "$testDir/${name}.xccdf.xml")"
60 xsed -i "s|%%TEST_DIR_PATH%%|${prefix}${testDir}|" $XCCDF
61
62 testInDirectory "$testDir" "$XCCDF"
63 rm -rf "$testDir"
64 done