winreg: Use the ntstatus return code for client side errors
[Samba/gebeck_regimport.git] / source3 / script / tests / test_net_registry.sh
blobb76a988b4dc4e1cf4d18121bf38cd7ff05400908
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 incdir=`dirname $0`/../../../testprogs/blackbox
31 . $incdir/subunit.sh
33 failed=0
35 test_enumerate()
37 KEY="$1"
39 ${NETREG} enumerate ${KEY}
42 test_getsd()
44 KEY="$1"
46 ${NETREG} getsd ${KEY}
49 test_enumerate_nonexisting()
51 KEY="$1"
52 ${NETREG} enumerate ${KEY}
54 if test "x$?" = "x0" ; then
55 echo "ERROR: enumerate succeeded with key '${KEY}'"
56 false
57 else
58 true
62 test_enumerate_no_key()
64 ${NETREG} enumerate
65 if test "x$?" = "x0" ; then
66 echo "ERROR: enumerate succeeded without any key spcified"
67 false
68 else
69 true
73 test_create_existing()
75 KEY="HKLM"
76 EXPECTED="createkey opened existing ${KEY}"
78 OUTPUT=`${NETREG} createkey ${KEY}`
79 if test "x$?" = "x0" ; then
80 if test "$OUTPUT" = "$EXPECTED" ; then
81 true
82 else
83 echo "got '$OUTPUT', expected '$EXPECTED'"
84 false
86 else
87 printf "%s\n" "$OUTPUT"
88 false
92 test_createkey()
94 KEY="$1"
95 BASEKEY=`dirname $KEY`
96 SUBKEY=`basename $KEY`
98 OUTPUT=`${NETREG} createkey ${KEY}`
99 if test "x$?" != "x0" ; then
100 echo "ERROR: createkey ${KEY} failed"
101 echo "output:"
102 printf "%s\n" "$OUTPUT"
103 false
104 return
107 # check enumerate of basekey lists new key:
108 OUTPUT=`${NETREG} enumerate ${BASEKEY}`
109 if test "x$?" != "x0" ; then
110 echo "ERROR: failed to enumerate key '${BASEKEY}'"
111 echo "output:"
112 printf "%s\n" "$OUTPUT"
113 false
114 return
117 EXPECTED="Keyname = ${SUBKEY}"
118 printf "%s\n" "$OUTPUT" | grep '^Keyname' | grep ${SUBKEY}
119 if test "x$?" != "x0" ; then
120 echo "ERROR: did not find expexted '$EXPECTED' in output"
121 echo "output:"
122 printf "%s\n" "$OUTPUT"
123 false
126 # check enumerate of new key works:
127 ${NETREG} enumerate ${KEY}
130 test_deletekey()
132 KEY="$1"
133 BASEKEY=`dirname ${KEY}`
134 SUBKEY=`basename ${KEY}`
136 OUTPUT=`test_createkey "${KEY}"`
137 if test "x$?" != "x0" ; then
138 printf "%s\n" "${OUTPUT}"
139 false
140 return
143 OUTPUT=`${NETREG} deletekey ${KEY}`
144 if test "x$?" != "x0" ; then
145 printf "%s\n" "${OUTPUT}"
146 false
147 return
150 # check enumerate of basekey does not show key anymore:
151 OUTPUT=`${NETREG} enumerate ${BASEKEY}`
152 if test "x$?" != "x0" ; then
153 printf "%s\n" "$OUTPUT"
154 false
155 return
158 UNEXPECTED="Keyname = ${SUBKEY}"
159 printf "%s\n" "$OUTPUT" | grep '^Keyname' | grep ${SUBKEY}
160 if test "x$?" = "x0" ; then
161 echo "ERROR: found '$UNEXPECTED' after delete in output"
162 echo "output:"
163 printf "%s\n" "$OUTPUT"
164 false
167 # check enumerate of key itself does not work anymore:
168 ${NETREG} enumerate ${KEY}
169 if test "x$?" = "x0" ; then
170 echo "ERROR: 'enumerate ${KEY}' works after 'deletekey ${KEY}'"
171 false
172 else
173 true
177 test_deletekey_nonexisting()
179 KEY="$1"
181 OUTPUT=`test_deletekey "${KEY}"`
182 if test "x$?" != "x0" ; then
183 printf "%s\n" "${OUTPUT}"
184 false
185 return
188 ${NETREG} deletekey "${KEY}"
189 if test "x$?" = "x0" ; then
190 echo "ERROR: delete after delete succeeded for key '${KEY}'"
191 false
195 test_createkey_with_subkey()
197 KEY="$1"
198 KEY2=`dirname ${KEY}`
199 SUBKEYNAME2=`basename ${KEY}`
200 BASENAME=`dirname ${KEY2}`
201 SUBKEYNAME1=`basename ${KEY2}`
203 OUTPUT=`${NETREG} createkey ${KEY}`
204 if test "x$?" != "x0" ; then
205 echo "ERROR: createkey ${KEY} failed"
206 printf "%s\n" "${OUTPUT}"
207 false
208 return
211 # check we can enumerate to level key
212 OUTPUT=`${NETREG} enumerate ${KEY}`
213 if test "x$?" != "x0" ; then
214 echo "ERROR: failed to enumerate '${KEY}' after creation"
215 printf "%s\n" "${OUTPUT}"
216 false
217 return
220 # clear:
221 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
224 test_deletekey_with_subkey()
226 KEY="$1"
227 KEY2=`dirname ${KEY}`
229 OUTPUT=`${NETREG} createkey ${KEY}`
230 if test "x$?" != "x0" ; then
231 printf "%s\n" "${OUTPUT}"
232 false
233 return
236 OUTPUT=`${NETREG} deletekey ${KEY2}`
238 if test "x$?" = "x0" ; then
239 echo "ERROR: delete of key with subkey succeeded"
240 echo "output:"
241 printf "%s\n" "$OUTPUT"
242 false
243 return
246 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
249 test_setvalue()
251 KEY="$1"
252 VALNAME="${2#_}"
253 VALTYPE="$3"
254 VALVALUE="$4"
256 OUTPUT=`test_createkey ${KEY}`
257 if test "x$?" != "x0" ; then
258 printf "%s\n" "${OUTPUT}"
259 false
260 return
263 OUTPUT=`${NETREG} setvalue ${KEY} "${VALNAME}" ${VALTYPE} ${VALVALUE}`
264 if test "x$?" != "x0" ; then
265 echo "ERROR: failed to set value testval in key ${KEY}"
266 printf "%s\n" "${OUTPUT}"
267 false
268 return
271 OUTPUT=`${NETREG} getvalueraw ${KEY} "${VALNAME}"`
272 if test "x$?" != "x0" ; then
273 echo "ERROR: failure calling getvalueraw for key ${KEY}"
274 echo output:
275 printf "%s\n" "${OUTPUT}"
276 false
277 return
280 if test "x${OUTPUT}" != "x${VALVALUE}" ; then
281 echo "ERROR: failure retrieving value ${VALNAME} for key ${KEY}"
282 printf "expected: %s\ngot: %s\n" "${VALVALUE}" "${OUTPUT}"
283 false
284 return
289 test_deletevalue()
291 KEY="$1"
292 VALNAME="${2#_}"
294 ${NETREG} deletevalue ${KEY} "${VALNAME}"
297 test_deletevalue_nonexisting()
299 KEY="$1"
300 VALNAME="${2#_}"
302 ${NETREG} deletevalue ${KEY} "${VALNAME}"
303 if test "x$?" = "x0" ; then
304 echo "ERROR: succeeded deleting value ${VALNAME}"
305 false
306 else
307 true
311 test_setvalue_twice()
313 KEY="$1"
314 VALNAME="${2#_}"
315 VALTYPE1="$3"
316 VALVALUE1="$4"
317 VALTYPE2="$5"
318 VALVALUE2="$6"
320 OUTPUT=`test_setvalue ${KEY} _"${VALNAME}" ${VALTYPE1} ${VALVALUE1}`
321 if test "x$?" != "x0" ; then
322 echo "ERROR: first setvalue call failed"
323 printf "%s\n" "$OUTPUT"
324 false
325 return
328 ${NETREG} setvalue ${KEY} "${VALNAME}" ${VALTYPE2} ${VALVALUE2}
332 testit "enumerate HKLM" \
333 test_enumerate HKLM || \
334 failed=`expr $failed + 1`
336 testit "enumerate nonexisting hive" \
337 test_enumerate_nonexisting XYZ || \
338 failed=`expr $failed + 1`
340 testit "enumerate without key" \
341 test_enumerate_no_key || \
342 failed=`expr $failed + 1`
344 # skip getsd test for registry currently: it fails
345 if test "x${RPC}" != "xrpc" ; then
346 testit "getsd HKLM" \
347 test_getsd HKLM || \
348 failed=`expr $failed + 1`
351 testit "create existing HKLM" \
352 test_create_existing || \
353 failed=`expr $failed + 1`
355 testit "create key" \
356 test_createkey HKLM/testkey || \
357 failed=`expr $failed + 1`
359 testit "delete key" \
360 test_deletekey HKLM/testkey || \
361 failed=`expr $failed + 1`
363 testit "delete^2 key" \
364 test_deletekey_nonexisting HKLM/testkey || \
365 failed=`expr $failed + 1`
367 testit "enumerate nonexisting key" \
368 test_enumerate_nonexisting HKLM/testkey || \
369 failed=`expr $failed + 1`
371 testit "create key with subkey" \
372 test_createkey_with_subkey HKLM/testkey/subkey || \
373 failed=`expr $failed + 1`
375 testit "delete key with subkey" \
376 test_deletekey_with_subkey HKLM/testkey/subkey || \
377 failed=`expr $failed + 1`
379 testit "set value" \
380 test_setvalue HKLM/testkey _testval sz moin || \
381 failed=`expr $failed + 1`
383 testit "delete value" \
384 test_deletevalue HKLM/testkey _testval || \
385 failed=`expr $failed + 1`
387 testit "delete nonexisting value" \
388 test_deletevalue_nonexisting HKLM/testkey _testval || \
389 failed=`expr $failed + 1`
391 testit "set value to different type" \
392 test_setvalue_twice HKLM/testkey testval sz moin dword 42 || \
393 failed=`expr $failed + 1`
395 testit "set default value" \
396 test_setvalue HKLM/testkey _"" sz 42 || \
397 failed=`expr $failed + 1`
399 testit "delete default value" \
400 test_deletevalue HKLM/testkey _"" || \
401 failed=`expr $failed + 1`
403 testit "delete nonexisting default value" \
404 test_deletevalue_nonexisting HKLM/testkey _"" || \
405 failed=`expr $failed + 1`
407 testit "delete key with value" \
408 test_deletekey HKLM/testkey || \
409 failed=`expr $failed + 1`
412 testok $0 $failed