xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test071-dirsync (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1*e670fd5cSchristos#! /bin/sh
2*e670fd5cSchristos# $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos
16*e670fd5cSchristosecho "running defines.sh"
17*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
18*e670fd5cSchristos
19*e670fd5cSchristos# requires MSAD_URI, MSAD_SUFFIX, MSAD_ADMINDN, MSAD_ADMINPW
20*e670fd5cSchristosif test -z "$MSAD_URI"; then
21*e670fd5cSchristos	echo "No MSAD envvars set, test skipped"
22*e670fd5cSchristos	exit 0
23*e670fd5cSchristosfi
24*e670fd5cSchristosif test $SYNCPROV = syncprovno; then
25*e670fd5cSchristos	echo "Syncrepl provider overlay not available, test skipped"
26*e670fd5cSchristos	exit 0
27*e670fd5cSchristosfi
28*e670fd5cSchristos
29*e670fd5cSchristosmkdir -p $TESTDIR $DBDIR2
30*e670fd5cSchristos
31*e670fd5cSchristosURI1=$MSAD_URI
32*e670fd5cSchristosBASEDN="ou=OpenLDAPtest,$MSAD_SUFFIX"
33*e670fd5cSchristosDC=`echo $MSAD_SUFFIX | sed -e 's/dc=//' -e 's/,.*//'`
34*e670fd5cSchristos
35*e670fd5cSchristos#
36*e670fd5cSchristos# Test replication:
37*e670fd5cSchristos# - populate MSAD over ldap
38*e670fd5cSchristos# - start consumer
39*e670fd5cSchristos# - perform some modifies and deletes
40*e670fd5cSchristos# - attempt to modify the consumer (referral)
41*e670fd5cSchristos# - retrieve database over ldap and compare against expected results
42*e670fd5cSchristos#
43*e670fd5cSchristos
44*e670fd5cSchristos# Notes:
45*e670fd5cSchristos# We use a separate OU under the MSAD suffix to contain our test objects,
46*e670fd5cSchristos# since we can't just wipe out the entire directory when starting over.
47*e670fd5cSchristos# The replication search filter is thus more convoluted than would normally
48*e670fd5cSchristos# be needed. Typically it would only need (|(objectclass=user)(objectclass=group))
49*e670fd5cSchristos#
50*e670fd5cSchristos# MSAD does referential integrity by default, so to get 1-to-1 modifications
51*e670fd5cSchristos# we must add users before creating groups that reference them, and we
52*e670fd5cSchristos# should delete group memberships before deleting users. If we delete
53*e670fd5cSchristos# users first, MSAD will automatically remove them from their groups,
54*e670fd5cSchristos# but won't notify us of these changed groups.
55*e670fd5cSchristos# We could use the refint overlay to duplicate this behavior, but that's
56*e670fd5cSchristos# beyond the scope of this test.
57*e670fd5cSchristos
58*e670fd5cSchristosecho "Using ldapsearch to check that MSAD is running..."
59*e670fd5cSchristos$LDAPSEARCH -D $MSAD_ADMINDN -w $MSAD_ADMINPW -s base -b "$MSAD_SUFFIX" -H $MSAD_URI 'objectclass=*' > /dev/null 2>&1
60*e670fd5cSchristosRC=$?
61*e670fd5cSchristosif test $RC != 0 ; then
62*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
63*e670fd5cSchristos	exit $RC
64*e670fd5cSchristosfi
65*e670fd5cSchristos
66*e670fd5cSchristosecho "Using ldapdelete to delete old MSAD test tree, if any..."
67*e670fd5cSchristos$LDAPDELETE -D "$MSAD_ADMINDN" -H $MSAD_URI -w $MSAD_ADMINPW -r "$BASEDN"
68*e670fd5cSchristosRC=$?
69*e670fd5cSchristos
70*e670fd5cSchristosecho "Using ldapadd to create the test context entry in MSAD..."
71*e670fd5cSchristossed -e "s/dc=example,dc=com/$MSAD_SUFFIX/" < $LDIFDIRSYNCCP | \
72*e670fd5cSchristos	$LDAPADD -D "$MSAD_ADMINDN" -H $MSAD_URI -w $MSAD_ADMINPW > /dev/null 2>&1
73*e670fd5cSchristos
74*e670fd5cSchristosRC=$?
75*e670fd5cSchristosif test $RC != 0 ; then
76*e670fd5cSchristos	echo "ldapadd failed ($RC)!"
77*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
78*e670fd5cSchristos	exit $RC
79*e670fd5cSchristosfi
80*e670fd5cSchristos
81*e670fd5cSchristosecho "Starting consumer slapd on TCP/IP port $PORT2..."
82*e670fd5cSchristos. $CONFFILTER $BACKEND < $DIRSYNC1CONF | . $CONFDIRSYNC > $CONF2
83*e670fd5cSchristos$SLAPADD -f $CONF2 <<EOMODS
84*e670fd5cSchristosdn: $MSAD_SUFFIX
85*e670fd5cSchristosdc: $DC
86*e670fd5cSchristosobjectclass: organization
87*e670fd5cSchristosobjectclass: dcObject
88*e670fd5cSchristoso: OpenLDAP Testing
89*e670fd5cSchristos
90*e670fd5cSchristosEOMODS
91*e670fd5cSchristos$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
92*e670fd5cSchristosCONSUMERPID=$!
93*e670fd5cSchristosif test $WAIT != 0 ; then
94*e670fd5cSchristos    echo CONSUMERPID $CONSUMERPID
95*e670fd5cSchristos    read foo
96*e670fd5cSchristosfi
97*e670fd5cSchristosKILLPIDS="$KILLPIDS $CONSUMERPID"
98*e670fd5cSchristos
99*e670fd5cSchristossleep 1
100*e670fd5cSchristos
101*e670fd5cSchristosecho "Using ldapsearch to check that consumer slapd is running..."
102*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
103*e670fd5cSchristos	$LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
104*e670fd5cSchristos		'objectclass=*' > /dev/null 2>&1
105*e670fd5cSchristos	RC=$?
106*e670fd5cSchristos	if test $RC = 0 ; then
107*e670fd5cSchristos		break
108*e670fd5cSchristos	fi
109*e670fd5cSchristos	echo "Waiting 5 seconds for slapd to start..."
110*e670fd5cSchristos	sleep 5
111*e670fd5cSchristosdone
112*e670fd5cSchristos
113*e670fd5cSchristosif test $RC != 0 ; then
114*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
115*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
116*e670fd5cSchristos	exit $RC
117*e670fd5cSchristosfi
118*e670fd5cSchristos
119*e670fd5cSchristos
120*e670fd5cSchristosecho "Using ldapsearch to check that consumer received context entry..."
121*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
122*e670fd5cSchristos	$LDAPSEARCH -s base -b "$BASEDN" -H $URI2 \
123*e670fd5cSchristos		'objectclass=*' > /dev/null 2>&1
124*e670fd5cSchristos	RC=$?
125*e670fd5cSchristos	if test $RC = 0 ; then
126*e670fd5cSchristos		break
127*e670fd5cSchristos	fi
128*e670fd5cSchristos	echo "Waiting 5 seconds for syncrepl to catch up..."
129*e670fd5cSchristos	sleep 5
130*e670fd5cSchristosdone
131*e670fd5cSchristos
132*e670fd5cSchristosif test $RC != 0 ; then
133*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
134*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
135*e670fd5cSchristos	exit $RC
136*e670fd5cSchristosfi
137*e670fd5cSchristos
138*e670fd5cSchristosecho "Using ldapadd to populate MSAD..."
139*e670fd5cSchristossed -e "s/dc=example,dc=com/$BASEDN/" < $LDIFDIRSYNCNOCP | \
140*e670fd5cSchristos	$LDAPADD -D "$MSAD_ADMINDN" -H $MSAD_URI -w $MSAD_ADMINPW > /dev/null 2>&1
141*e670fd5cSchristosRC=$?
142*e670fd5cSchristosif test $RC != 0 ; then
143*e670fd5cSchristos	echo "ldapadd failed ($RC)!"
144*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
145*e670fd5cSchristos	exit $RC
146*e670fd5cSchristosfi
147*e670fd5cSchristos
148*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
149*e670fd5cSchristossleep $SLEEP1
150*e670fd5cSchristos
151*e670fd5cSchristosecho "Using ldapmodify to modify provider directory..."
152*e670fd5cSchristos
153*e670fd5cSchristos#
154*e670fd5cSchristos# Do some modifications
155*e670fd5cSchristos#
156*e670fd5cSchristos
157*e670fd5cSchristos$LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
158*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
159*e670fd5cSchristosdn: cn=James A Jones 1, ou=Alumni Association, ou=People, $BASEDN
160*e670fd5cSchristoschangetype: modify
161*e670fd5cSchristosadd: carLicense
162*e670fd5cSchristoscarLicense: Orange Juice
163*e670fd5cSchristos-
164*e670fd5cSchristosdelete: sn
165*e670fd5cSchristossn: Jones
166*e670fd5cSchristos-
167*e670fd5cSchristosadd: sn
168*e670fd5cSchristossn: Jones
169*e670fd5cSchristos
170*e670fd5cSchristosdn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, $BASEDN
171*e670fd5cSchristoschangetype: modify
172*e670fd5cSchristosreplace: carLicense
173*e670fd5cSchristoscarLicense: Iced Tea
174*e670fd5cSchristoscarLicense: Mad Dog 20/20
175*e670fd5cSchristos
176*e670fd5cSchristosdn: cn=ITD Staff,ou=Groups,$BASEDN
177*e670fd5cSchristoschangetype: modify
178*e670fd5cSchristosdelete: uniquemember
179*e670fd5cSchristosuniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, $BASEDN
180*e670fd5cSchristosuniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, $BASEDN
181*e670fd5cSchristos-
182*e670fd5cSchristosadd: uniquemember
183*e670fd5cSchristosuniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, $BASEDN
184*e670fd5cSchristosuniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, $BASEDN
185*e670fd5cSchristos
186*e670fd5cSchristosdn: cn=All Staff,ou=Groups,$BASEDN
187*e670fd5cSchristoschangetype: modify
188*e670fd5cSchristosreplace: description
189*e670fd5cSchristosdescription: The whole universe
190*e670fd5cSchristos-
191*e670fd5cSchristosdelete: member
192*e670fd5cSchristosmember: cn=James A Jones 2,ou=Information Technology Division,ou=People,$BASEDN
193*e670fd5cSchristos
194*e670fd5cSchristosdn: cn=Gern Jensen, ou=Information Technology Division, ou=People, $BASEDN
195*e670fd5cSchristoschangetype: add
196*e670fd5cSchristosobjectclass: inetorgperson
197*e670fd5cSchristosobjectclass: domainrelatedobject
198*e670fd5cSchristoscn: Gern Jensen
199*e670fd5cSchristossn: Jensen
200*e670fd5cSchristosuid: gjensen
201*e670fd5cSchristostitle: Chief Investigator, ITD
202*e670fd5cSchristospostaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
203*e670fd5cSchristosseealso: cn=All Staff, ou=Groups, $BASEDN
204*e670fd5cSchristoscarLicense: Coffee
205*e670fd5cSchristoshomepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
206*e670fd5cSchristosdescription: Very odd
207*e670fd5cSchristosfacsimiletelephonenumber: +1 313 555 7557
208*e670fd5cSchristostelephonenumber: +1 313 555 8343
209*e670fd5cSchristosmail: gjensen@mailgw.example.com
210*e670fd5cSchristoshomephone: +1 313 555 8844
211*e670fd5cSchristosassociateddomain: test.openldap.org
212*e670fd5cSchristos
213*e670fd5cSchristosdn: ou=Retired, ou=People, $BASEDN
214*e670fd5cSchristoschangetype: add
215*e670fd5cSchristosobjectclass: organizationalUnit
216*e670fd5cSchristosou: Retired
217*e670fd5cSchristos
218*e670fd5cSchristosdn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, $BASEDN
219*e670fd5cSchristoschangetype: add
220*e670fd5cSchristosobjectclass: inetorgperson
221*e670fd5cSchristosobjectclass: domainrelatedobject
222*e670fd5cSchristoscn: Rosco P. Coltrane
223*e670fd5cSchristossn: Coltrane
224*e670fd5cSchristosuid: rosco
225*e670fd5cSchristosassociateddomain: test.openldap.org
226*e670fd5cSchristos
227*e670fd5cSchristosdn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, $BASEDN
228*e670fd5cSchristoschangetype: modrdn
229*e670fd5cSchristosnewrdn: cn=Rosco P. Coltrane
230*e670fd5cSchristosdeleteoldrdn: 1
231*e670fd5cSchristosnewsuperior: ou=Retired, ou=People, $BASEDN
232*e670fd5cSchristos
233*e670fd5cSchristosdn: ou=testdomain1,$BASEDN
234*e670fd5cSchristoschangetype: modrdn
235*e670fd5cSchristosnewrdn: ou=itsdomain1
236*e670fd5cSchristosdeleteoldrdn: 1
237*e670fd5cSchristos
238*e670fd5cSchristosdn: ou=itsdomain1,$BASEDN
239*e670fd5cSchristoschangetype: modify
240*e670fd5cSchristosreplace: description
241*e670fd5cSchristosdescription: Example, Inc. ITS test domain
242*e670fd5cSchristos
243*e670fd5cSchristosEOMODS
244*e670fd5cSchristos
245*e670fd5cSchristosRC=$?
246*e670fd5cSchristosif test $RC != 0 ; then
247*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
248*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
249*e670fd5cSchristos	exit $RC
250*e670fd5cSchristosfi
251*e670fd5cSchristos
252*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
253*e670fd5cSchristossleep $SLEEP1
254*e670fd5cSchristos
255*e670fd5cSchristosecho "Performing modrdn alone on the provider..."
256*e670fd5cSchristos$LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
257*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
258*e670fd5cSchristosdn: ou=testdomain2,$BASEDN
259*e670fd5cSchristoschangetype: modrdn
260*e670fd5cSchristosnewrdn: ou=itsdomain2
261*e670fd5cSchristosdeleteoldrdn: 1
262*e670fd5cSchristos
263*e670fd5cSchristosEOMODS
264*e670fd5cSchristos
265*e670fd5cSchristosRC=$?
266*e670fd5cSchristosif test $RC != 0 ; then
267*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
268*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
269*e670fd5cSchristos	exit $RC
270*e670fd5cSchristosfi
271*e670fd5cSchristos
272*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
273*e670fd5cSchristossleep $SLEEP1
274*e670fd5cSchristos
275*e670fd5cSchristosecho "Performing modify alone on the provider..."
276*e670fd5cSchristos$LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
277*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
278*e670fd5cSchristosdn: ou=itsdomain2,$BASEDN
279*e670fd5cSchristoschangetype: modify
280*e670fd5cSchristosreplace: description
281*e670fd5cSchristosdescription: Example, Inc. itsdomain2 test domain
282*e670fd5cSchristos
283*e670fd5cSchristosEOMODS
284*e670fd5cSchristos
285*e670fd5cSchristosRC=$?
286*e670fd5cSchristosif test $RC != 0 ; then
287*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
288*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
289*e670fd5cSchristos	exit $RC
290*e670fd5cSchristosfi
291*e670fd5cSchristos
292*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
293*e670fd5cSchristossleep $SLEEP1
294*e670fd5cSchristos
295*e670fd5cSchristosecho "Performing larger modify on the provider..."
296*e670fd5cSchristos$LDAPMODIFY -v -H $MSAD_URI -D "$MSAD_ADMINDN" -w $MSAD_ADMINPW > \
297*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
298*e670fd5cSchristosdn: cn=James A Jones 2, ou=Information Technology Division, ou=People, $BASEDN
299*e670fd5cSchristoschangetype: delete
300*e670fd5cSchristos
301*e670fd5cSchristosdn: cn=Alumni Assoc Staff,ou=Groups,$BASEDN
302*e670fd5cSchristoschangetype: modify
303*e670fd5cSchristosreplace: description
304*e670fd5cSchristosdescription: blablabla
305*e670fd5cSchristos-
306*e670fd5cSchristosreplace: member
307*e670fd5cSchristosmember: cn=Manager,$BASEDN
308*e670fd5cSchristosmember: cn=Dorothy Stevens,ou=Alumni Association,ou=People,$BASEDN
309*e670fd5cSchristosmember: cn=James A Jones 1,ou=Alumni Association,ou=People,$BASEDN
310*e670fd5cSchristosmember: cn=Jane Doe,ou=Alumni Association,ou=People,$BASEDN
311*e670fd5cSchristosmember: cn=Jennifer Smith,ou=Alumni Association,ou=People,$BASEDN
312*e670fd5cSchristosmember: cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN
313*e670fd5cSchristosmember: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
314*e670fd5cSchristos
315*e670fd5cSchristosEOMODS
316*e670fd5cSchristos
317*e670fd5cSchristosRC=$?
318*e670fd5cSchristosif test $RC != 0 ; then
319*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
320*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
321*e670fd5cSchristos	exit $RC
322*e670fd5cSchristosfi
323*e670fd5cSchristos
324*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
325*e670fd5cSchristossleep $SLEEP1
326*e670fd5cSchristos
327*e670fd5cSchristosOPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp"
328*e670fd5cSchristos
329*e670fd5cSchristosecho "Using ldapsearch to read all the entries from the provider..."
330*e670fd5cSchristos$LDAPSEARCH -D $MSAD_ADMINDN -w $MSAD_ADMINPW -S "" -H $MSAD_URI -b "$MSAD_SUFFIX" -E \!dirsync=0/0 -o ldif_wrap=120 \
331*e670fd5cSchristos	'(associatedDomain=test.openldap.org)' > $PROVIDEROUT 2>&1
332*e670fd5cSchristosRC=$?
333*e670fd5cSchristos
334*e670fd5cSchristosif test $RC != 0 ; then
335*e670fd5cSchristos	echo "ldapsearch failed at provider ($RC)!"
336*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
337*e670fd5cSchristos	exit $RC
338*e670fd5cSchristosfi
339*e670fd5cSchristos
340*e670fd5cSchristosecho "Using ldapsearch to read all the entries from the consumer..."
341*e670fd5cSchristos$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 -o ldif_wrap=120 \
342*e670fd5cSchristos	'(objectclass=*)' > $CONSUMEROUT 2>&1
343*e670fd5cSchristosRC=$?
344*e670fd5cSchristos
345*e670fd5cSchristosif test $RC != 0 ; then
346*e670fd5cSchristos	echo "ldapsearch failed at consumer ($RC)!"
347*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
348*e670fd5cSchristos	exit $RC
349*e670fd5cSchristosfi
350*e670fd5cSchristos
351*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
352*e670fd5cSchristos
353*e670fd5cSchristosecho "Filtering provider results..."
354*e670fd5cSchristos$LDIFFILTER -s a < $PROVIDEROUT | sed -e 's/CN=/cn=/g' -e 's/OU=/ou=/g' -e 's/DC=/dc=/g' > $PROVIDERFLT
355*e670fd5cSchristosecho "Filtering consumer results..."
356*e670fd5cSchristos$LDIFFILTER -s a < $CONSUMEROUT > $CONSUMERFLT
357*e670fd5cSchristos
358*e670fd5cSchristosecho "Comparing retrieved entries from provider and consumer..."
359*e670fd5cSchristos$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT
360*e670fd5cSchristos
361*e670fd5cSchristosif test $? != 0 ; then
362*e670fd5cSchristos	echo "test failed - provider and consumer databases differ"
363*e670fd5cSchristos	exit 1
364*e670fd5cSchristosfi
365*e670fd5cSchristos
366*e670fd5cSchristosecho ">>>>> Test succeeded"
367*e670fd5cSchristos
368*e670fd5cSchristostest $KILLSERVERS != no && wait
369*e670fd5cSchristos
370*e670fd5cSchristosexit 0
371