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