Debian Codegraph @

tests/API/XCCDF/unittests/test_xccdf_oval_relative_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 relatively to XCCDF file
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 testDir=$(make_temp_dir /tmp tmp)
51 mkdir -p "$testDir/oval/always-fail"
52 cp "$ORIGINAL_XCCDF" "$srcdir/test_default_selector.oval.xml" "$testDir"
53 cp "$srcdir/oval/always-fail/oval.xml" "$testDir/oval/always-fail"
54
55 XCCDF="$(readlink -f "$testDir/${name}.xccdf.xml")"
56 testInDirectory "$testDir" "$XCCDF"
57 rm -rf "$testDir"
58
59
60 ### test in random directory - different from directory of XCCDF
61 RANDOM_DIRECTORY=`mktemp -d`
62 testInDirectory "$RANDOM_DIRECTORY" "$ORIGINAL_XCCDF"
63 rm -rf $RANDOM_DIRECTORY