s3:test_net_registry_check: eliminate "local" keyword in shell
[metze/samba/wip.git] / source3 / script / tests / test_net_registry_check.sh
1 #!/bin/sh
2 #
3 # Blackbox tests for the "net registry check" command.
4 #
5 # Copyright (C) 2011 Björn Baumbach <bb@sernet.de>
6
7 if [ $# -lt 5 ]; then
8         echo "Usage: test_net_registry.sh SCRIPTDIR SERVERCONFFILE NET CONFIGURATION DBWRAP_TOOL"
9         exit 1
10 fi
11
12 SCRIPTDIR="$1"
13 SERVERCONFFILE="$2"
14 NET="$3"
15 CONFIGURATION="$4"
16 DBWRAP_TOOL="$5"
17
18 NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
19
20 NETREG="${NET} registry"
21 REGORIG="$(grep 'state directory = ' $SERVERCONFFILE | sed 's/[^=]*=//')/registry.tdb"
22 REG=$REGORIG.wip
23
24 incdir=`dirname $0`/../../../testprogs/blackbox
25 . $incdir/subunit.sh
26
27 failed=0
28
29 # run registry check and filter allowed errors
30 regcheck()
31 {
32         ALLOWEDERR="Check database:|INFO: version ="
33         ERRSTR=$(${NETREG} check $REG $@ 2>&1 | grep -E -v "$ALLOWEDERR")
34 }
35
36 # try to repair registry
37 regrepair()
38 {
39         regcheck -a
40 }
41
42 # check if $ERRSTR contains expected error
43 checkerr()
44 {
45         EXPERR=$1
46
47         ERRCNT=$(echo "$ERRSTR" | grep "$EXPERR" | wc -l)
48         return $ERRCNT
49 }
50
51 regchecknrepair()
52 {
53         EXPERR="$1"
54         EXPERRCNT="$2"
55
56         regcheck
57         checkerr "$EXPERR"
58         test "x$?" = "x$ERRCNT" || {
59                 echo "Expected $EXPERRCNT of error $EXPERR. Received $ERRCNT"
60                 return 1
61         }
62
63         regrepair
64         regcheck
65         test "x$ERRSTR" = "x" || {
66                 echo "Error: Can't repair database"
67                 return 1
68         }
69 }
70
71 test_simple()
72 (
73         ERRSTR=""
74         cp $REGORIG $REG
75
76         regcheck
77         test "x$ERRSTR" = "x" || {
78                 echo $ERRSTR
79                 return 1
80         }
81 )
82
83 test_damage()
84 {
85         diff $REGORIG $REG
86 }
87
88 test_duplicate()
89 (
90         ERRSTR=""
91         $DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'
92
93         regchecknrepair "Duplicate subkeylist" 1
94 )
95
96 test_slashes()
97 (
98         ERRSTR=""
99         $DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'
100
101         regchecknrepair "Unnormal key:" 1
102 )
103
104 test_uppercase()
105 (
106         ERRSTR=""
107         $DBWRAP_TOOL $REG store 'HKLM\Software' hex '02000000534F4654574152450053595354454D00'
108
109         regchecknrepair "Unnormal key:" 1
110 )
111
112 test_strangeletters()
113 (
114         ERRSTR=""
115         $DBWRAP_TOOL $REG store 'HKLM\SOFTWARE' hex '02000000534F4654574FABFABFABFAB354454D00'
116
117         regchecknrepair "Conversion error: Incomplete multibyte sequence" 1
118 )
119
120 testit "simple" \
121         test_simple || \
122         failed=`expr $failed + 1`
123
124 testit "damages_registry" \
125         test_damage || \
126         failed=`expr $failed + 1`
127
128 testit "duplicate" \
129         test_duplicate || \
130         failed=`expr $failed + 1`
131
132 testit "slashes" \
133         test_slashes || \
134         failed=`expr $failed + 1`
135
136 testit "uppercase" \
137         test_uppercase || \
138         failed=`expr $failed + 1`
139
140 #Can't repair this atm
141 #testit "strangeletters" \
142 #       test_strangeletters || \
143 #       failed=`expr $failed + 1`
144
145 testok $0 $failed
146