test023-refint revision 1.1.1.2
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test023-refint,v 1.10.2.6 2009/01/22 00:01:19 kurt Exp
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 2004-2009 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
16if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then
17	echo "Test does not support $BACKEND"
18	exit 0
19fi
20
21echo "running defines.sh"
22. $SRCDIR/scripts/defines.sh
23
24if test $REFINT = refintno; then 
25	echo "Referential Integrity overlay not available, test skipped"
26	exit 0
27fi 
28
29mkdir -p $TESTDIR $DBDIR1
30
31echo "Running slapadd to build slapd database..."
32. $CONFFILTER $BACKEND $MONITORDB < $REFINTCONF > $CONF1
33$SLAPADD -f $CONF1 -l $LDIFREFINT
34RC=$?
35if test $RC != 0 ; then
36	echo "slapadd failed ($RC)!"
37	exit $RC
38fi
39
40echo "Starting slapd on TCP/IP port $PORT1..."
41$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
42PID=$!
43if test $WAIT != 0 ; then
44    echo PID $PID
45    read foo
46fi
47KILLPIDS="$PID"
48
49sleep 1
50
51echo "Testing slapd referential integrity operations..."
52for i in 0 1 2 3 4 5; do
53	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
54		'objectclass=*' > /dev/null 2>&1
55	RC=$?
56	if test $RC = 0 ; then
57		break
58	fi
59	echo "Waiting 5 seconds for slapd to start..."
60	sleep 5
61done
62
63if test $RC != 0 ; then
64	echo "ldapsearch failed ($RC)!"
65	test $KILLSERVERS != no && kill -HUP $KILLPIDS
66	exit $RC
67fi
68
69echo "Searching unmodified database..."
70
71$LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
72RC=$?
73if test $RC != 0 ; then
74	echo "ldapsearch failed ($RC)!"
75	test $KILLSERVERS != no && kill -HUP $KILLPIDS
76	exit $RC
77fi
78
79$EGREP_CMD "(manager|secretary):" $SEARCHOUT | sed "s/george/foster/g" | \
80	sort > $TESTOUT 2>&1
81
82echo "Testing modrdn..."
83$LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD > \
84	/dev/null 2>&1 'uid=george,ou=users,o=refint' 'uid=foster'
85#$LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD  \
86#	'uid=george,ou=users,o=refint' 'uid=foster'
87
88RC=$?
89if test $RC != 0 ; then
90	echo "ldapmodrdn failed ($RC)!"
91	test $KILLSERVERS != no && kill -HUP $KILLPIDS
92	exit $RC
93fi
94
95sleep 1;
96
97echo "Using ldapsearch to check dependents new rdn..."
98
99$LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
100
101RC=$?
102	if test $RC != 0 ; then
103	echo "ldapsearch failed ($RC)!"
104	test $KILLSERVERS != no && kill -HUP $KILLPIDS
105	exit $RC
106fi
107
108$EGREP_CMD "(manager|secretary):" $SEARCHOUT | sort > $SEARCHFLT 2>&1
109
110echo "Comparing ldapsearch results against original..."
111$CMP $TESTOUT $SEARCHFLT > $CMPOUT
112
113if test $? != 0 ; then
114	echo "comparison failed - modify operations did not complete correctly"
115	test $KILLSERVERS != no && kill -HUP $KILLPIDS
116	exit 1
117fi
118
119echo "Testing delete..."
120$LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
121	$TESTOUT 2>&1 << EDEL
122version: 1
123dn: uid=foster,ou=users,o=refint
124changetype: delete
125EDEL
126
127RC=$?
128if test $RC != 0 ; then
129	echo "ldapmodify failed ($RC)!"
130	test $KILLSERVERS != no && kill -HUP $KILLPIDS
131	exit $RC
132fi
133
134sleep 1;
135
136echo "Using ldapsearch to verify dependents have been deleted..."
137$LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 > $SEARCHOUT 2>&1
138
139RC=$?
140if test $RC != 0 ; then
141	echo "ldapsearch failed ($RC)!"
142	test $KILLSERVERS != no && kill -HUP $KILLPIDS
143	exit $RC
144fi
145
146$EGREP_CMD "(manager|secretary):" $SEARCHOUT > $SEARCHFLT 2>&1
147
148RC=`grep -c foster $SEARCHFLT`
149if test $RC != 0 ; then
150	echo "dependent modify failed - dependents were not deleted"
151	test $KILLSERVERS != no && kill -HUP $KILLPIDS
152	exit 1
153fi
154
155echo "Additional test records..."
156
157$LDAPADD -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
158	$TESTOUT 2>&1 << ETEST
159dn: uid=special,ou=users,o=refint
160objectClass: inetOrgPerson
161objectClass: extensibleObject
162uid: special
163sn: special
164cn: special
165businessCategory: nothing
166carLicense: FOO
167departmentNumber: 933
168displayName: special
169employeeNumber: 41491
170employeeType: vendor
171givenName: special
172member: uid=alice,ou=users,o=refint
173ETEST
174
175RC=$?
176if test $RC != 0 ; then
177	echo "ldapadd failed ($RC)!"
178	test $KILLSERVERS != no && kill -HUP $KILLPIDS
179	exit $RC
180fi
181
182echo "Testing delete when referential attribute is a MUST..."
183$LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
184	$TESTOUT 2>&1 << EDEL
185version: 1
186dn: uid=alice,ou=users,o=refint
187changetype: delete
188EDEL
189
190RC=$?
191if test $RC != 0 ; then
192	echo "ldapmodify failed ($RC)!"
193	test $KILLSERVERS != no && kill -HUP $KILLPIDS
194	exit $RC
195fi
196
197if test $BACKEND = "hdb" ; then
198	$LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
199		$TESTOUT 2>&1 << EDEL
200version: 1
201dn: cn=group,o=refint
202changetype: add
203objectClass: groupOfNames
204cn: group
205member: uid=bill,ou=users,o=refint
206member: uid=bob,ou=users,o=refint
207member: uid=dave,ou=users,o=refint
208member: uid=jorge,ou=users,o=refint
209member: uid=theman,ou=users,o=refint
210member: uid=richard,ou=users,o=refint
211EDEL
212
213	RC=$?
214	if test $RC != 0 ; then
215		echo "ldapmodify failed ($RC)!"
216		test $KILLSERVERS != no && kill -HUP $KILLPIDS
217		exit $RC
218	fi
219
220	sleep 1;
221
222	$LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 \
223		manager member secretary > $SEARCHOUT 2>&1
224	RC=$?
225	if test $RC != 0 ; then
226		echo "ldapsearch failed ($RC)!"
227		test $KILLSERVERS != no && kill -HUP $KILLPIDS
228		exit $RC
229	fi
230
231	$EGREP_CMD "(manager|member|secretary):" $SEARCHOUT \
232		| sed "s/ou=users/ou=people/g" | \
233		sort > $TESTOUT 2>&1
234
235	echo "testing subtree rename"
236	$LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD > \
237		/dev/null 2>&1 'ou=users,o=refint' 'ou=people'
238	RC=$?
239	if test $RC != 0 ; then
240		echo "ldapmodrdn failed ($RC)!"
241		test $KILLSERVERS != no && kill -HUP $KILLPIDS
242		exit $RC
243	fi
244
245	sleep 1;
246
247	echo "Using ldapsearch to check dependents new rdn..."
248
249	$LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 \
250		manager member secretary > $SEARCHOUT 2>&1
251
252	RC=$?
253	if test $RC != 0 ; then
254		echo "ldapsearch failed ($RC)!"
255		test $KILLSERVERS != no && kill -HUP $KILLPIDS
256		exit $RC
257	fi
258
259	$EGREP_CMD "(manager|member|secretary):" $SEARCHOUT \
260		| sort > $SEARCHFLT 2>&1
261
262	echo "Comparing ldapsearch results against original..."
263	$CMP $TESTOUT $SEARCHFLT > $CMPOUT
264
265	if test $? != 0 ; then
266		echo "comparison failed - subtree rename operations did not complete correctly"
267		test $KILLSERVERS != no && kill -HUP $KILLPIDS
268		exit 1
269	fi
270fi
271
272test $KILLSERVERS != no && kill -HUP $KILLPIDS
273
274echo ">>>>> Test succeeded"
275
276test $KILLSERVERS != no && wait
277
278exit 0
279