Debian Codegraph @

tests/API/XCCDF/unittests/test_xccdf_oval_relative_path.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/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 testInDirectoryscip-shell shell shell-project 0.0.0 testInDirectory().(){
11 local directory="$1"
12 local xccdf="$2"
13
14 pushd "$directory"
15
16 local result=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.out.result)
17 local report=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.out.report)
18 local stderr=$(make_temp_file /tmpscip-shell filesystem . . `/tmp`. ${name}.err)
19
20 echoscip-shell system . . echo. "Stderr file = $stderr"
21 echoscip-shell system . . echo. "Result file = $result"
22 echoscip-shell system . . 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 [scip-shell system . . `[`. -f $directory/*oval*always-fail*oval.xml.result.xml ]
28
29 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . 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 grepscip-shell system . . grep. "Testing permissions on /not_executable" "$report" --quiet
37
38 rmscip-shell system . . rm. -f $result $report
39
40 popd
41 }
42
43 name=$(basenamescip-shell system . . basename. $0 .sh)
44 ORIGINAL_XCCDF="$(readlinkscip-shell system . . 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 /tmpscip-shell filesystem . . `/tmp`. tmp)
51 mkdirscip-shell system . . mkdir. -p "$testDir/oval/always-fail"
52 cpscip-shell system . . cp. "$ORIGINAL_XCCDF" "$srcdir/test_default_selector.oval.xml" "$testDir"
53 cpscip-shell system . . cp. "$srcdir/oval/always-fail/oval.xml" "$testDir/oval/always-fail"
54
55 XCCDF="$(readlinkscip-shell system . . readlink. -f "$testDir/${name}.xccdf.xml")"
56 testInDirectoryscip-shell shell shell-project 0.0.0 testInDirectory(). "$testDir" "$XCCDF"
57 rmscip-shell system . . rm. -rf "$testDir"
58
59
60 ### test in random directory - different from directory of XCCDF
61 RANDOM_DIRECTORY=`mktempscip-shell system . . mktemp. -d`
62 testInDirectoryscip-shell shell shell-project 0.0.0 testInDirectory(). "$RANDOM_DIRECTORY" "$ORIGINAL_XCCDF"
63 rmscip-shell system . . rm. -rf $RANDOM_DIRECTORY