Debian Codegraph @

tests/API/XCCDF/unittests/test_xccdf_oval_absolute_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 referenced absolutely
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
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 /tmpscip-shell filesystem . . `/tmp`. tmp)
55 mkdirscip-shell system . . mkdir. -p "$testDir/oval/always-fail"
56
57 cpscip-shell system . . cp. "$ORIGINAL_XCCDF" "$srcdir/test_default_selector.oval.xml" "$testDir"
58 cpscip-shell system . . cp. "$srcdir/oval/always-fail/oval.xml" "$testDir/oval/always-fail"
59 XCCDF="$(readlinkscip-shell system . . readlink. -f "$testDir/${name}.xccdf.xml")"
60 xsed -i "s|%%TEST_DIR_PATH%%|${prefix}${testDir}|" $XCCDF
61
62 testInDirectoryscip-shell shell shell-project 0.0.0 testInDirectory(). "$testDir" "$XCCDF"
63 rmscip-shell system . . rm. -rf "$testDir"
64 done