Debian Codegraph @

tests/API/XCCDF/unittests/test_profile_selection_by_suffix.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 . $builddir/tests/test_common.sh
3
4 set -e
5 set -o pipefail
6
7 name=$(basenamescip-shell system . . basename. $0 .sh)
8 stderr=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
9 result=$(mktempscip-shell system . . mktemp. -t ${name}.out.XXXXXX)
10 benchmark=$srcdir/${name}.xccdf.xml
11 tailoring=$srcdir/${name}_tailoring.xccdf.xml
12 echoscip-shell system . . echo. "Stderr file = $stderr"
13 echoscip-shell system . . echo. "Result file = $result"
14 ret=0
15
16 touchscip-shell system . . touch. test_file
17 [scip-shell system . . `[`. -f test_file ]
18
19 # Multiple matches should result in failure
20 $OSCAP xccdf eval --profile common $benchmark 2> $stderr || ret=$?
21 [scip-shell system . . `[`. $ret -eq 1 ]
22 # Checks that first test does result in multiple match error
23 grepscip-shell system . . grep. -Fq "Multiple matches found" $stderr
24
25 # Should pass, because underscore creates unique suffix
26 $OSCAP xccdf eval --profile _common --results $result $benchmark 2> $stderr
27 # Checks that full profile name is used in rule evaluation
28 grepscip-shell system . . grep. -Fq xccdf_org.open-scap_testresult_xccdf_moc.elpmaxe.www_profile_common $result
29
30 # Should fail, because a profile with this suffix does not exist
31 $OSCAP xccdf eval --profile xcommon $benchmark 2> $stderr || ret=$?
32 [scip-shell system . . `[`. $ret -eq 1 ]
33 # Checks that last test does result in no match error
34 grepscip-shell system . . grep. -Fq "No profile matching suffix \"xcommon\" was found" $stderr
35
36
37 # Should pass, because only one match is in tailoring file, which takes precedence
38 $OSCAP xccdf eval --tailoring-file $tailoring --profile common $benchmark 2> $stderr
39 # Checks that full profile name is used in rule evaluation
40 grepscip-shell system . . grep. -Fq xccdf_org.open-scap_testresult_xccdf_moc.elpmaxe.www_profile_common $result
41
42 # Should fail, because there will be multiple suffix matches
43 $OSCAP xccdf eval --tailoring-file $tailoring --profile her $benchmark 2> $stderr || ret=$?
44 [scip-shell system . . `[`. $ret -eq 1 ]
45 # Checks that multiple match error does result
46 grepscip-shell system . . grep. -Fq "Multiple matches found" $stderr
47
48 # Should pass, because underscore creates unique suffix
49 $OSCAP xccdf eval --tailoring-file $tailoring --profile _her --results $result $benchmark 2> $stderr
50 # Checks that full profile name is used in rule evaluation
51 grepscip-shell system . . grep. -Fq xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_her $result
52
53 # Should fail, because a profile with this suffix does not exist
54 $OSCAP xccdf eval --tailoring-file $tailoring --profile another $benchmark 2> $stderr || ret=$?
55 [scip-shell system . . `[`. $ret -eq 1 ]
56 # Checks that last test does result in no match error
57 grepscip-shell system . . grep. -Fq "No profile matching suffix \"another\" was found" $stderr
58
59 [scip-shell system . . `[`. -f $stderr ]; rmscip-shell system . . rm. $stderr
60 rmscip-shell system . . rm. $result
61
62 rmscip-shell system . . rm. -f test_file