summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Baumbach <bb@sernet.de>2011-11-09 13:24:42 +0100
committerMichael Adam <obnox@samba.org>2012-03-22 00:21:56 +0100
commitd5db47c7d412c1795a7485f10c2517e36f80c7fc (patch)
tree99d780cb8a3811ec4a1d7a0a0d5fe2798285f498
parent86a80cf4fde13576ed89a5e1ea12bb5e61261fc8 (diff)
downloadsamba-d5db47c7d412c1795a7485f10c2517e36f80c7fc.tar.gz
samba-d5db47c7d412c1795a7485f10c2517e36f80c7fc.tar.bz2
samba-d5db47c7d412c1795a7485f10c2517e36f80c7fc.zip
s3-selftest: introduce new net registry check check
Add a new check which checks for defects in the net registry check tool. Signed-off-by: Michael Adam <obnox@samba.org>
-rwxr-xr-xsource3/script/tests/test_net_registry_check.sh146
1 files changed, 146 insertions, 0 deletions
diff --git a/source3/script/tests/test_net_registry_check.sh b/source3/script/tests/test_net_registry_check.sh
new file mode 100755
index 0000000000..627f67c55a
--- /dev/null
+++ b/source3/script/tests/test_net_registry_check.sh
@@ -0,0 +1,146 @@
+#!/bin/sh
+#
+# Blackbox tests for the "net registry check" command.
+#
+# Copyright (C) 2011 Björn Baumbach <bb@sernet.de>
+
+if [ $# -lt 5 ]; then
+ echo "Usage: test_net_registry.sh SCRIPTDIR SERVERCONFFILE NET CONFIGURATION DBWRAP_TOOL"
+ exit 1
+fi
+
+SCRIPTDIR="$1"
+SERVERCONFFILE="$2"
+NET="$3"
+CONFIGURATION="$4"
+DBWRAP_TOOL="$5"
+
+NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"
+
+NETREG="${NET} registry"
+REGORIG="$(grep 'state directory = ' $SERVERCONFFILE | sed 's/[^=]*=//')/registry.tdb"
+REG=$REGORIG.wip
+
+incdir=`dirname $0`/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+failed=0
+
+# run registry check and filter allowed errors
+regcheck()
+{
+ ALLOWEDERR="Check database:|INFO: version ="
+ ERRSTR=$(${NETREG} check $REG $@ 2>&1 | grep -E -v "$ALLOWEDERR")
+}
+
+# try to repair registry
+regrepair()
+{
+ regcheck -a
+}
+
+# check if $ERRSTR contains expected error
+checkerr()
+{
+ EXPERR=$1
+
+ ERRCNT=$(echo "$ERRSTR" | grep "$EXPERR" | wc -l)
+ return $ERRCNT
+}
+
+regchecknrepair()
+{
+ EXPERR="$1"
+ EXPERRCNT="$2"
+
+ regcheck
+ checkerr "$EXPERR"
+ test "x$?" = "x$ERRCNT" || {
+ echo "Expected $EXPERRCNT of error $EXPERR. Received $ERRCNT"
+ return 1
+ }
+
+ regrepair
+ regcheck
+ test "x$ERRSTR" = "x" || {
+ echo "Error: Can't repair database"
+ return 1
+ }
+}
+
+test_simple()
+{
+ local ERRSTR=""
+ cp $REGORIG $REG
+
+ regcheck
+ test "x$ERRSTR" = "x" || {
+ echo $ERRSTR
+ return 1
+ }
+}
+
+test_damage()
+{
+ diff $REGORIG $REG
+}
+
+test_duplicate()
+{
+ local ERRSTR=""
+ $DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'
+
+ regchecknrepair "Duplicate subkeylist" 1
+}
+
+test_slashes()
+{
+ local ERRSTR=""
+ $DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'
+
+ regchecknrepair "Unnormal key:" 1
+}
+
+test_uppercase()
+{
+ local ERRSTR=""
+ $DBWRAP_TOOL $REG store 'HKLM\Software' hex '02000000534F4654574152450053595354454D00'
+
+ regchecknrepair "Unnormal key:" 1
+}
+
+test_strangeletters()
+{
+ local ERRSTR=""
+ $DBWRAP_TOOL $REG store 'HKLM\SOFTWARE' hex '02000000534F4654574FABFABFABFAB354454D00'
+
+ regchecknrepair "Conversion error: Incomplete multibyte sequence" 1
+}
+
+testit "simple" \
+ test_simple || \
+ failed=`expr $failed + 1`
+
+testit "damages_registry" \
+ test_damage || \
+ failed=`expr $failed + 1`
+
+testit "duplicate" \
+ test_duplicate || \
+ failed=`expr $failed + 1`
+
+testit "slashes" \
+ test_slashes || \
+ failed=`expr $failed + 1`
+
+testit "uppercase" \
+ test_uppercase || \
+ failed=`expr $failed + 1`
+
+#Can't repair this atm
+#testit "strangeletters" \
+# test_strangeletters || \
+# failed=`expr $failed + 1`
+
+testok $0 $failed
+