testprogs:blackbox: add regression test for unsorted links in tombstones-expunge.sh
[samba.git] / testprogs / blackbox / tombstones-expunge.sh
1 #!/bin/sh
2
3 if [ $# -lt 1 ]; then
4 cat <<EOF
5 Usage: tombstones-expunge.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 undump() {
39        if test -x $BINDIR/tdbrestore;
40        then
41         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE $BINDIR/tdbrestore
42        else
43         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE
44        fi
45 }
46
47 tombstones_expunge() {
48     tmpfile=$PREFIX_ABS/$RELEASE/expected-expunge-output.txt.tmp
49     tmpldif1=$PREFIX_ABS/$RELEASE/expected-expunge-output2.txt.tmp1
50
51     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
52
53     $PYTHON $BINDIR/samba-tool domain tombstones expunge -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb --current-time=2016-07-30 --tombstone-lifetime=4 > $tmpfile
54     if [ "$?" != "0" ]; then
55         return 1
56     fi
57     diff $tmpfile $release_dir/expected-expunge-output.txt
58     if [ "$?" != "0" ]; then
59         return 1
60     fi
61
62     tmpldif2=$PREFIX_ABS/$RELEASE/expected-expunge-output2.txt.tmp2
63     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
64
65     diff $tmpldif1 $tmpldif2
66     if [ "$?" != "0" ]; then
67         return 1
68     fi
69 }
70
71 add_dangling_link() {
72     ldif=$release_dir/add-dangling-link.ldif
73     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
74     if [ "$?" != "0" ]; then
75         return 1
76     fi
77 }
78
79 add_two_more_users() {
80     ldif=$release_dir/add-two-more-users.ldif
81     TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
82     if [ "$?" != "0" ]; then
83         return 1
84     fi
85 }
86
87 add_four_more_links() {
88     ldif=$release_dir/add-four-more-links.ldif
89     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
90     if [ "$?" != "0" ]; then
91         return 1
92     fi
93 }
94
95 add_unsorted_links() {
96     ldif=$release_dir/add-unsorted-links-step1.ldif
97     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif --relax
98     if [ "$?" != "0" ]; then
99         return 1
100     fi
101     ldif=$release_dir/add-unsorted-links-step2.ldif
102     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
103     if [ "$?" != "0" ]; then
104         return 1
105     fi
106 }
107
108 remove_one_link() {
109     ldif=$release_dir/remove-one-more-link.ldif
110     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
111     if [ "$?" != "0" ]; then
112         return 1
113     fi
114 }
115
116 remove_one_user() {
117     ldif=$release_dir/remove-one-more-user.ldif
118     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
119     if [ "$?" != "0" ]; then
120         return 1
121     fi
122 }
123
124 check_match_rule_links() {
125     tmpldif=$PREFIX_ABS/$RELEASE/expected-match-rule-links.ldif.tmp
126     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted no_attrs > $tmpldif
127     diff $tmpldif $release_dir/expected-match-rule-links.ldif
128     if [ "$?" != "0" ]; then
129         return 1
130     fi
131 }
132
133 check_match_rule_links_negative() {
134     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=-131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
135 }
136
137 check_match_rule_links_overflow() {
138     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=18446744073709551617)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
139 }
140
141 check_match_rule_links_null() {
142     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=18446744\073709551617)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
143 }
144
145 check_match_rule_links_hex() {
146     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=abcd)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
147 }
148
149 check_match_rule_links_hex2() {
150     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=0xabcd)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
151 }
152
153 check_match_rule_links_decimal() {
154     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=131139216000000000.00)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
155 }
156
157 check_match_rule_links_backlink() {
158     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(memberOf:1.3.6.1.4.1.7165.4.5.2:=131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted memberOf
159 }
160
161 check_match_rule_links_notlink() {
162     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(samAccountName:1.3.6.1.4.1.7165.4.5.2:=131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted samAccountName
163 }
164
165 check_expected_after_links() {
166     tmpldif=$PREFIX_ABS/$RELEASE/expected-links-after-expunge.ldif.tmp
167     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
168     diff $tmpldif $release_dir/expected-links-after-expunge.ldif
169     if [ "$?" != "0" ]; then
170         return 1
171     fi
172 }
173
174 check_expected_after_deleted_links() {
175     tmpldif=$PREFIX_ABS/$RELEASE/expected-deleted-links-after-expunge.ldif.tmp
176     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
177     diff $tmpldif $release_dir/expected-deleted-links-after-expunge.ldif
178     if [ "$?" != "0" ]; then
179         return 1
180     fi
181 }
182
183 check_expected_after_objects() {
184     tmpldif=$PREFIX_ABS/$RELEASE/expected-objects-after-expunge.ldif.tmp
185     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(samaccountname=fred)(samaccountname=ddg)(samaccountname=usg)(samaccountname=user1)(samaccountname=user2))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted samAccountName | grep sAMAccountName > $tmpldif
186     diff $tmpldif $release_dir/expected-objects-after-expunge.ldif
187     if [ "$?" != "0" ]; then
188         return 1
189     fi
190 }
191
192 check_expected_unsorted_links() {
193     tmpldif=$PREFIX_ABS/$RELEASE/expected-unsorted-links-after-expunge.ldif.tmp
194     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(name=unsorted-g)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member > $tmpldif
195     diff $tmpldif $release_dir/expected-unsorted-links-after-expunge.ldif
196     if [ "$?" != "0" ]; then
197         return 1
198     fi
199 }
200
201 if [ -d $release_dir ]; then
202     testit $RELEASE undump
203     testit "add_two_more_users" add_two_more_users
204     testit "add_four_more_links" add_four_more_links
205     testit "add_dangling_link" add_dangling_link
206     testit "remove_one_link" remove_one_link
207     testit "remove_one_user" remove_one_user
208     testit "check_match_rule_links" check_match_rule_links
209     testit_expect_failure "check_match_rule_links_negative" check_match_rule_links_negative
210     testit_expect_failure "check_match_rule_links_overflow" check_match_rule_links_overflow
211     testit_expect_failure "check_match_rule_links_null" check_match_rule_links_null
212     testit_expect_failure "check_match_rule_links_hex" check_match_rule_links_hex
213     testit_expect_failure "check_match_rule_links_hex2" check_match_rule_links_hex2
214     testit_expect_failure "check_match_rule_links_decimal" check_match_rule_links_decimal
215     testit_expect_failure "check_match_rule_links_backlink" check_match_rule_links_backlink
216     testit_expect_failure "check_match_rule_links_notlink" check_match_rule_links_notlink
217     testit "add_unsorted_links" add_unsorted_links
218     testit "tombstones_expunge" tombstones_expunge
219     testit "check_expected_after_deleted_links" check_expected_after_deleted_links
220     testit "check_expected_after_links" check_expected_after_links
221     testit "check_expected_after_objects" check_expected_after_objects
222     testit "check_expected_unsorted_links" check_expected_unsorted_links
223 else
224     subunit_start_test $RELEASE
225     subunit_skip_test $RELEASE <<EOF
226 no test provision
227 EOF
228
229     subunit_start_test "tombstones_expunge"
230     subunit_skip_test "tombstones_expunge" <<EOF
231 no test provision
232 EOF
233 fi
234
235 if [ -d $PREFIX_ABS/${RELEASE} ]; then
236     rm -fr $PREFIX_ABS/${RELEASE}
237 fi
238
239 exit $failed