s3-selftest: introduce new net registry check check
[Samba/gebeck_regimport.git] / source3 / script / tests / test_net_registry_check.sh
blob627f67c55a83d3718fcf7ac65ef14ac719d07f8d
1 #!/bin/sh
3 # Blackbox tests for the "net registry check" command.
5 # Copyright (C) 2011 Björn Baumbach <bb@sernet.de>
7 if [ $# -lt 5 ]; then
8 echo "Usage: test_net_registry.sh SCRIPTDIR SERVERCONFFILE NET CONFIGURATION DBWRAP_TOOL"
9 exit 1
12 SCRIPTDIR="$1"
13 SERVERCONFFILE="$2"
14 NET="$3"
15 CONFIGURATION="$4"
16 DBWRAP_TOOL="$5"
18 NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
20 NETREG="${NET} registry"
21 REGORIG="$(grep 'state directory = ' $SERVERCONFFILE | sed 's/[^=]*=//')/registry.tdb"
22 REG=$REGORIG.wip
24 incdir=`dirname $0`/../../../testprogs/blackbox
25 . $incdir/subunit.sh
27 failed=0
29 # run registry check and filter allowed errors
30 regcheck()
32 ALLOWEDERR="Check database:|INFO: version ="
33 ERRSTR=$(${NETREG} check $REG $@ 2>&1 | grep -E -v "$ALLOWEDERR")
36 # try to repair registry
37 regrepair()
39 regcheck -a
42 # check if $ERRSTR contains expected error
43 checkerr()
45 EXPERR=$1
47 ERRCNT=$(echo "$ERRSTR" | grep "$EXPERR" | wc -l)
48 return $ERRCNT
51 regchecknrepair()
53 EXPERR="$1"
54 EXPERRCNT="$2"
56 regcheck
57 checkerr "$EXPERR"
58 test "x$?" = "x$ERRCNT" || {
59 echo "Expected $EXPERRCNT of error $EXPERR. Received $ERRCNT"
60 return 1
63 regrepair
64 regcheck
65 test "x$ERRSTR" = "x" || {
66 echo "Error: Can't repair database"
67 return 1
71 test_simple()
73 local ERRSTR=""
74 cp $REGORIG $REG
76 regcheck
77 test "x$ERRSTR" = "x" || {
78 echo $ERRSTR
79 return 1
83 test_damage()
85 diff $REGORIG $REG
88 test_duplicate()
90 local ERRSTR=""
91 $DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'
93 regchecknrepair "Duplicate subkeylist" 1
96 test_slashes()
98 local ERRSTR=""
99 $DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'
101 regchecknrepair "Unnormal key:" 1
104 test_uppercase()
106 local ERRSTR=""
107 $DBWRAP_TOOL $REG store 'HKLM\Software' hex '02000000534F4654574152450053595354454D00'
109 regchecknrepair "Unnormal key:" 1
112 test_strangeletters()
114 local ERRSTR=""
115 $DBWRAP_TOOL $REG store 'HKLM\SOFTWARE' hex '02000000534F4654574FABFABFABFAB354454D00'
117 regchecknrepair "Conversion error: Incomplete multibyte sequence" 1
120 testit "simple" \
121 test_simple || \
122 failed=`expr $failed + 1`
124 testit "damages_registry" \
125 test_damage || \
126 failed=`expr $failed + 1`
128 testit "duplicate" \
129 test_duplicate || \
130 failed=`expr $failed + 1`
132 testit "slashes" \
133 test_slashes || \
134 failed=`expr $failed + 1`
136 testit "uppercase" \
137 test_uppercase || \
138 failed=`expr $failed + 1`
140 #Can't repair this atm
141 #testit "strangeletters" \
142 # test_strangeletters || \
143 # failed=`expr $failed + 1`
145 testok $0 $failed