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 NET CONFIGURATION RPC
23 NET
="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
25 if test "x${RPC}" = "xrpc" ; then
26 NETREG
="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry"
28 NETREG
="${NET} registry"
31 incdir
=`dirname $0`/..
/..
/..
/testprogs
/blackbox
40 ${NETREG} enumerate
${KEY}
47 ${NETREG} getsd
${KEY}
50 test_enumerate_nonexisting
()
53 ${NETREG} enumerate
${KEY}
55 if test "x$?" = "x0" ; then
56 echo "ERROR: enumerate succeeded with key '${KEY}'"
63 test_enumerate_no_key
()
66 if test "x$?" = "x0" ; then
67 echo "ERROR: enumerate succeeded without any key spcified"
74 test_create_existing
()
77 EXPECTED
="createkey opened existing ${KEY}"
79 OUTPUT
=`${NETREG} createkey ${KEY}`
80 if test "x$?" = "x0" ; then
81 if test "$OUTPUT" = "$EXPECTED" ; then
84 echo "got '$OUTPUT', expected '$EXPECTED'"
88 printf "%s\n" "$OUTPUT"
96 BASEKEY
=`dirname $KEY`
97 SUBKEY
=`basename $KEY`
99 OUTPUT
=`${NETREG} createkey ${KEY}`
100 if test "x$?" != "x0" ; then
101 echo "ERROR: createkey ${KEY} failed"
103 printf "%s\n" "$OUTPUT"
108 # check enumerate of basekey lists new key:
109 OUTPUT
=`${NETREG} enumerate ${BASEKEY}`
110 if test "x$?" != "x0" ; then
111 echo "ERROR: failed to enumerate key '${BASEKEY}'"
113 printf "%s\n" "$OUTPUT"
118 EXPECTED
="Keyname = ${SUBKEY}"
119 printf "%s\n" "$OUTPUT" |
grep '^Keyname' |
grep ${SUBKEY}
120 if test "x$?" != "x0" ; then
121 echo "ERROR: did not find expexted '$EXPECTED' in output"
123 printf "%s\n" "$OUTPUT"
127 # check enumerate of new key works:
128 ${NETREG} enumerate
${KEY}
134 BASEKEY
=`dirname ${KEY}`
135 SUBKEY
=`basename ${KEY}`
137 OUTPUT
=`test_createkey "${KEY}"`
138 if test "x$?" != "x0" ; then
139 printf "%s\n" "${OUTPUT}"
144 OUTPUT
=`${NETREG} deletekey ${KEY}`
145 if test "x$?" != "x0" ; then
146 printf "%s\n" "${OUTPUT}"
151 # check enumerate of basekey does not show key anymore:
152 OUTPUT
=`${NETREG} enumerate ${BASEKEY}`
153 if test "x$?" != "x0" ; then
154 printf "%s\n" "$OUTPUT"
159 UNEXPECTED
="Keyname = ${SUBKEY}"
160 printf "%s\n" "$OUTPUT" |
grep '^Keyname' |
grep ${SUBKEY}
161 if test "x$?" = "x0" ; then
162 echo "ERROR: found '$UNEXPECTED' after delete in output"
164 printf "%s\n" "$OUTPUT"
168 # check enumerate of key itself does not work anymore:
169 ${NETREG} enumerate
${KEY}
170 if test "x$?" = "x0" ; then
171 echo "ERROR: 'enumerate ${KEY}' works after 'deletekey ${KEY}'"
178 test_deletekey_nonexisting
()
182 OUTPUT
=`test_deletekey "${KEY}"`
183 if test "x$?" != "x0" ; then
184 printf "%s\n" "${OUTPUT}"
189 ${NETREG} deletekey
"${KEY}"
190 if test "x$?" = "x0" ; then
191 echo "ERROR: delete after delete succeeded for key '${KEY}'"
196 test_createkey_with_subkey
()
199 KEY2
=`dirname ${KEY}`
200 SUBKEYNAME2
=`basename ${KEY}`
201 BASENAME
=`dirname ${KEY2}`
202 SUBKEYNAME1
=`basename ${KEY2}`
204 OUTPUT
=`${NETREG} createkey ${KEY}`
205 if test "x$?" != "x0" ; then
206 echo "ERROR: createkey ${KEY} failed"
207 printf "%s\n" "${OUTPUT}"
212 # check we can enumerate to level key
213 OUTPUT
=`${NETREG} enumerate ${KEY}`
214 if test "x$?" != "x0" ; then
215 echo "ERROR: failed to enumerate '${KEY}' after creation"
216 printf "%s\n" "${OUTPUT}"
222 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
225 test_deletekey_with_subkey
()
228 KEY2
=`dirname ${KEY}`
230 OUTPUT
=`${NETREG} createkey ${KEY}`
231 if test "x$?" != "x0" ; then
232 printf "%s\n" "${OUTPUT}"
237 OUTPUT
=`${NETREG} deletekey ${KEY2}`
239 if test "x$?" = "x0" ; then
240 echo "ERROR: delete of key with subkey succeeded"
242 printf "%s\n" "$OUTPUT"
247 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
257 OUTPUT
=`test_createkey ${KEY}`
258 if test "x$?" != "x0" ; then
259 printf "%s\n" "${OUTPUT}"
264 OUTPUT
=`${NETREG} setvalue ${KEY} "${VALNAME}" ${VALTYPE} ${VALVALUE}`
265 if test "x$?" != "x0" ; then
266 echo "ERROR: failed to set value testval in key ${KEY}"
267 printf "%s\n" "${OUTPUT}"
272 OUTPUT
=`${NETREG} getvalueraw ${KEY} "${VALNAME}"`
273 if test "x$?" != "x0" ; then
274 echo "ERROR: failure calling getvalueraw for key ${KEY}"
276 printf "%s\n" "${OUTPUT}"
281 if test "x${OUTPUT}" != "x${VALVALUE}" ; then
282 echo "ERROR: failure retrieving value ${VALNAME} for key ${KEY}"
283 printf "expected: %s\ngot: %s\n" "${VALVALUE}" "${OUTPUT}"
295 ${NETREG} deletevalue ${KEY} "${VALNAME}"
298 test_deletevalue_nonexisting()
303 ${NETREG} deletevalue ${KEY} "${VALNAME}"
304 if test "x$?" = "x0" ; then
305 echo "ERROR: succeeded deleting value ${VALNAME}"
312 test_setvalue_twice
()
321 OUTPUT
=`test_setvalue ${KEY} _"${VALNAME}" ${VALTYPE1} ${VALVALUE1}`
322 if test "x$?" != "x0" ; then
323 echo "ERROR: first setvalue call failed"
324 printf "%s\n" "$OUTPUT"
329 ${NETREG} setvalue ${KEY} "${VALNAME}" ${VALTYPE2} ${VALVALUE2}
333 testit
"enumerate HKLM" \
334 test_enumerate HKLM || \
335 failed
=`expr $failed + 1`
337 testit
"enumerate nonexisting hive" \
338 test_enumerate_nonexisting XYZ || \
339 failed
=`expr $failed + 1`
341 testit
"enumerate without key" \
342 test_enumerate_no_key || \
343 failed
=`expr $failed + 1`
345 # skip getsd test for registry currently: it fails
346 if test "x${RPC}" != "xrpc" ; then
347 testit
"getsd HKLM" \
349 failed
=`expr $failed + 1`
352 testit
"create existing HKLM" \
353 test_create_existing || \
354 failed
=`expr $failed + 1`
356 testit
"create key" \
357 test_createkey HKLM
/testkey || \
358 failed
=`expr $failed + 1`
360 testit
"delete key" \
361 test_deletekey HKLM
/testkey || \
362 failed
=`expr $failed + 1`
364 testit
"delete^2 key" \
365 test_deletekey_nonexisting HKLM
/testkey || \
366 failed
=`expr $failed + 1`
368 testit
"enumerate nonexisting key" \
369 test_enumerate_nonexisting HKLM
/testkey || \
370 failed
=`expr $failed + 1`
372 testit
"create key with subkey" \
373 test_createkey_with_subkey HKLM
/testkey
/subkey || \
374 failed
=`expr $failed + 1`
376 testit
"delete key with subkey" \
377 test_deletekey_with_subkey HKLM
/testkey
/subkey || \
378 failed
=`expr $failed + 1`
381 test_setvalue HKLM
/testkey _testval sz moin || \
382 failed
=`expr $failed + 1`
384 testit
"delete value" \
385 test_deletevalue HKLM
/testkey _testval || \
386 failed
=`expr $failed + 1`
388 testit
"delete nonexisting value" \
389 test_deletevalue_nonexisting HKLM
/testkey _testval || \
390 failed
=`expr $failed + 1`
392 testit
"set value to different type" \
393 test_setvalue_twice HKLM
/testkey testval sz moin dword
42 || \
394 failed
=`expr $failed + 1`
396 testit
"set default value" \
397 test_setvalue HKLM
/testkey _
"" sz
42 || \
398 failed
=`expr $failed + 1`
400 testit
"delete default value" \
401 test_deletevalue HKLM
/testkey _
"" || \
402 failed
=`expr $failed + 1`
404 testit
"delete nonexisting default value" \
405 test_deletevalue_nonexisting HKLM
/testkey _
"" || \
406 failed
=`expr $failed + 1`
408 testit
"delete key with value" \
409 test_deletekey HKLM
/testkey || \
410 failed
=`expr $failed + 1`