selftest: Add test for link and deleted link behaviour in dbcheck
[sfrench/samba-autobuild/.git] / testprogs / blackbox / dbcheck-links.sh
1 #!/bin/sh
2
3 if [ $# -lt 1 ]; then
4 cat <<EOF
5 Usage: dbcheck-links.sh PREFIX RELEASE
6 EOF
7 exit 1;
8 fi
9
10 PREFIX_ABS="$1"
11 RELEASE="$2"
12 shift 2
13
14 . `dirname $0`/subunit.sh
15
16 release_dir=`dirname $0`/../../source4/selftest/provisions/$RELEASE
17
18 ldbadd="ldbadd"
19 if [ -x "$BINDIR/ldbadd" ]; then
20     ldbadd="$BINDIR/ldbadd"
21 fi
22
23 ldbmodify="ldbmodify"
24 if [ -x "$BINDIR/ldbmodify" ]; then
25     ldbmodify="$BINDIR/ldbmodify"
26 fi
27
28 ldbdel="ldbdel"
29 if [ -x "$BINDIR/ldbdel" ]; then
30     ldbdel="$BINDIR/ldbdel"
31 fi
32
33 ldbsearch="ldbsearch"
34 if [ -x "$BINDIR/ldbsearch" ]; then
35     ldbsearch="$BINDIR/ldbsearch"
36 fi
37
38 ldbrename="ldbrename"
39 if [ -x "$BINDIR/ldbrename" ]; then
40     ldbrename="$BINDIR/ldbrename"
41 fi
42
43 undump() {
44        if test -x $BINDIR/tdbrestore;
45        then
46         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE $BINDIR/tdbrestore
47        else
48         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE
49        fi
50 }
51
52 dbcheck() {
53     tmpfile=$PREFIX_ABS/$RELEASE/expected-dbcheck-link-output.txt.tmp
54     tmpldif1=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp1
55
56     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
57
58     $PYTHON $BINDIR/samba-tool dbcheck -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb --fix --yes > $tmpfile
59     if [ "$?" != "1" ]; then
60         return 1
61     fi
62     diff $tmpfile $release_dir/expected-dbcheck-link-output.txt
63     if [ "$?" != "0" ]; then
64         return 1
65     fi
66
67     tmpldif2=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp2
68     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
69
70     diff $tmpldif1 $tmpldif2
71     if [ "$?" != "0" ]; then
72         return 1
73     fi
74 }
75
76 dbcheck_clean() {
77     tmpldif1=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp1
78
79     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
80
81     $PYTHON $BINDIR/samba-tool dbcheck -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb
82     if [ "$?" != "0" ]; then
83         return 1
84     fi
85     tmpldif2=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp2
86     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
87
88     diff $tmpldif1 $tmpldif2
89     if [ "$?" != "0" ]; then
90         return 1
91     fi
92 }
93
94 add_two_more_users() {
95     ldif=$release_dir/add-two-more-users.ldif
96     TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
97     if [ "$?" != "0" ]; then
98         return 1
99     fi
100 }
101
102 add_four_more_links() {
103     ldif=$release_dir/add-four-more-links.ldif
104     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
105     if [ "$?" != "0" ]; then
106         return 1
107     fi
108 }
109
110 remove_one_link() {
111     ldif=$release_dir/remove-one-more-link.ldif
112     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
113     if [ "$?" != "0" ]; then
114         return 1
115     fi
116 }
117
118 remove_one_user() {
119     ldif=$release_dir/remove-one-more-user.ldif
120     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
121     if [ "$?" != "0" ]; then
122         return 1
123     fi
124 }
125
126 move_one_user() {
127     TZ=UTC $ldbrename -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb 'cn=user1,cn=users,DC=release-4-5-0-pre1,DC=samba,DC=corp' 'cn=user1x,cn=users,DC=release-4-5-0-pre1,DC=samba,DC=corp'
128     if [ "$?" != "0" ]; then
129         return 1
130     fi
131 }
132
133 check_expected_after_links() {
134     tmpldif=$PREFIX_ABS/$RELEASE/expected-links-after-link-dbcheck.ldif.tmp
135     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(cn=swimmers)(cn=leaders)(cn=helpers))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --sorted member > $tmpldif
136     diff $tmpldif $release_dir/expected-links-after-link-dbcheck.ldif
137     if [ "$?" != "0" ]; then
138         return 1
139     fi
140 }
141
142 check_expected_after_deleted_links() {
143     tmpldif=$PREFIX_ABS/$RELEASE/expected-deleted-links-after-link-dbcheck.ldif.tmp
144     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(cn=swimmers)(cn=leaders)(cn=helpers))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member > $tmpldif
145     diff $tmpldif $release_dir/expected-deleted-links-after-link-dbcheck.ldif
146     if [ "$?" != "0" ]; then
147         return 1
148     fi
149 }
150
151 check_expected_after_objects() {
152     tmpldif=$PREFIX_ABS/$RELEASE/expected-objects-after-link-dbcheck.ldif.tmp
153     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(samaccountname=fred)(samaccountname=ddg)(samaccountname=usg)(samaccountname=user1)(samaccountname=user1x)(samaccountname=user2))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted samAccountName | grep sAMAccountName > $tmpldif
154     diff $tmpldif $release_dir/expected-objects-after-link-dbcheck.ldif
155     if [ "$?" != "0" ]; then
156         return 1
157     fi
158 }
159
160 if [ -d $release_dir ]; then
161     testit $RELEASE undump
162     testit "add_two_more_users" add_two_more_users
163     testit "add_four_more_links" add_four_more_links
164     testit "remove_one_link" remove_one_link
165     testit "remove_one_user" remove_one_user
166     testit "move_one_user" move_one_user
167     testit "dbcheck" dbcheck
168     testit "dbcheck_clean" dbcheck_clean
169     testit "check_expected_after_deleted_links" check_expected_after_deleted_links
170     testit "check_expected_after_links" check_expected_after_links
171     testit "check_expected_after_objects" check_expected_after_objects
172 else
173     subunit_start_test $RELEASE
174     subunit_skip_test $RELEASE <<EOF
175 no test provision
176 EOF
177
178     subunit_start_test "tombstones_expunge"
179     subunit_skip_test "tombstones_expunge" <<EOF
180 no test provision
181 EOF
182 fi
183
184 if [ -d $PREFIX_ABS/${RELEASE} ]; then
185     rm -fr $PREFIX_ABS/${RELEASE}
186 fi
187
188 exit $failed