Debian Codegraph @

tests/API/probes/fts.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2 #
3 # Copyright 2011 Red Hat Inc., Durham, North Carolina.
4 # All Rights Reserved.
5 #
6 # Authors:
7 # Daniel Kopecek <[email protected]>
8 # Tomas Heinrich <[email protected]>
9
10 . $builddir/tests/test_common.sh
11
12 function gen_tree {
13 echo "Generating tree for traversal" >&2
14
15 mkdir -p $ROOT/{d1/{d11/d111,d12},d2/d21}
16 touch $ROOT/{d1/{d11/{d111/f1111,f111,f112,f113},d12/f121,f11},d2/{d21/f211,f21}}
17 }
18
19 function oval_fts {
20 echo "=== $1 ==="
21 shift
22 ./oval_fts_list "$@" | sort | tee ${tmpdir}/oval_fts_list.out | \
23 sed "s|${ROOT}/||" | tr '\n' ',' > ${tmpdir}/oval_fts_list.out2
24 if [ $? -ne 0 ]; then
25 echo "oval_fts_list failed"
26 return 2
27 fi
28
29 shift 10
30 echo -e "expected result:\n$1\noval_fts_list.out2:"
31 cat ${tmpdir}/oval_fts_list.out2
32 echo
33 if [ "$(cat ${tmpdir}/oval_fts_list.out2 | openssl md5)" == \
34 "$(echo -n $1 | openssl md5)" ]; then
35 return 0
36 else
37 return 1
38 fi
39 }
40
41 set -e -o pipefail
42
43 if [ -n "${CUSTOM_OSCAP+x}" ] ; then
44 exit 255
45 fi
46
47 name=$(basename $0 .sh)
48 tmpdir=$(make_temp_dir /tmp ${name})
49
50 ROOT=${tmpdir}/ftsroot
51 echo "Temp dir: ${tmpdir}."
52 gen_tree $ROOT
53
54 # The format for the arguments is as follows:
55 #
56 # <name of test>
57 # <path_operation_number> <path_operation_argument>
58 # <filename_operation_number> <filename_operation_argument>
59 # <filepath_operation_number> <filepath_operation_argument>
60 # <behaviors_max_depth> <behaviors_recurse> <behaviors_recurse_direction> <behaviors_recurse_file_system>
61 #
62 # When path is specified, filename must also be. Else, filepath can be
63 # specified. The first case is equivalent to the following SEXPs:
64 #
65 # ((path :operation <path_operation_number>) <path_operation_argument>)
66 # ((filename :operation <filename_operation_number>) <filename_operation_argument)
67 # ---empty filepath expression---
68 # ((behaviors :max_depth <behaviors_max_depth> :recurse <behaviors_recurse> :recurse_direction <behaviors_recurse_direction> :recurse_file_system <behaviors_recurse_file_system>))
69 #
70 # Else with filepath:
71 #
72 # ---empty path expression---
73 # ---empty filename expression---
74 # ((filepath :operation <filepath_operation_number>) <filepath_operation_argument>)
75 # ((behaviors :max_depth <behaviors_max_depth> :recurse <behaviors_recurse> :recurse_direction <behaviors_recurse_direction> :recurse_file_system <behaviors_recurse_file_system>))
76 #
77 # When both <*_operation_number> and <*_operation_argument> are empty, the
78 # resulting SEXP is not add. When <*_operation_argument> is empty, the
79 # resulting SEXP looks like:
80 # ((* :operation <*_operation_number))
81 # For filename only, if <filename_operation_argument> is equal to the string
82 # "EMPTY_STRING", the resulting SEXP looks like:
83 # ((filename :operation <filename_operation_number>) '')
84 #
85 # In general the utilized values of operation_number are:
86 # equals (5) - a comparison against a fixed string
87 # pattern match (11) - a regex based comparison
88 # and the value of the argument is then directly passed as a string.
89 #
90 # behaviors_recurse can be some combination of "symlinks" and "directories"
91 #
92 # behaviors_recurse_direction can either be none, down, or up
93 #
94 # behaviors_recurse_file_system is commonly used as all or local
95 #
96 # All of this is implemented in oval_fts_list.c.
97
98 while read args; do
99 [ -z "${args%%#*}" ] && continue
100 eval oval_fts $args
101 done <<EOF
102 test1 \
103 '' '' \
104 '' '' \
105 "equals" "$ROOT/d1/d12/f121" \
106 "-1" "symlinks and directories" "none" "all" \
107 d1/d12/f121,
108
109 test2 \
110 '' '' \
111 '' '' \
112 "pattern match" "^$ROOT/d1/.*/f1111" \
113 "-1" "symlinks and directories" "none" "all" \
114 d1/d11/d111/f1111,
115
116 test3 \
117 "equals" "$ROOT/d2" \
118 "equals" "f21" \
119 '' '' \
120 "-1" "symlinks and directories" "none" "all" \
121 d2/f21,
122
123 test4 \
124 "equals" "$ROOT/d1/d11" \
125 "pattern match" "^f11[23]$" \
126 '' '' \
127 "-1" "symlinks and directories" "none" "all" \
128 d1/d11/f112,d1/d11/f113,
129
130 test5 \
131 "pattern match" "^$ROOT/d1/d1[12]$" \
132 "pattern match" "^f..1$" \
133 '' '' \
134 "-1" "symlinks and directories" "none" "all" \
135 d1/d11/f111,d1/d12/f121,
136
137 test6 \
138 "pattern match" "^$ROOT/d1/.*" \
139 "equals" "f1111" \
140 '' '' \
141 "-1" "symlinks and directories" "none" "all" \
142 d1/d11/d111/f1111,
143
144 test7 \
145 "equals" "$ROOT/d1" \
146 "equals" "f112" \
147 '' '' \
148 "-1" "symlinks and directories" "down" "all" \
149 d1/d11/f112,
150
151 test8 \
152 "equals" "$ROOT/d1" \
153 "pattern match" "^f.*1$" \
154 '' '' \
155 "1" "symlinks and directories" "down" "all" \
156 d1/d11/f111,d1/d12/f121,d1/f11,
157
158 test9 \
159 "equals" "$ROOT/d1/d11/d111" \
160 "equals" "f11" \
161 '' '' \
162 "3" "symlinks and directories" "up" "all" \
163 d1/f11,
164
165 test10 \
166 "equals" "$ROOT/d2" \
167 "pattern match" "^f21.*$" \
168 '' '' \
169 "-1" "symlinks and directories" "down" "all" \
170 d2/d21/f211,d2/f21,
171
172 test11 \
173 "equals" "$ROOT/d2" \
174 "pattern match" "^f21.*$" \
175 '' '' \
176 "-1" "symlinks" "down" "all" \
177 d2/f21,
178
179 test12 \
180 "equals" "$ROOT/d1" \
181 "equals" "" \
182 '' '' \
183 "0" "symlinks and directories" "none" "all" \
184 d1/,
185
186 test13 \
187 "equals" "$ROOT/d1" \
188 "equals" "" \
189 '' '' \
190 "0" "symlinks and directories" "down" "all" \
191 d1/,
192
193 test14 \
194 "equals" "$ROOT/d1" \
195 "equals" "" \
196 '' '' \
197 "0" "symlinks and directories" "up" "all" \
198 d1/,
199
200 test15 \
201 "equals" "$ROOT/d1" \
202 "equals" "" \
203 '' '' \
204 "1" "symlinks and directories" "down" "all" \
205 d1/,d1/d11/,d1/d12/,
206
207 test16 \
208 "equals" "$ROOT/d1/d11" \
209 "equals" "" \
210 '' '' \
211 "1" "symlinks and directories" "up" "all" \
212 d1/,d1/d11/,
213
214 test17 \
215 "equals" "$ROOT/d1/d11" \
216 "equals" "" \
217 '' '' \
218 "-1" "symlinks and directories" "down" "all" \
219 d1/d11/,d1/d11/d111/,
220
221 # support for empty string as a pattern in 'filename' entity
222 test18 \
223 "equals" "$ROOT/d2" \
224 "pattern match" "EMPTY_STRING" \
225 '' '' \
226 "-1" "symlinks and directories" "none" "all" \
227 d2/f21,
228
229 # don't return nonexistent filepath
230 test19 \
231 '' '' \
232 '' '' \
233 "equals" "/nonexistent" \
234 "-1" "symlinks and directories" "none" "all" \
235 # intentionally left blank
236
237 # test for a regression caused by the errno check that follows calls to fts_open()
238 test20 \
239 "equals" "$ROOT/d1/d11/d111" \
240 "equals" "f1111" \
241 '' '' \
242 "-1" "directories" "down" "local" \
243 d1/d11/d111/f1111,
244
245 EOF
246
247 rm -rf $tmpdir