File: test_external_variable.sh

package info (click to toggle)
openscap 1.4.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 125,040 kB
  • sloc: xml: 527,109; ansic: 91,390; sh: 19,789; python: 2,515; perl: 444; makefile: 49
file content (112 lines) | stat: -rwxr-xr-x 8,064 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
. $builddir/tests/test_common.sh

set -e -o pipefail

name=$(basename $0 .sh)
result=$(mktemp ${name}.out.XXXXXX)
echo "result file: $result"
stderr=$(mktemp ${name}.err.XXXXXX)
echo "stderr file: $stderr"

$OSCAP oval eval --results $result --variables $srcdir/external_variables.xml $srcdir/$name.oval.xml 2> $stderr
# filter out the expected warnings in stderr

sed -i -E "/^W: oscap:[ ]+Referenced variable has no values \(oval:x:var:[13689]\)/d" "$stderr"
[ -f $stderr ]; [ ! -s $stderr ]; rm $stderr

[ -s $result ]

assert_exists 10 '/oval_results/oval_definitions/variables/external_variable'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction[@hint="hint"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction/restriction'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction/restriction[@operation="pattern match"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction/restriction[text()="^[0-9]{3}-[0-9]{3}-[0-9]{4}$"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]'
assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction'
assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restriction'
assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restriction[@operation="pattern match"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction[@hint="This restricts the variable value(s) to the 10 digit telephone number format xxx-xxx-xxxx"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction[@hint="This restricts the variable value(s) to the 1 plus 10 digit telephone number format x-xxx-xxx-xxxx"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restriction[text()="^[0-9]{3}-[0-9]{3}-[0-9]{4}$"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restriction[text()="^1-[0-9]{3}-[0-9]{3}-[0-9]{4}$"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]/possible_value'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]/possible_value[text()="0"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]'
assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[@hint="This restricts the variable value(s) to 0."]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[text()="0"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[text()="1"]'
assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[@hint="This restricts the variable value(s) to 1."]'

CO='/oval_results/results/system/oval_system_characteristics/collected_objects'
assert_exists 10 $CO'/object'
assert_exists 1 $CO'/object[@id="oval:x:obj:1"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:1"][@flag="does not exist"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:1"]/message'
assert_exists 1 $CO'/object[@id="oval:x:obj:1"]/message[text()="Referenced variable has no values (oval:x:var:1)."]'
assert_exists 1 $CO'/object[@id="oval:x:obj:2"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/variable_value'
assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/variable_value[@variable_id="oval:x:var:2"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/variable_value[text()="123-456-7890"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/reference'
assert_exists 1 $CO'/object[@id="oval:x:obj:3"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:3"][@flag="does not exist"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:3"]/message'
assert_exists 1 $CO'/object[@id="oval:x:obj:3"]/message[text()="Referenced variable has no values (oval:x:var:3)."]'
assert_exists 1 $CO'/object[@id="oval:x:obj:4"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/variable_value'
assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/variable_value[@variable_id="oval:x:var:4"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/variable_value[text()="1"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/reference'

assert_exists 1 $CO'/object[@id="oval:x:obj:5"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/variable_value'
assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/variable_value[@variable_id="oval:x:var:5"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/variable_value[text()="13"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/reference'

assert_exists 1 $CO'/object[@id="oval:x:obj:6"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:6"][@flag="does not exist"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:6"]/message'
assert_exists 1 $CO'/object[@id="oval:x:obj:6"]/message[text()="Referenced variable has no values (oval:x:var:6)."]'

assert_exists 1 $CO'/object[@id="oval:x:obj:7"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/variable_value'
assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/variable_value[@variable_id="oval:x:var:7"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/variable_value[text()="300"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/reference'

assert_exists 1 $CO'/object[@id="oval:x:obj:8"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:8"][@flag="does not exist"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:8"]/message'
assert_exists 1 $CO'/object[@id="oval:x:obj:8"]/message[text()="Referenced variable has no values (oval:x:var:8)."]'

assert_exists 1 $CO'/object[@id="oval:x:obj:9"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:9"][@flag="does not exist"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:9"]/message'
assert_exists 1 $CO'/object[@id="oval:x:obj:9"]/message[text()="Referenced variable has no values (oval:x:var:9)."]'

assert_exists 1 $CO'/object[@id="oval:x:obj:10"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/variable_value'
assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/variable_value[@variable_id="oval:x:var:10"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/variable_value[text()="17"]'
assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/reference'

SD='/oval_results/results/system/oval_system_characteristics/system_data'
assert_exists 5 $SD'/ind-sys:variable_item'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:2"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="123-456-7890"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:4"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="1"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:5"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="13"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:7"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="300"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:10"]'
assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="17"]'

rm $result