xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test043-delta-syncrepl (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2014 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
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19if test $SYNCPROV = syncprovno; then
20	echo "Syncrepl provider overlay not available, test skipped"
21	exit 0
22fi
23if test $ACCESSLOG = accesslogno; then
24	echo "Accesslog overlay not available, test skipped"
25	exit 0
26fi
27if test $BACKEND = ldif ; then
28	# Onelevel search does not return entries in order of creation or CSN.
29	echo "$BACKEND backend unsuitable for syncprov logdb, test skipped"
30	exit 0
31fi
32
33mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2
34
35#
36# Test replication:
37# - start provider
38# - start consumer
39# - populate over ldap
40# - perform some modifies and deleted
41# - attempt to modify the consumer (referral or chain)
42# - retrieve database over ldap and compare against expected results
43#
44
45echo "Starting provider slapd on TCP/IP port $PORT1..."
46. $CONFFILTER $BACKEND $MONITORDB < $DSRMASTERCONF > $CONF1
47$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
48PID=$!
49if test $WAIT != 0 ; then
50    echo PID $PID
51    read foo
52fi
53KILLPIDS="$PID"
54
55sleep 1
56
57echo "Using ldapsearch to check that provider slapd is running..."
58for i in 0 1 2 3 4 5; do
59	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
60		'objectclass=*' > /dev/null 2>&1
61	RC=$?
62	if test $RC = 0 ; then
63		break
64	fi
65	echo "Waiting 5 seconds for slapd to start..."
66	sleep 5
67done
68
69if test $RC != 0 ; then
70	echo "ldapsearch failed ($RC)!"
71	test $KILLSERVERS != no && kill -HUP $KILLPIDS
72	exit $RC
73fi
74
75echo "Using ldapadd to create the context prefix entries in the provider..."
76$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
77	$LDIFORDEREDCP > /dev/null 2>&1
78RC=$?
79if test $RC != 0 ; then
80	echo "ldapadd failed ($RC)!"
81	test $KILLSERVERS != no && kill -HUP $KILLPIDS
82	exit $RC
83fi
84
85echo "Starting consumer slapd on TCP/IP port $PORT2..."
86. $CONFFILTER $BACKEND $MONITORDB < $DSRSLAVECONF > $CONF2
87$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
88SLAVEPID=$!
89if test $WAIT != 0 ; then
90    echo SLAVEPID $SLAVEPID
91    read foo
92fi
93KILLPIDS="$KILLPIDS $SLAVEPID"
94
95sleep 1
96
97echo "Using ldapsearch to check that consumer slapd is running..."
98for i in 0 1 2 3 4 5; do
99	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
100		'objectclass=*' > /dev/null 2>&1
101	RC=$?
102	if test $RC = 0 ; then
103		break
104	fi
105	echo "Waiting 5 seconds for slapd to start..."
106	sleep 5
107done
108
109if test $RC != 0 ; then
110	echo "ldapsearch failed ($RC)!"
111	test $KILLSERVERS != no && kill -HUP $KILLPIDS
112	exit $RC
113fi
114
115echo "Using ldapadd to populate the provider directory..."
116$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
117	$LDIFORDEREDNOCP > /dev/null 2>&1
118RC=$?
119if test $RC != 0 ; then
120	echo "ldapadd failed ($RC)!"
121	test $KILLSERVERS != no && kill -HUP $KILLPIDS
122	exit $RC
123fi
124
125echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
126sleep $SLEEP1
127
128echo "Stopping the provider, sleeping 10 seconds and restarting it..."
129kill -HUP "$PID"
130sleep 10
131echo "RESTART" >> $LOG1
132$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
133PID=$!
134if test $WAIT != 0 ; then
135    echo PID $PID
136    read foo
137fi
138KILLPIDS="$PID $SLAVEPID"
139
140sleep 1
141
142echo "Using ldapsearch to check that provider slapd is running..."
143for i in 0 1 2 3 4 5; do
144	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
145		'objectclass=*' > /dev/null 2>&1
146	RC=$?
147	if test $RC = 0 ; then
148		break
149	fi
150	echo "Waiting 5 seconds for slapd to start..."
151	sleep 5
152done
153
154if test $RC != 0 ; then
155	echo "ldapsearch failed ($RC)!"
156	test $KILLSERVERS != no && kill -HUP $KILLPIDS
157	exit $RC
158fi
159
160echo "Using ldapmodify to modify provider directory..."
161
162#
163# Do some modifications
164#
165
166$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
167	$TESTOUT 2>&1 << EOMODS
168dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
169changetype: modify
170add: drink
171drink: Orange Juice
172-
173delete: sn
174sn: Jones
175-
176add: sn
177sn: Jones
178
179dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
180changetype: modify
181replace: drink
182drink: Iced Tea
183
184dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
185changetype: modify
186delete: uniquemember
187uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
188uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
189-
190add: uniquemember
191uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
192uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
193
194dn: cn=All Staff,ou=Groups,dc=example,dc=com
195changetype: modify
196delete: description
197
198dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
199changetype: add
200objectclass: OpenLDAPperson
201cn: Gern Jensen
202sn: Jensen
203uid: gjensen
204title: Chief Investigator, ITD
205postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
206seealso: cn=All Staff, ou=Groups, dc=example,dc=com
207drink: Coffee
208homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
209description: Very odd
210facsimiletelephonenumber: +1 313 555 7557
211telephonenumber: +1 313 555 8343
212mail: gjensen@mailgw.example.com
213homephone: +1 313 555 8844
214
215dn: ou=Retired, ou=People, dc=example,dc=com
216changetype: add
217objectclass: organizationalUnit
218ou: Retired
219
220dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
221changetype: add
222objectclass: OpenLDAPperson
223cn: Rosco P. Coltrane
224sn: Coltrane
225uid: rosco
226description: Fat tycoon
227
228dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
229changetype: modrdn
230newrdn: cn=Rosco P. Coltrane
231deleteoldrdn: 1
232newsuperior: ou=Retired, ou=People, dc=example,dc=com
233
234dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
235changetype: delete
236
237EOMODS
238RC=$?
239if test $RC != 0 ; then
240	echo "ldapmodify failed ($RC)!"
241	test $KILLSERVERS != no && kill -HUP $KILLPIDS
242	exit $RC
243fi
244
245echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
246sleep $SLEEP1
247
248echo "Using ldapsearch to read all the entries from the provider..."
249$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
250	'objectclass=*' \* + > $MASTEROUT 2>&1
251RC=$?
252
253if test $RC != 0 ; then
254	echo "ldapsearch failed at provider ($RC)!"
255	test $KILLSERVERS != no && kill -HUP $KILLPIDS
256	exit $RC
257fi
258
259echo "Using ldapsearch to read all the entries from the consumer..."
260$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
261	'objectclass=*' \* + > $SLAVEOUT 2>&1
262RC=$?
263
264if test $RC != 0 ; then
265	echo "ldapsearch failed at consumer ($RC)!"
266	test $KILLSERVERS != no && kill -HUP $KILLPIDS
267	exit $RC
268fi
269
270echo "Filtering provider results..."
271$LDIFFILTER -s bdb=a,hdb=a < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
272echo "Filtering consumer results..."
273$LDIFFILTER -s bdb=a,hdb=a < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
274
275echo "Comparing retrieved entries from provider and consumer..."
276$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
277
278if test $? != 0 ; then
279	echo "test failed - provider and consumer databases differ"
280	test $KILLSERVERS != no && kill -HUP $KILLPIDS
281	exit 1
282fi
283
284echo "Stopping consumer to test recovery..."
285kill -HUP $SLAVEPID
286sleep 10
287
288echo "Modifying more entries on the provider..."
289$LDAPMODIFY -v -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
290	$TESTOUT 2>&1 << EOMODS
291dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
292changetype: delete
293
294dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
295changetype: modify
296add: drink
297drink: Mad Dog 20/20
298
299dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
300changetype: add
301objectclass: OpenLDAPperson
302sn: Coltrane
303uid: rosco
304cn: Rosco P. Coltrane
305
306dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com
307changetype: modify
308replace: drink
309
310dn: cn=All Staff,ou=Groups,dc=example,dc=com
311changetype: modrdn
312newrdn: cn=Some Staff
313deleteoldrdn: 1
314
315EOMODS
316
317echo "Restarting consumer..."
318echo "RESTART" >> $LOG2
319$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
320SLAVEPID=$!
321if test $WAIT != 0 ; then
322    echo SLAVEPID $SLAVEPID
323    read foo
324fi
325KILLPIDS="$PID $SLAVEPID"
326
327echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
328sleep $SLEEP1
329
330if test ! $BACKLDAP = "ldapno" ; then
331	echo "Try updating the consumer slapd..."
332	$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
333		$TESTOUT 2>&1 << EOMODS
334dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
335changetype: modify
336add: description
337description: This write must fail because directed to a shadow context,
338description: unless the chain overlay is configured appropriately ;)
339
340EOMODS
341
342	RC=$?
343	if test $RC != 0 ; then
344		echo "ldapmodify failed ($RC)!"
345		test $KILLSERVERS != no && kill -HUP $KILLPIDS
346		exit $RC
347	fi
348
349	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
350	sleep $SLEEP1
351fi
352
353echo "Using ldapsearch to read all the entries from the provider..."
354$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
355	'objectclass=*' \* + > $MASTEROUT 2>&1
356RC=$?
357
358if test $RC != 0 ; then
359	echo "ldapsearch failed at provider ($RC)!"
360	test $KILLSERVERS != no && kill -HUP $KILLPIDS
361	exit $RC
362fi
363
364echo "Using ldapsearch to read all the entries from the consumer..."
365$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
366	'objectclass=*' \* + > $SLAVEOUT 2>&1
367RC=$?
368
369if test $RC != 0 ; then
370	echo "ldapsearch failed at consumer ($RC)!"
371	test $KILLSERVERS != no && kill -HUP $KILLPIDS
372	exit $RC
373fi
374
375test $KILLSERVERS != no && kill -HUP $KILLPIDS
376
377echo "Filtering provider results..."
378$LDIFFILTER -s bdb=a,hdb=a < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
379echo "Filtering consumer results..."
380$LDIFFILTER -s bdb=a,hdb=a < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
381
382echo "Comparing retrieved entries from provider and consumer..."
383$CMP $MASTERFLT $SLAVEFLT > $CMPOUT
384
385if test $? != 0 ; then
386	echo "test failed - provider and consumer databases differ"
387	exit 1
388fi
389
390echo ">>>>> Test succeeded"
391
392test $KILLSERVERS != no && wait
393
394exit 0
395