| 1 | #!/bin/sh
|
|---|
| 2 | #
|
|---|
| 3 | # Blackbox tests for the "net registry" and "net rpc registry" commands.
|
|---|
| 4 | #
|
|---|
| 5 | # Copyright (C) 2010-2011 Michael Adam <[email protected]>
|
|---|
| 6 | # Copyright (C) 2010 Gregor Beck <[email protected]>
|
|---|
| 7 | #
|
|---|
| 8 | # rpc tests are chose by specifying "rpc" as commandline parameter.
|
|---|
| 9 |
|
|---|
| 10 | if [ $# -lt 3 ]; then
|
|---|
| 11 | cat <<EOF
|
|---|
| 12 | Usage: test_net_registry.sh SCRIPTDIR SERVERCONFFILE CONFIGURATION RPC
|
|---|
| 13 | EOF
|
|---|
| 14 | exit 1;
|
|---|
| 15 | fi
|
|---|
| 16 |
|
|---|
| 17 | SCRIPTDIR="$1"
|
|---|
| 18 | SERVERCONFFILE="$2"
|
|---|
| 19 | CONFIGURATION="$3"
|
|---|
| 20 | RPC="$4"
|
|---|
| 21 |
|
|---|
| 22 | NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
|
|---|
| 23 |
|
|---|
| 24 | if test "x${RPC}" = "xrpc" ; then
|
|---|
| 25 | NETREG="${NET} -U${USERNAME}%${PASSWORD} -I ${SERVER_IP} rpc registry"
|
|---|
| 26 | else
|
|---|
| 27 | NETREG="${NET} registry"
|
|---|
| 28 | fi
|
|---|
| 29 |
|
|---|
| 30 | test x"$TEST_FUNCTIONS_SH" != x"INCLUDED" && {
|
|---|
| 31 | incdir=`dirname $0`/../../../testprogs/blackbox
|
|---|
| 32 | . $incdir/subunit.sh
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | failed=0
|
|---|
| 36 |
|
|---|
| 37 | test_enumerate()
|
|---|
| 38 | {
|
|---|
| 39 | KEY="$1"
|
|---|
| 40 |
|
|---|
| 41 | ${NETREG} enumerate ${KEY}
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | test_getsd()
|
|---|
| 45 | {
|
|---|
| 46 | KEY="$1"
|
|---|
| 47 |
|
|---|
| 48 | ${NETREG} getsd ${KEY}
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | test_enumerate_nonexisting()
|
|---|
| 52 | {
|
|---|
| 53 | KEY="$1"
|
|---|
| 54 | ${NETREG} enumerate ${KEY}
|
|---|
| 55 |
|
|---|
| 56 | if test "x$?" = "x0" ; then
|
|---|
| 57 | echo "ERROR: enumerate succeeded with key '${KEY}'"
|
|---|
| 58 | false
|
|---|
| 59 | else
|
|---|
| 60 | true
|
|---|
| 61 | fi
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | test_enumerate_no_key()
|
|---|
| 65 | {
|
|---|
| 66 | ${NETREG} enumerate
|
|---|
| 67 | if test "x$?" = "x0" ; then
|
|---|
| 68 | echo "ERROR: enumerate succeeded without any key spcified"
|
|---|
| 69 | false
|
|---|
| 70 | else
|
|---|
| 71 | true
|
|---|
| 72 | fi
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | test_create_existing()
|
|---|
| 76 | {
|
|---|
| 77 | KEY="HKLM"
|
|---|
| 78 | EXPECTED="createkey opened existing ${KEY}"
|
|---|
| 79 |
|
|---|
| 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
|
|---|
| 87 | fi
|
|---|
| 88 | else
|
|---|
| 89 | printf "%s\n" "$OUTPUT"
|
|---|
| 90 | false
|
|---|
| 91 | fi
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | test_createkey()
|
|---|
| 95 | {
|
|---|
| 96 | KEY="$1"
|
|---|
| 97 | BASEKEY=`dirname $KEY`
|
|---|
| 98 | SUBKEY=`basename $KEY`
|
|---|
| 99 |
|
|---|
| 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
|
|---|
| 107 | fi
|
|---|
| 108 |
|
|---|
| 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
|
|---|
| 117 | fi
|
|---|
| 118 |
|
|---|
| 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
|
|---|
| 126 | fi
|
|---|
| 127 |
|
|---|
| 128 | # check enumerate of new key works:
|
|---|
| 129 | ${NETREG} enumerate ${KEY}
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | test_deletekey()
|
|---|
| 133 | {
|
|---|
| 134 | KEY="$1"
|
|---|
| 135 | BASEKEY=`dirname ${KEY}`
|
|---|
| 136 | SUBKEY=`basename ${KEY}`
|
|---|
| 137 |
|
|---|
| 138 | OUTPUT=`test_createkey "${KEY}"`
|
|---|
| 139 | if test "x$?" != "x0" ; then
|
|---|
| 140 | printf "%s\n" "${OUTPUT}"
|
|---|
| 141 | false
|
|---|
| 142 | return
|
|---|
| 143 | fi
|
|---|
| 144 |
|
|---|
| 145 | OUTPUT=`${NETREG} deletekey ${KEY}`
|
|---|
| 146 | if test "x$?" != "x0" ; then
|
|---|
| 147 | printf "%s\n" "${OUTPUT}"
|
|---|
| 148 | false
|
|---|
| 149 | return
|
|---|
| 150 | fi
|
|---|
| 151 |
|
|---|
| 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
|
|---|
| 158 | fi
|
|---|
| 159 |
|
|---|
| 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
|
|---|
| 167 | fi
|
|---|
| 168 |
|
|---|
| 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
|
|---|
| 176 | fi
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | test_deletekey_nonexisting()
|
|---|
| 180 | {
|
|---|
| 181 | KEY="$1"
|
|---|
| 182 |
|
|---|
| 183 | OUTPUT=`test_deletekey "${KEY}"`
|
|---|
| 184 | if test "x$?" != "x0" ; then
|
|---|
| 185 | printf "%s\n" "${OUTPUT}"
|
|---|
| 186 | false
|
|---|
| 187 | return
|
|---|
| 188 | fi
|
|---|
| 189 |
|
|---|
| 190 | ${NETREG} deletekey "${KEY}"
|
|---|
| 191 | if test "x$?" = "x0" ; then
|
|---|
| 192 | echo "ERROR: delete after delete succeeded for key '${KEY}'"
|
|---|
| 193 | false
|
|---|
| 194 | fi
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | test_createkey_with_subkey()
|
|---|
| 198 | {
|
|---|
| 199 | KEY="$1"
|
|---|
| 200 | KEY2=`dirname ${KEY}`
|
|---|
| 201 | SUBKEYNAME2=`basename ${KEY}`
|
|---|
| 202 | BASENAME=`dirname ${KEY2}`
|
|---|
| 203 | SUBKEYNAME1=`basename ${KEY2}`
|
|---|
| 204 |
|
|---|
| 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
|
|---|
| 211 | fi
|
|---|
| 212 |
|
|---|
| 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
|
|---|
| 220 | fi
|
|---|
| 221 |
|
|---|
| 222 | # clear:
|
|---|
| 223 | ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | test_deletekey_with_subkey()
|
|---|
| 227 | {
|
|---|
| 228 | KEY="$1"
|
|---|
| 229 | KEY2=`dirname ${KEY}`
|
|---|
| 230 |
|
|---|
| 231 | OUTPUT=`${NETREG} createkey ${KEY}`
|
|---|
| 232 | if test "x$?" != "x0" ; then
|
|---|
| 233 | printf "%s\n" "${OUTPUT}"
|
|---|
| 234 | false
|
|---|
| 235 | return
|
|---|
| 236 | fi
|
|---|
| 237 |
|
|---|
| 238 | OUTPUT=`${NETREG} deletekey ${KEY2}`
|
|---|
| 239 |
|
|---|
| 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
|
|---|
| 246 | fi
|
|---|
| 247 |
|
|---|
| 248 | ${NETREG} deletekey ${KEY} && ${NETREG} deletekey ${KEY2}
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | test_setvalue()
|
|---|
| 252 | {
|
|---|
| 253 | KEY="$1"
|
|---|
| 254 | VALNAME="${2#_}"
|
|---|
| 255 | VALTYPE="$3"
|
|---|
| 256 | VALVALUE="$4"
|
|---|
| 257 |
|
|---|
| 258 | OUTPUT=`test_createkey ${KEY}`
|
|---|
| 259 | if test "x$?" != "x0" ; then
|
|---|
| 260 | printf "%s\n" "${OUTPUT}"
|
|---|
| 261 | false
|
|---|
| 262 | return
|
|---|
| 263 | fi
|
|---|
| 264 |
|
|---|
| 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
|
|---|
| 271 | fi
|
|---|
| 272 |
|
|---|
| 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
|
|---|
| 280 | fi
|
|---|
| 281 |
|
|---|
| 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
|
|---|
| 287 | fi
|
|---|
| 288 |
|
|---|
| 289 | }
|
|---|
| 290 |
|
|---|
| 291 | test_deletevalue()
|
|---|
| 292 | {
|
|---|
| 293 | KEY="$1"
|
|---|
| 294 | VALNAME="${2#_}"
|
|---|
| 295 |
|
|---|
| 296 | ${NETREG} deletevalue ${KEY} "${VALNAME}"
|
|---|
| 297 | }
|
|---|
| 298 |
|
|---|
| 299 | test_deletevalue_nonexisting()
|
|---|
| 300 | {
|
|---|
| 301 | KEY="$1"
|
|---|
| 302 | VALNAME="${2#_}"
|
|---|
| 303 |
|
|---|
| 304 | ${NETREG} deletevalue ${KEY} "${VALNAME}"
|
|---|
| 305 | if test "x$?" = "x0" ; then
|
|---|
| 306 | echo "ERROR: succeeded deleting value ${VALNAME}"
|
|---|
| 307 | false
|
|---|
| 308 | else
|
|---|
| 309 | true
|
|---|
| 310 | fi
|
|---|
| 311 | }
|
|---|
| 312 |
|
|---|
| 313 | test_setvalue_twice()
|
|---|
| 314 | {
|
|---|
| 315 | KEY="$1"
|
|---|
| 316 | VALNAME="${2#_}"
|
|---|
| 317 | VALTYPE1="$3"
|
|---|
| 318 | VALVALUE1="$4"
|
|---|
| 319 | VALTYPE2="$5"
|
|---|
| 320 | VALVALUE2="$6"
|
|---|
| 321 |
|
|---|
| 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
|
|---|
| 328 | fi
|
|---|
| 329 |
|
|---|
| 330 | ${NETREG} setvalue ${KEY} "${VALNAME}" ${VALTYPE2} ${VALVALUE2}
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 |
|
|---|
| 334 | testit "enumerate HKLM" \
|
|---|
| 335 | test_enumerate HKLM || \
|
|---|
| 336 | failed=`expr $failed + 1`
|
|---|
| 337 |
|
|---|
| 338 | testit "enumerate nonexisting hive" \
|
|---|
| 339 | test_enumerate_nonexisting XYZ || \
|
|---|
| 340 | failed=`expr $failed + 1`
|
|---|
| 341 |
|
|---|
| 342 | testit "enumerate without key" \
|
|---|
| 343 | test_enumerate_no_key || \
|
|---|
| 344 | failed=`expr $failed + 1`
|
|---|
| 345 |
|
|---|
| 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`
|
|---|
| 351 | fi
|
|---|
| 352 |
|
|---|
| 353 | testit "create existing HKLM" \
|
|---|
| 354 | test_create_existing || \
|
|---|
| 355 | failed=`expr $failed + 1`
|
|---|
| 356 |
|
|---|
| 357 | testit "create key" \
|
|---|
| 358 | test_createkey HKLM/testkey || \
|
|---|
| 359 | failed=`expr $failed + 1`
|
|---|
| 360 |
|
|---|
| 361 | testit "delete key" \
|
|---|
| 362 | test_deletekey HKLM/testkey || \
|
|---|
| 363 | failed=`expr $failed + 1`
|
|---|
| 364 |
|
|---|
| 365 | testit "delete^2 key" \
|
|---|
| 366 | test_deletekey_nonexisting HKLM/testkey || \
|
|---|
| 367 | failed=`expr $failed + 1`
|
|---|
| 368 |
|
|---|
| 369 | testit "enumerate nonexisting key" \
|
|---|
| 370 | test_enumerate_nonexisting HKLM/testkey || \
|
|---|
| 371 | failed=`expr $failed + 1`
|
|---|
| 372 |
|
|---|
| 373 | testit "create key with subkey" \
|
|---|
| 374 | test_createkey_with_subkey HKLM/testkey/subkey || \
|
|---|
| 375 | failed=`expr $failed + 1`
|
|---|
| 376 |
|
|---|
| 377 | testit "delete key with subkey" \
|
|---|
| 378 | test_deletekey_with_subkey HKLM/testkey/subkey || \
|
|---|
| 379 | failed=`expr $failed + 1`
|
|---|
| 380 |
|
|---|
| 381 | testit "set value" \
|
|---|
| 382 | test_setvalue HKLM/testkey _testval sz moin || \
|
|---|
| 383 | failed=`expr $failed + 1`
|
|---|
| 384 |
|
|---|
| 385 | testit "delete value" \
|
|---|
| 386 | test_deletevalue HKLM/testkey _testval || \
|
|---|
| 387 | failed=`expr $failed + 1`
|
|---|
| 388 |
|
|---|
| 389 | testit "delete nonexisting value" \
|
|---|
| 390 | test_deletevalue_nonexisting HKLM/testkey _testval || \
|
|---|
| 391 | failed=`expr $failed + 1`
|
|---|
| 392 |
|
|---|
| 393 | testit "set value to different type" \
|
|---|
| 394 | test_setvalue_twice HKLM/testkey testval sz moin dword 42 || \
|
|---|
| 395 | failed=`expr $failed + 1`
|
|---|
| 396 |
|
|---|
| 397 | testit "set default value" \
|
|---|
| 398 | test_setvalue HKLM/testkey _"" sz 42 || \
|
|---|
| 399 | failed=`expr $failed + 1`
|
|---|
| 400 |
|
|---|
| 401 | testit "delete default value" \
|
|---|
| 402 | test_deletevalue HKLM/testkey _"" || \
|
|---|
| 403 | failed=`expr $failed + 1`
|
|---|
| 404 |
|
|---|
| 405 | testit "delete nonexisting default value" \
|
|---|
| 406 | test_deletevalue_nonexisting HKLM/testkey _"" || \
|
|---|
| 407 | failed=`expr $failed + 1`
|
|---|
| 408 |
|
|---|
| 409 | testit "delete key with value" \
|
|---|
| 410 | test_deletekey HKLM/testkey || \
|
|---|
| 411 | failed=`expr $failed + 1`
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 | testok $0 $failed
|
|---|
| 415 |
|
|---|