WHATSNEW: Automatic keytab update after machine password changes
[Samba.git] / source3 / script / tests / test_net_registry.sh
blob155533eedb78ace587758bdab1d4160d18b4c77b
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 NET CONFIGURATION RPC
13 EOF
14 exit 1
17 SCRIPTDIR="$1"
18 SERVERCONFFILE="$2"
19 NET="$3"
20 CONFIGURATION="$4"
21 RPC="$5"
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"
27 else
28 NETREG="${NET} registry"
31 incdir=$(dirname $0)/../../../testprogs/blackbox
32 . $incdir/subunit.sh
34 failed=0
36 test_enumerate()
38 KEY="$1"
40 ${NETREG} enumerate ${KEY}
43 test_getsd()
45 KEY="$1"
47 ${NETREG} getsd ${KEY}
50 test_enumerate_nonexisting()
52 KEY="$1"
53 ${NETREG} enumerate ${KEY}
55 if test "x$?" = "x0"; then
56 echo "ERROR: enumerate succeeded with key '${KEY}'"
57 false
58 else
59 true
63 test_enumerate_no_key()
65 ${NETREG} enumerate
66 if test "x$?" = "x0"; then
67 echo "ERROR: enumerate succeeded without any key specified"
68 false
69 else
70 true
74 test_create_existing()
76 KEY="HKLM"
77 EXPECTED="createkey opened existing ${KEY}"
79 OUTPUT=$(${NETREG} createkey ${KEY})
80 if test "x$?" = "x0"; then
81 if test "$OUTPUT" = "$EXPECTED"; then
82 true
83 else
84 echo "got '$OUTPUT', expected '$EXPECTED'"
85 false
87 else
88 printf "%s\n" "$OUTPUT"
89 false
93 test_createkey()
95 KEY="$1"
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"
102 echo "output:"
103 printf "%s\n" "$OUTPUT"
104 false
105 return
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}'"
112 echo "output:"
113 printf "%s\n" "$OUTPUT"
114 false
115 return
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 expected '$EXPECTED' in output"
122 echo "output:"
123 printf "%s\n" "$OUTPUT"
124 false
127 # check enumerate of new key works:
128 ${NETREG} enumerate ${KEY}
131 test_deletekey()
133 KEY="$1"
134 BASEKEY=$(dirname ${KEY})
135 SUBKEY=$(basename ${KEY})
137 OUTPUT=$(test_createkey "${KEY}")
138 if test "x$?" != "x0"; then
139 printf "%s\n" "${OUTPUT}"
140 false
141 return
144 OUTPUT=$(${NETREG} deletekey ${KEY})
145 if test "x$?" != "x0"; then
146 printf "%s\n" "${OUTPUT}"
147 false
148 return
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"
155 false
156 return
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"
163 echo "output:"
164 printf "%s\n" "$OUTPUT"
165 false
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}'"
172 false
173 else
174 true
178 test_deletekey_nonexisting()
180 KEY="$1"
182 OUTPUT=$(test_deletekey "${KEY}")
183 if test "x$?" != "x0"; then
184 printf "%s\n" "${OUTPUT}"
185 false
186 return
189 ${NETREG} deletekey "${KEY}"
190 if test "x$?" = "x0"; then
191 echo "ERROR: delete after delete succeeded for key '${KEY}'"
192 false
196 test_createkey_with_subkey()
198 KEY="$1"
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}"
208 false
209 return
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}"
217 false
218 return
221 # clear:
222 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
225 test_deletekey_with_subkey()
227 KEY="$1"
228 KEY2=$(dirname ${KEY})
230 OUTPUT=$(${NETREG} createkey ${KEY})
231 if test "x$?" != "x0"; then
232 printf "%s\n" "${OUTPUT}"
233 false
234 return
237 OUTPUT=$(${NETREG} deletekey ${KEY2})
239 if test "x$?" = "x0"; then
240 echo "ERROR: delete of key with subkey succeeded"
241 echo "output:"
242 printf "%s\n" "$OUTPUT"
243 false
244 return
247 ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
250 test_setvalue()
252 KEY="$1"
253 VALNAME="${2#_}"
254 VALTYPE="$3"
255 VALVALUE="$4"
257 OUTPUT=$(test_createkey ${KEY})
258 if test "x$?" != "x0"; then
259 printf "%s\n" "${OUTPUT}"
260 false
261 return
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}"
268 false
269 return
272 OUTPUT=$(${NETREG} getvalueraw ${KEY} "${VALNAME}")
273 if test "x$?" != "x0"; then
274 echo "ERROR: failure calling getvalueraw for key ${KEY}"
275 echo output:
276 printf "%s\n" "${OUTPUT}"
277 false
278 return
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}"
284 false
285 return
290 test_deletevalue()
292 KEY="$1"
293 VALNAME="${2#_}"
295 ${NETREG} deletevalue ${KEY} "${VALNAME}"
298 test_deletevalue_nonexisting()
300 KEY="$1"
301 VALNAME="${2#_}"
303 ${NETREG} deletevalue ${KEY} "${VALNAME}"
304 if test "x$?" = "x0"; then
305 echo "ERROR: succeeded deleting value ${VALNAME}"
306 false
307 else
308 true
312 test_setvalue_twice()
314 KEY="$1"
315 VALNAME="${2#_}"
316 VALTYPE1="$3"
317 VALVALUE1="$4"
318 VALTYPE2="$5"
319 VALVALUE2="$6"
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"
325 false
326 return
329 ${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)
411 testok $0 $failed