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.
12 Usage: test_net_registry.sh SCRIPTDIR SERVERCONFFILE CONFIGURATION RPC
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"
27 NETREG
="${NET} registry"
30 test x
"$TEST_FUNCTIONS_SH" != x
"INCLUDED" && {
31 incdir
=`dirname $0`/..
/..
/..
/testprogs
/blackbox
41 ${NETREG} enumerate
${KEY}
48 ${NETREG} getsd
${KEY}
51 test_enumerate_nonexisting
()
54 ${NETREG} enumerate
${KEY}
56 if test "x$?" = "x0" ; then
57 echo "ERROR: enumerate succeeded with key '${KEY}'"
64 test_enumerate_no_key
()
67 if test "x$?" = "x0" ; then
68 echo "ERROR: enumerate succeeded without any key spcified"
75 test_create_existing
()
78 EXPECTED
="createkey opened existing ${KEY}"
80 OUTPUT
=`${NETREG} createkey ${KEY}`
81 if test "x$?" = "x0" ; then
82 if test "$OUTPUT" = "$EXPECTED" ; then
85 echo "got '$OUTPUT', expected '$EXPECTED'"
89 printf "%s\n" "$OUTPUT"
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"
104 printf "%s\n" "$OUTPUT"
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}'"
114 printf "%s\n" "$OUTPUT"
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"
124 printf "%s\n" "$OUTPUT"
128 # check enumerate of new key works:
129 ${NETREG} enumerate
${KEY}
135 BASEKEY
=`dirname ${KEY}`
136 SUBKEY
=`basename ${KEY}`
138 OUTPUT
=`test_createkey "${KEY}"`
139 if test "x$?" != "x0" ; then
140 printf "%s\n" "${OUTPUT}"
145 OUTPUT
=`${NETREG} deletekey ${KEY}`
146 if test "x$?" != "x0" ; then
147 printf "%s\n" "${OUTPUT}"
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"
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"
165 printf "%s\n" "$OUTPUT"
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}'"
179 test_deletekey_nonexisting
()
183 OUTPUT
=`test_deletekey "${KEY}"`
184 if test "x$?" != "x0" ; then
185 printf "%s\n" "${OUTPUT}"
190 ${NETREG} deletekey
"${KEY}"
191 if test "x$?" = "x0" ; then
192 echo "ERROR: delete after delete succeeded for key '${KEY}'"
197 test_createkey_with_subkey
()
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}"
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}"
223 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
226 test_deletekey_with_subkey
()
229 KEY2
=`dirname ${KEY}`
231 OUTPUT
=`${NETREG} createkey ${KEY}`
232 if test "x$?" != "x0" ; then
233 printf "%s\n" "${OUTPUT}"
238 OUTPUT
=`${NETREG} deletekey ${KEY2}`
240 if test "x$?" = "x0" ; then
241 echo "ERROR: delete of key with subkey succeeded"
243 printf "%s\n" "$OUTPUT"
248 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
258 OUTPUT
=`test_createkey ${KEY}`
259 if test "x$?" != "x0" ; then
260 printf "%s\n" "${OUTPUT}"
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}"
273 OUTPUT
=`${NETREG} getvalueraw ${KEY} "${VALNAME}"`
274 if test "x$?" != "x0" ; then
275 echo "ERROR: failure calling getvalueraw for key ${KEY}"
277 printf "%s\n" "${OUTPUT}"
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}"
296 ${NETREG} deletevalue ${KEY} "${VALNAME}"
299 test_deletevalue_nonexisting()
304 ${NETREG} deletevalue ${KEY} "${VALNAME}"
305 if test "x$?" = "x0" ; then
306 echo "ERROR: succeeded deleting value ${VALNAME}"
313 test_setvalue_twice
()
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"
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" \
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`
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`