]> git.sur5r.net Git - openldap/blob - tests/data/regressions/its8521/its8521
ITS#8521 - Add testcase for this regression
[openldap] / tests / data / regressions / its8521 / its8521
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2016 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $SYNCPROV = syncprovno; then
20         echo "Syncrepl provider overlay not available, test skipped"
21         exit 0
22 fi
23
24 echo "This test tracks a case where a consumer fails to replicate from the provider"
25 echo "when the provider is dynamically configured for replication."
26 echo "See http://www.openldap.org/its/index.cgi/?findid=8521 for more information."
27
28 PRODIR=$TESTDIR/pro
29 CONDIR=$TESTDIR/con1
30 CFPRO=$PRODIR/slapd.d
31 CFCON=$CONDIR/slapd.d
32
33 mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $PRODIR $CONDIR $CFPRO $CFCON
34
35 $SLAPPASSWD -g -n >$CONFIGPWF
36
37 ITS=8521
38 ITSDIR=$DATADIR/regressions/its$ITS
39
40 echo "Starting provider slapd on TCP/IP port $PORT1..."
41 . $CONFFILTER $BACKEND $MONITORDB < $ITSDIR/slapd-provider.ldif > $CONFLDIF
42 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
43 $SLAPD -F $CFPRO -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
44 PID=$!
45 if test $WAIT != 0 ; then
46         echo PID $PID
47         read foo
48 fi
49 KILLPIDS="$PID"
50
51 sleep 1
52
53 echo "Using ldapsearch to check that provider slapd is running..."
54 for i in 0 1 2 3 4 5; do
55         $LDAPSEARCH -s base -b "" -H $URI1 \
56                 'objectclass=*' > /dev/null 2>&1
57         RC=$?
58         if test $RC = 0 ; then
59                 break
60         fi
61         echo "Waiting 5 seconds for slapd to start..."
62         sleep 5
63 done
64
65 if test $RC != 0 ; then
66         echo "ldapsearch failed ($RC)!"
67         test $KILLSERVERS != no && kill -HUP $KILLPIDS
68         exit $RC
69 fi
70
71 echo "Starting consumer slapd on TCP/IP port $PORT2..."
72 . $CONFFILTER $BACKEND $MONITORDB < $ITSDIR/slapd-consumer.ldif > $CONFLDIF
73 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
74 $SLAPD -F $CFCON -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
75 SLAVEPID=$!
76 if test $WAIT != 0 ; then
77         echo SLAVEPID $SLAVEPID
78         read foo
79 fi
80 KILLPIDS="$KILLPIDS $SLAVEPID"
81
82 sleep 1
83
84 echo "Using ldapsearch to check that consumer slapd is running..."
85 for i in 0 1 2 3 4 5; do
86         $LDAPSEARCH -s base -b "" -H $URI2 \
87                 'objectclass=*' > /dev/null 2>&1
88         RC=$?
89         if test $RC = 0 ; then
90                 break
91         fi
92         echo "Waiting 5 seconds for slapd to start..."
93         sleep 5
94 done
95
96 if test $RC != 0 ; then
97         echo "ldapsearch failed ($RC)!"
98         test $KILLSERVERS != no && kill -HUP $KILLPIDS
99         exit $RC
100 fi
101
102 echo "Setting serverID on provider..."
103 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
104 dn: cn=config
105 changetype: modify
106 add: olcServerId
107 olcServerId: 1
108 EOF
109 RC=$?
110
111 if test $RC != 0 ; then
112         echo "ldapmodify failed ($RC)!"
113         test $KILLSERVERS != no && kill -HUP $KILLPIDS
114         exit $RC
115 fi
116
117 echo "Populating database on provider..."
118 $LDAPADD -D $MANAGERDN -H $URI1 -w $PASSWD << EOMODS >> $TESTOUT 2>&1
119 dn: dc=example,dc=com
120 changetype: add
121 objectClass: domain
122 objectClass: top
123 dc: example
124
125 dn: ou=LDAPRoles,dc=example,dc=com
126 objectClass: top
127 objectClass: organizationalUnit
128 ou: LDAPRoles
129
130 dn: dc=users,dc=example,dc=com
131 changetype: add
132 dc: users
133 objectClass: domain
134 objectClass: top
135
136 dn: cn=Johndoe,dc=users,dc=example,dc=com
137 changetype: add
138 objectClass: person
139 objectClass: top
140 sn: John Doe
141 cn: Johndoe
142
143 dn: cn=replicator,ou=LDAPRoles,dc=example,dc=com
144 objectClass: top
145 objectClass: simpleSecurityObject
146 objectClass: organizationalRole
147 userPassword: secret
148 cn: replicator
149 EOMODS
150
151 RC=$?
152 if test $RC != 0 ; then
153         echo "ldapadd failed ($RC)!"
154         test $KILLSERVERS != no && kill -HUP $KILLPIDS
155         exit $RC
156 fi
157
158 if [ "$SYNCPROV" = syncprovmod ]; then
159         echo "Configuring syncprov module on the provider..."
160         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
161 dn: cn=module,cn=config
162 objectClass: olcModuleList
163 cn: module
164 olcModulePath: $TESTWD/../servers/slapd/overlays
165 olcModuleLoad: syncprov.la
166 EOF
167         RC=$?
168         if test $RC != 0 ; then
169                 echo "ldapadd failed for moduleLoad ($RC)!"
170                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
171                 exit $RC
172         fi
173 fi
174
175 echo "Configuring replication on the provider..."
176 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
177 dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
178 changetype: add
179 objectClass: olcOverlayConfig
180 objectClass: olcConfig
181 objectClass: top
182 objectClass: olcSyncprovConfig
183 olcOverlay: syncprov
184 olcSpSessionLog: 10000
185 olcSpCheckpoint: 100 10
186
187 dn: olcDatabase={1}$BACKEND,cn=config
188 changetype: modify
189 add: olcLimits
190 olcLimits: dn.exact="cn=replicator,ou=LDAPRoles,dc=example,dc=com"
191   time.soft=unlimited time.hard=unlimited size.soft=unlimited
192   size.hard=unlimited
193
194 dn: olcDatabase={1}$BACKEND,cn=config
195 changetype: modify
196 replace: olcAccess
197 olcAccess: {0}to dn.subtree="dc=example,dc=com"  by self write
198   by dn.exact="cn=replicator,ou=LDAPRoles,dc=example,dc=com" read
199   by anonymous auth by * read
200 EOF
201
202 RC=$?
203 if test $RC != 0 ; then
204         echo "ldapmodify failed ($RC)!"
205         test $KILLSERVERS != no && kill -HUP $KILLPIDS
206         exit $RC
207 fi
208
209 echo "Configuring replication on the consumer..."
210 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
211 dn: olcDatabase={1}$BACKEND,cn=config
212 changetype: modify
213 add: olcSyncrepl
214 olcSyncrepl: rid=100 provider=$URI1 bindmethod=simple
215   binddn="cn=replicator,ou=LDAPRoles,dc=example,dc=com" credentials=secret
216   type=refreshOnly searchbase="dc=example,dc=com" filter="(objectclass=*)"
217   scope=sub schemachecking=on retry="5 10 60 +" sizeLimit=unlimited
218   timelimit=unlimited
219 -
220
221 EOF
222 RC=$?
223 if test $RC != 0 ; then
224   echo "ldapmodify failed for olcSyncrepl configuration ($RC)!"
225   test $KILLSERVERS != no && kill -HUP $KILLPIDS
226   exit $RC
227 fi
228
229 #### See if restarting provider makes any differnce (It doesn't) ####
230 echo "Stopping provider to test recovery..."
231 kill -INT $PID
232 sleep 10
233
234 echo "Restarting provider..."
235 echo "RESTART" >> $LOG1
236 $SLAPD -F $CFPRO -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
237 PID=$!
238 if test $WAIT != 0 ; then
239     echo PID $PID
240     read foo
241 fi
242 KILLPIDS="$PID $SLAVEPID"
243
244 sleep 1
245
246 echo "Using ldapsearch to check that provider slapd is running..."
247 for i in 0 1 2 3 4 5; do
248         $LDAPSEARCH -s base -b "" -H $URI1 \
249                 'objectclass=*' > /dev/null 2>&1
250         RC=$?
251         if test $RC = 0 ; then
252                 break
253         fi
254         echo "Waiting 5 seconds for slapd to start..."
255         sleep 5
256 done
257
258 if test $RC != 0 ; then
259         echo "ldapsearch failed ($RC)!"
260         test $KILLSERVERS != no && kill -HUP $KILLPIDS
261         exit $RC
262 fi
263
264 #### END TEST LINES ####
265
266 #### See if restarting consumer makes any differnce (It doesn't) ####
267 echo "Stopping consumer to test recovery..."
268 kill -INT $SLAVEPID
269 sleep 10
270
271 echo "Restarting consumer..."
272 echo "RESTART" >> $LOG2
273 $SLAPD -F $CFCON -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
274 SLAVEPID=$!
275 if test $WAIT != 0 ; then
276     echo SLAVEPID $SLAVEPID
277     read foo
278 fi
279 KILLPIDS="$PID $SLAVEPID"
280
281 sleep 1
282
283 echo "Using ldapsearch to check that consumer slapd is running..."
284 for i in 0 1 2 3 4 5; do
285         $LDAPSEARCH -s base -b "" -H $URI2 \
286                 'objectclass=*' > /dev/null 2>&1
287         RC=$?
288         if test $RC = 0 ; then
289                 break
290         fi
291         echo "Waiting 5 seconds for slapd to start..."
292         sleep 5
293 done
294
295 if test $RC != 0 ; then
296         echo "ldapsearch failed ($RC)!"
297         test $KILLSERVERS != no && kill -HUP $KILLPIDS
298         exit $RC
299 fi
300
301 echo "Sleeping 30 seconds to allow replication to initiate..."
302 sleep 30
303 #### END TEST LINES ####
304
305 echo "Using ldapsearch to read all the entries from the provider..."
306 $LDAPSEARCH -S "" -D $MANAGERDN -w $PASSWD -b "$BASEDN" -H $URI1 \
307         '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
308 RC=$?
309
310 if test $RC != 0 ; then
311         echo "ldapsearch failed at provider ($RC)!"
312         test $KILLSERVERS != no && kill -HUP $KILLPIDS
313         exit $RC
314 fi
315
316 echo "Using ldapsearch to read all the entries from the consumer..."
317 $LDAPSEARCH -S "" -D $MANAGERDN -w $PASSWD -b "$BASEDN" -H $URI2 \
318         '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
319 RC=$?
320
321 if test $RC != 0 ; then
322         echo "ldapsearch failed at consumer ($RC)!"
323         test $KILLSERVERS != no && kill -HUP $KILLPIDS
324         exit $RC
325 fi
326
327 test $KILLSERVERS != no && kill -HUP $KILLPIDS
328
329 echo "Filtering provider results..."
330 $LDIFFILTER < $MASTEROUT > $MASTERFLT
331 echo "Filtering consumer results..."
332 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
333
334 echo "Comparing retrieved entries from provider and consumer..."
335 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
336
337 if test $? != 0 ; then
338         echo "test failed - provider and consumer databases differ"
339         exit 1
340 fi
341
342 echo
343 echo ">>>>> Test succeeded"
344
345 test $KILLSERVERS != no && wait
346
347 exit 0