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