Debian Codegraph @

tests/API/OVAL/unittests/test_external_variable.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2 . $builddir/tests/test_common.sh
3
4 set -e -o pipefail
5
6 name=$(basenamescip-shell system . . basename. $0 .sh)
7 result=$(mktempscip-shell system . . mktemp. ${name}.out.XXXXXX)
8 echoscip-shell system . . echo. "result file: $result"
9 stderr=$(mktempscip-shell system . . mktemp. ${name}.err.XXXXXX)
10 echoscip-shell system . . echo. "stderr file: $stderr"
11
12 $OSCAP oval eval --results $result --variables $srcdir/external_variables.xml $srcdir/$name.oval.xml 2> $stderr
13 # filter out the expected warnings in stderr
14
15 sedscip-shell system . . sed. -i -E "/^W: oscap:[ ]+Referenced variable has no values \(oval:x:var:[13689]\)/d" "$stderr"
16 [scip-shell system . . `[`. -f $stderr ]; [scip-shell system . . `[`. ! -s $stderr ]; rmscip-shell system . . rm. $stderr
17
18 [scip-shell system . . `[`. -s $result ]
19
20 assert_exists 10 '/oval_results/oval_definitions/variables/external_variablescip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable`.'
21 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]`.'
22 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restrictionscip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction`.'
23 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction[@hint="hint"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction[@hint="hint"]`.'
24 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction/restrictionscip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction/restriction`.'
25 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction/restriction[@operation="pattern match"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:1"]/possible_restriction/restriction[@operation="pattern match"]`.'
26 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}$"]scip-shell filesystem . . `/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}$"]`.'
27 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]`.'
28 assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restrictionscip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction`.'
29 assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restrictionscip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restriction`.'
30 assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restriction[@operation="pattern match"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:2"]/possible_restriction/restriction[@operation="pattern match"]`.'
31 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"]scip-shell filesystem . . `/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"]`.'
32 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"]scip-shell filesystem . . `/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"]`.'
33 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}$"]scip-shell filesystem . . `/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}$"]`.'
34 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}$"]scip-shell filesystem . . `/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}$"]`.'
35 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]`.'
36 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]/possible_valuescip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]/possible_value`.'
37 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]/possible_value[text()="0"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:3"]/possible_value[text()="0"]`.'
38 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]`.'
39 assert_exists 2 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_valuescip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value`.'
40 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."]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[@hint="This restricts the variable value(s) to 0."]`.'
41 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[text()="0"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[text()="0"]`.'
42 assert_exists 1 '/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[text()="1"]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[text()="1"]`.'
43 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."]scip-shell filesystem . . `/oval_results/oval_definitions/variables/external_variable[@id="oval:x:var:4"]/possible_value[@hint="This restricts the variable value(s) to 1."]`.'
44
45 CO='/oval_results/results/system/oval_system_characteristics/collected_objectsscip-shell filesystem . . `/oval_results/results/system/oval_system_characteristics/collected_objects`.'
46 assert_exists 10 $CO'/object'
47 assert_exists 1 $CO'/object[@id="oval:x:obj:1"]'
48 assert_exists 1 $CO'/object[@id="oval:x:obj:1"][@flag="does not exist"]'
49 assert_exists 1 $CO'/object[@id="oval:x:obj:1"]/message'
50 assert_exists 1 $CO'/object[@id="oval:x:obj:1"]/message[text()="Referenced variable has no values (oval:x:var:1)."]'
51 assert_exists 1 $CO'/object[@id="oval:x:obj:2"]'
52 assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/variable_value'
53 assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/variable_value[@variable_id="oval:x:var:2"]'
54 assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/variable_value[text()="123-456-7890"]'
55 assert_exists 1 $CO'/object[@id="oval:x:obj:2"]/reference'
56 assert_exists 1 $CO'/object[@id="oval:x:obj:3"]'
57 assert_exists 1 $CO'/object[@id="oval:x:obj:3"][@flag="does not exist"]'
58 assert_exists 1 $CO'/object[@id="oval:x:obj:3"]/message'
59 assert_exists 1 $CO'/object[@id="oval:x:obj:3"]/message[text()="Referenced variable has no values (oval:x:var:3)."]'
60 assert_exists 1 $CO'/object[@id="oval:x:obj:4"]'
61 assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/variable_value'
62 assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/variable_value[@variable_id="oval:x:var:4"]'
63 assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/variable_value[text()="1"]'
64 assert_exists 1 $CO'/object[@id="oval:x:obj:4"]/reference'
65
66 assert_exists 1 $CO'/object[@id="oval:x:obj:5"]'
67 assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/variable_value'
68 assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/variable_value[@variable_id="oval:x:var:5"]'
69 assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/variable_value[text()="13"]'
70 assert_exists 1 $CO'/object[@id="oval:x:obj:5"]/reference'
71
72 assert_exists 1 $CO'/object[@id="oval:x:obj:6"]'
73 assert_exists 1 $CO'/object[@id="oval:x:obj:6"][@flag="does not exist"]'
74 assert_exists 1 $CO'/object[@id="oval:x:obj:6"]/message'
75 assert_exists 1 $CO'/object[@id="oval:x:obj:6"]/message[text()="Referenced variable has no values (oval:x:var:6)."]'
76
77 assert_exists 1 $CO'/object[@id="oval:x:obj:7"]'
78 assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/variable_value'
79 assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/variable_value[@variable_id="oval:x:var:7"]'
80 assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/variable_value[text()="300"]'
81 assert_exists 1 $CO'/object[@id="oval:x:obj:7"]/reference'
82
83 assert_exists 1 $CO'/object[@id="oval:x:obj:8"]'
84 assert_exists 1 $CO'/object[@id="oval:x:obj:8"][@flag="does not exist"]'
85 assert_exists 1 $CO'/object[@id="oval:x:obj:8"]/message'
86 assert_exists 1 $CO'/object[@id="oval:x:obj:8"]/message[text()="Referenced variable has no values (oval:x:var:8)."]'
87
88 assert_exists 1 $CO'/object[@id="oval:x:obj:9"]'
89 assert_exists 1 $CO'/object[@id="oval:x:obj:9"][@flag="does not exist"]'
90 assert_exists 1 $CO'/object[@id="oval:x:obj:9"]/message'
91 assert_exists 1 $CO'/object[@id="oval:x:obj:9"]/message[text()="Referenced variable has no values (oval:x:var:9)."]'
92
93 assert_exists 1 $CO'/object[@id="oval:x:obj:10"]'
94 assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/variable_value'
95 assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/variable_value[@variable_id="oval:x:var:10"]'
96 assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/variable_value[text()="17"]'
97 assert_exists 1 $CO'/object[@id="oval:x:obj:10"]/reference'
98
99 SD='/oval_results/results/system/oval_system_characteristics/system_datascip-shell filesystem . . `/oval_results/results/system/oval_system_characteristics/system_data`.'
100 assert_exists 5 $SD'/ind-sys:variable_item'
101 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:2"]'
102 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="123-456-7890"]'
103 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:4"]'
104 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="1"]'
105 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:5"]'
106 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="13"]'
107 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:7"]'
108 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="300"]'
109 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:var_ref[text()="oval:x:var:10"]'
110 assert_exists 1 $SD'/ind-sys:variable_item/ind-sys:value[text()="17"]'
111
112 rmscip-shell system . . rm. $result