Add some const to can_delete_file_in_directory().
[Samba.git] / source3 / script / tests / test_net_registry.sh
blob21c452d6e1aaad7518af41337ea9718967a1d574
1 #!/bin/sh
3 # Blackbox tests for the "net registry" and "net rpc registry" commands.
5 # Copyright (C) 2010-2011 Michael Adam <obnox@samba.org>
6 # Copyright (C) 2010 Gregor Beck <gbeck@sernet.de>
8 # rpc tests are chose by specifying "rpc" as commandline parameter.
10 if [ $# -lt 3 ]; then
11 cat <<EOF
12 Usage: test_net_registry.sh SCRIPTDIR SERVERCONFFILE CONFIGURATION RPC
13 EOF
14 exit 1;
17 SCRIPTDIR="$1"
18 SERVERCONFFILE="$2"
19 CONFIGURATION="$3"
20 RPC="$4"
22 NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
24 if test "x${RPC}" = "xrpc" ; then
25 NETREG="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry"
26 else
27 NETREG="${NET} registry"
30 test x"$TEST_FUNCTIONS_SH" != x"INCLUDED" && {
31 incdir=`dirname $0`/../../../testprogs/blackbox
32 . $incdir/subunit.sh
35 failed=0
37 test_enumerate()
39 KEY="$1"
41 ${NETREG} enumerate ${KEY}
44 test_getsd()
46 KEY="$1"
48 ${NETREG} getsd ${KEY}
51 test_enumerate_nonexisting()
53 KEY="$1"
54 ${NETREG} enumerate ${KEY}
56 if test "x$?" = "x0" ; then
57 echo "ERROR: enumerate succeeded with key '${KEY}'"
58 false
59 else
60 true
64 test_enumerate_no_key()
66 ${NETREG} enumerate
67 if test "x$?" = "x0" ; then
68 echo "ERROR: enumerate succeeded without any key spcified"
69 false
70 else
71 true
75 test_create_existing()
77 KEY="HKLM"
78 EXPECTED="createkey opened existing ${KEY}"
80 OUTPUT=`${NETREG} createkey ${KEY}`
81 if test "x$?" = "x0" ; then
82 if test "$OUTPUT" = "$EXPECTED" ; then
83 true
84 else
85 echo "got '$OUTPUT', expected '$EXPECTED'"
86 false
88 else
89 printf "%s\n" "$OUTPUT"
90 false
94 test_createkey()
96 KEY="$1"
97 BASEKEY=`dirname $KEY`
98 SUBKEY=`basename $KEY`
100 OUTPUT=`${NETREG} createkey ${KEY}`
101 if test "x$?" != "x0" ; then
102 echo "ERROR: createkey ${KEY} failed"
103 echo "output:"
104 printf "%s\n" "$OUTPUT"
105 false
106 return
109 # check enumerate of basekey lists new key:
110 OUTPUT=`${NETREG} enumerate ${BASEKEY}`
111 if test "x$?" != "x0" ; then
112 echo "ERROR: failed to enumerate key '${BASEKEY}'"
113 echo "output:"
114 printf "%s\n" "$OUTPUT"
115 false
116 return
119 EXPECTED="Keyname = ${SUBKEY}"
120 printf "%s\n" "$OUTPUT" | grep '^Keyname' | grep ${SUBKEY}
121 if test "x$?" != "x0" ; then
122 echo "ERROR: did not find expexted '$EXPECTED' in output"
123 echo "output:"
124 printf "%s\n" "$OUTPUT"
125 false
128 # check enumerate of new key works:
129 ${NETREG} enumerate ${KEY}
132 test_deletekey()
134 KEY="$1"
135 BASEKEY=`dirname ${KEY}`
136 SUBKEY=`basename ${KEY}`
138 OUTPUT=`test_createkey "${KEY}"`
139 if test "x$?" != "x0" ; then
140 printf "%s\n" "${OUTPUT}"
141 false
142 return
145 OUTPUT=`${NETREG} deletekey ${KEY}`
146 if test "x$?" != "x0" ; then
147 printf "%s\n" "${OUTPUT}"
148 false
149 return
152 # check enumerate of basekey does not show key anymore:
153 OUTPUT=`${NETREG} enumerate ${BASEKEY}`
154 if test "x$?" != "x0" ; then
155 printf "%s\n" "$OUTPUT"
156 false
157 return
160 UNEXPECTED="Keyname = ${SUBKEY}"
161 printf "%s\n" "$OUTPUT" | grep '^Keyname' | grep ${SUBKEY}
162 if test "x$?" = "x0" ; then
163 echo "ERROR: found '$UNEXPECTED' after delete in output"
164 echo "output:"
165 printf "%s\n" "$OUTPUT"
166 false
169 # check enumerate of key itself does not work anymore:
170 ${NETREG} enumerate ${KEY}
171 if test "x$?" = "x0" ; then
172 echo "ERROR: 'enumerate ${KEY}' works after 'deletekey ${KEY}'"
173 false
174 else
175 true
179 test_deletekey_nonexisting()
181 KEY="$1"
183 OUTPUT=`test_deletekey "${KEY}"`
184 if test "x$?" != "x0" ; then
185 printf "%s\n" "${OUTPUT}"
186 false
187 return
190 ${NETREG} deletekey "${KEY}"
191 if test "x$?" = "x0" ; then
192 echo "ERROR: delete after delete succeeded for key '${KEY}'"
193 false
197 test_createkey_with_subkey()
199 KEY="$1"
200 KEY2=`dirname ${KEY}`
201 SUBKEYNAME2=`basename ${KEY}`
202 BASENAME=`dirname ${KEY2}`
203 SUBKEYNAME1=`basename ${KEY2}`
205 OUTPUT=`${NETREG} createkey ${KEY}`
206 if test "x$?" != "x0" ; then
207 echo "ERROR: createkey ${KEY} failed"
208 printf "%s\n" "${OUTPUT}"
209 false
210 return
213 # check we can enumerate to level key
214 OUTPUT=`${NETREG} enumerate ${KEY}`
215 if test "x$?" != "x0" ; then
216 echo "ERROR: failed to enumerate '${KEY}' after creation"
217 printf "%s\n" "${OUTPUT}"
218 false
219 return
222 # clear:
223 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
226 test_deletekey_with_subkey()
228 KEY="$1"
229 KEY2=`dirname ${KEY}`
231 OUTPUT=`${NETREG} createkey ${KEY}`
232 if test "x$?" != "x0" ; then
233 printf "%s\n" "${OUTPUT}"
234 false
235 return
238 OUTPUT=`${NETREG} deletekey ${KEY2}`
240 if test "x$?" = "x0" ; then
241 echo "ERROR: delete of key with subkey succeeded"
242 echo "output:"
243 printf "%s\n" "$OUTPUT"
244 false
245 return
248 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
251 test_setvalue()
253 KEY="$1"
254 VALNAME="${2#_}"
255 VALTYPE="$3"
256 VALVALUE="$4"
258 OUTPUT=`test_createkey ${KEY}`
259 if test "x$?" != "x0" ; then
260 printf "%s\n" "${OUTPUT}"
261 false
262 return
265 OUTPUT=`${NETREG} setvalue ${KEY} "${VALNAME}" ${VALTYPE} ${VALVALUE}`
266 if test "x$?" != "x0" ; then
267 echo "ERROR: failed to set value testval in key ${KEY}"
268 printf "%s\n" "${OUTPUT}"
269 false
270 return
273 OUTPUT=`${NETREG} getvalueraw ${KEY} "${VALNAME}"`
274 if test "x$?" != "x0" ; then
275 echo "ERROR: failure calling getvalueraw for key ${KEY}"
276 echo output:
277 printf "%s\n" "${OUTPUT}"
278 false
279 return
282 if test "x${OUTPUT}" != "x${VALVALUE}" ; then
283 echo "ERROR: failure retrieving value ${VALNAME} for key ${KEY}"
284 printf "expected: %s\ngot: %s\n" "${VALVALUE}" "${OUTPUT}"
285 false
286 return
291 test_deletevalue()
293 KEY="$1"
294 VALNAME="${2#_}"
296 ${NETREG} deletevalue ${KEY} "${VALNAME}"
299 test_deletevalue_nonexisting()
301 KEY="$1"
302 VALNAME="${2#_}"
304 ${NETREG} deletevalue ${KEY} "${VALNAME}"
305 if test "x$?" = "x0" ; then
306 echo "ERROR: succeeded deleting value ${VALNAME}"
307 false
308 else
309 true
313 test_setvalue_twice()
315 KEY="$1"
316 VALNAME="${2#_}"
317 VALTYPE1="$3"
318 VALVALUE1="$4"
319 VALTYPE2="$5"
320 VALVALUE2="$6"
322 OUTPUT=`test_setvalue ${KEY} _"${VALNAME}" ${VALTYPE1} ${VALVALUE1}`
323 if test "x$?" != "x0" ; then
324 echo "ERROR: first setvalue call failed"
325 printf "%s\n" "$OUTPUT"
326 false
327 return
330 ${NETREG} setvalue ${KEY} "${VALNAME}" ${VALTYPE2} ${VALVALUE2}
334 testit "enumerate HKLM" \
335 test_enumerate HKLM || \
336 failed=`expr $failed + 1`
338 testit "enumerate nonexisting hive" \
339 test_enumerate_nonexisting XYZ || \
340 failed=`expr $failed + 1`
342 testit "enumerate without key" \
343 test_enumerate_no_key || \
344 failed=`expr $failed + 1`
346 # skip getsd test for registry currently: it fails
347 if test "x${RPC}" != "xrpc" ; then
348 testit "getsd HKLM" \
349 test_getsd HKLM || \
350 failed=`expr $failed + 1`
353 testit "create existing HKLM" \
354 test_create_existing || \
355 failed=`expr $failed + 1`
357 testit "create key" \
358 test_createkey HKLM/testkey || \
359 failed=`expr $failed + 1`
361 testit "delete key" \
362 test_deletekey HKLM/testkey || \
363 failed=`expr $failed + 1`
365 testit "delete^2 key" \
366 test_deletekey_nonexisting HKLM/testkey || \
367 failed=`expr $failed + 1`
369 testit "enumerate nonexisting key" \
370 test_enumerate_nonexisting HKLM/testkey || \
371 failed=`expr $failed + 1`
373 testit "create key with subkey" \
374 test_createkey_with_subkey HKLM/testkey/subkey || \
375 failed=`expr $failed + 1`
377 testit "delete key with subkey" \
378 test_deletekey_with_subkey HKLM/testkey/subkey || \
379 failed=`expr $failed + 1`
381 testit "set value" \
382 test_setvalue HKLM/testkey _testval sz moin || \
383 failed=`expr $failed + 1`
385 testit "delete value" \
386 test_deletevalue HKLM/testkey _testval || \
387 failed=`expr $failed + 1`
389 testit "delete nonexisting value" \
390 test_deletevalue_nonexisting HKLM/testkey _testval || \
391 failed=`expr $failed + 1`
393 testit "set value to different type" \
394 test_setvalue_twice HKLM/testkey testval sz moin dword 42 || \
395 failed=`expr $failed + 1`
397 testit "set default value" \
398 test_setvalue HKLM/testkey _"" sz 42 || \
399 failed=`expr $failed + 1`
401 testit "delete default value" \
402 test_deletevalue HKLM/testkey _"" || \
403 failed=`expr $failed + 1`
405 testit "delete nonexisting default value" \
406 test_deletevalue_nonexisting HKLM/testkey _"" || \
407 failed=`expr $failed + 1`
409 testit "delete key with value" \
410 test_deletekey HKLM/testkey || \
411 failed=`expr $failed + 1`
414 testok $0 $failed