]> git.sur5r.net Git - openldap/blob - tests/scripts/test035-meta
3d427aa31ed27e42fc3868b450336eed907792c7
[openldap] / tests / scripts / test035-meta
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2005 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 echo ""
20
21 if test $BACKMETA = metano ; then 
22         echo "meta backend not available, test skipped"
23         exit 0
24 fi
25
26 rm -rf $TESTDIR
27
28 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
29
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
32 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
33 PID=$!
34 if test $WAIT != 0 ; then
35     echo PID $PID
36     read foo
37 fi
38 KILLPIDS="$PID"
39
40 echo "Using ldapsearch to check that slapd is running..."
41 for i in 0 1 2 3 4 5; do
42         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
43                 'objectclass=*' > /dev/null 2>&1
44         RC=$?
45         if test $RC = 0 ; then
46                 break
47         fi
48         echo "Waiting 5 seconds for slapd to start..."
49         sleep 5
50 done
51 if test $RC != 0 ; then
52         echo "ldapsearch failed ($RC)!"
53         test $KILLSERVERS != no && kill -HUP $KILLPIDS
54         exit $RC
55 fi
56
57 echo "Using ldapadd to populate the database..."
58 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
59         $LDIFORDERED > $TESTOUT 2>&1
60 RC=$?
61 if test $RC != 0 ; then
62         echo "ldapadd failed ($RC)!"
63         test $KILLSERVERS != no && kill -HUP $KILLPIDS
64         exit $RC
65 fi
66
67 echo "Starting slapd on TCP/IP port $PORT2..."
68 . $CONFFILTER $BACKEND $MONITORDB < $METACONF2 > $CONF2
69 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
70 PID=$!
71 if test $WAIT != 0 ; then
72     echo PID $PID
73     read foo
74 fi
75 KILLPIDS="$KILLPIDS $PID"
76
77 echo "Using ldapsearch to check that slapd is running..."
78 for i in 0 1 2 3 4 5; do
79         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
80                 'objectclass=*' > /dev/null 2>&1
81         RC=$?
82         if test $RC = 0 ; then
83                 break
84         fi
85         echo "Waiting 5 seconds for slapd to start..."
86         sleep 5
87 done
88 if test $RC != 0 ; then
89         echo "ldapsearch failed ($RC)!"
90         test $KILLSERVERS != no && kill -HUP $KILLPIDS
91         exit $RC
92 fi
93
94 echo "Using ldapadd to populate the database..."
95 $LDAPADD -D "$METAMANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD < \
96         $LDIFMETA >> $TESTOUT 2>&1
97 RC=$?
98 if test $RC != 0 ; then
99         echo "ldapadd failed ($RC)!"
100         test $KILLSERVERS != no && kill -HUP $KILLPIDS
101         exit $RC
102 fi
103
104 echo "Starting slapd on TCP/IP port $PORT3..."
105 . $CONFFILTER $BACKEND $MONITORDB < $METACONF > $CONF3
106 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
107 PID=$!
108 if test $WAIT != 0 ; then
109     echo PID $PID
110     read foo
111 fi
112 KILLPIDS="$KILLPIDS $PID"
113
114 echo "Using ldapsearch to check that slapd is running..."
115 for i in 0 1 2 3 4 5; do
116         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
117                 'objectclass=*' > /dev/null 2>&1
118         RC=$?
119         if test $RC = 0 ; then
120                 break
121         fi
122         echo "Waiting 5 seconds for slapd to start..."
123         sleep 5
124 done
125 if test $RC != 0 ; then
126         echo "ldapsearch failed ($RC)!"
127         test $KILLSERVERS != no && kill -HUP $KILLPIDS
128         exit $RC
129 fi
130
131 cat /dev/null > $SEARCHOUT
132
133 BASEDN="o=Example,c=US"
134 echo "Searching base=\"$BASEDN\"..."
135 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
136 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" >> $SEARCHOUT 2>&1
137 RC=$?
138 if test $RC != 0 ; then
139         echo "Search failed ($RC)!"
140         test $KILLSERVERS != no && kill -HUP $KILLPIDS
141         exit $RC
142 fi
143
144 #
145 # Do some modifications
146 #
147
148 BASEDN="o=Example,c=US"
149 echo "Modifying database \"$BASEDN\"..."
150 $LDAPMODIFY -v -D "cn=Manager,$BASEDN" -h $LOCALHOST -p $PORT3 -w $PASSWD \
151         -M >> $TESTOUT 2>&1 << EOMODS
152 # These operations (updates with objectClass mapping) triggered ITS#3499
153 dn: cn=Added Group,ou=Groups,$BASEDN
154 changetype: add
155 objectClass: groupOfNames
156 objectClass: uidObject
157 cn: Added Group
158 member: cn=Added Group,ou=Groups,$BASEDN
159 uid: added
160
161 dn: cn=Another Added Group,ou=Groups,$BASEDN
162 changetype: add
163 objectClass: groupOfNames
164 cn: Another Added Group
165 member: cn=Added Group,ou=Groups,$BASEDN
166 member: cn=Another Added Group,ou=Groups,$BASEDN
167
168 dn: cn=Another Added Group,ou=Groups,$BASEDN
169 changetype: modify
170 add: objectClass
171 objectClass: uidObject
172 -
173 add: uid
174 uid: added
175 -
176
177 dn: cn=Added Group,ou=Groups,$BASEDN
178 changetype: modify
179 delete: objectClass
180 objectClass: uidObject
181 -
182 delete: uid
183 -
184
185 dn: ou=Meta,$BASEDN
186 changetype: modify
187 add: description
188 description: added to "ou=Meta,$BASEDN"
189 -
190
191 dn: ou=Who's going to handle this?,$BASEDN
192 changetype: add
193 objectClass: organizationalUnit
194 ou: Who's going to handle this?
195 description: added
196 description: will be deleted
197
198 dn: ou=Same as above,$BASEDN
199 changetype: add
200 objectClass: organizationalUnit
201 ou: Same as above
202 description: added right after "Who's going to handle this?"
203 description: will be preserved
204
205 dn: ou=Who's going to handle this?,$BASEDN
206 changetype: delete
207
208 dn: ou=Who's going to handle this?,ou=Meta,$BASEDN
209 changetype: add
210 objectClass: organizationalUnit
211 ou: Who's going to handle this?
212 description: added
213 description: will be deleted
214
215 dn: ou=Same as above,ou=Meta,$BASEDN
216 changetype: add
217 objectClass: organizationalUnit
218 ou: Same as above
219 description: added right after "Who's going to handle this?"
220 description: will be preserved
221
222 dn: cn=Added User,ou=Same as above,ou=Meta,$BASEDN
223 changetype: add
224 objectClass: inetOrgPerson
225 cn: Added User
226 sn: User
227 userPassword: secret
228
229 dn: ou=Who's going to handle this?,ou=Meta,$BASEDN
230 changetype: delete
231 EOMODS
232
233 RC=$?
234 if test $RC != 0 ; then
235         echo "Modify failed ($RC)!"
236         test $KILLSERVERS != no && kill -HUP $KILLPIDS
237         exit $RC
238 fi
239
240 echo "Searching base=\"$BASEDN\"..."
241 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
242 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" >> $SEARCHOUT 2>&1
243 RC=$?
244 if test $RC != 0 ; then
245         echo "Search failed ($RC)!"
246         test $KILLSERVERS != no && kill -HUP $KILLPIDS
247         exit $RC
248 fi
249
250 BASEDN="o=Example,c=US"
251 echo "  base=\"$BASEDN\"..."
252 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
253 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" -M "$FILTER" '*' ref \
254         >> $SEARCHOUT 2>&1
255 RC=$?
256 if test $RC != 0 ; then
257         echo "Search failed ($RC)!"
258         test $KILLSERVERS != no && kill -HUP $KILLPIDS
259         exit $RC
260 fi
261
262 BASEDN="o=Example,c=US"
263 FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
264 echo "Searching filter=\"$FILTER\""
265 echo "  attrs=\"seeAlso\""
266 echo "  base=\"$BASEDN\"..."
267 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
268 echo "#         attrs=\"seeAlso\"" >> $SEARCHOUT
269 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
270 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" "$FILTER" seeAlso \
271         >> $SEARCHOUT 2>&1
272 RC=$?
273 if test $RC != 0 ; then
274         echo "Search failed ($RC)!"
275         test $KILLSERVERS != no && kill -HUP $KILLPIDS
276         exit $RC
277 fi
278
279 FILTER="(uid=example)"
280 echo "Searching filter=\"$FILTER\""
281 echo "  attrs=\"uid\""
282 echo "  base=\"$BASEDN\"..."
283 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
284 echo "#         attrs=\"uid\"" >> $SEARCHOUT
285 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
286 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" "$FILTER" uid \
287         >> $SEARCHOUT 2>&1
288 RC=$?
289 if test $RC != 0 ; then
290         echo "Search failed ($RC)!"
291         test $KILLSERVERS != no && kill -HUP $KILLPIDS
292         exit $RC
293 fi
294
295 FILTER="(member=cn=Another Added Group,ou=Groups,$BASEDN)"
296 echo "Searching filter=\"$FILTER\""
297 echo "  attrs=\"member\""
298 echo "  base=\"$BASEDN\"..."
299 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
300 echo "#         attrs=\"member\"" >> $SEARCHOUT
301 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
302 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT3 -b "$BASEDN" "$FILTER" member \
303         >> $SEARCHOUT 2>&1
304 RC=$?
305 if test $RC != 0 ; then
306         echo "Search failed ($RC)!"
307         test $KILLSERVERS != no && kill -HUP $KILLPIDS
308         exit $RC
309 fi
310
311 echo "Filtering ldapsearch results..."
312 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
313 echo "Filtering original ldif used to create database..."
314 . $LDIFFILTER < $METAOUT > $LDIFFLT
315 echo "Comparing filter output..."
316 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
317         
318 if test $? != 0 ; then
319         echo "comparison failed - meta search/modification didn't succeed"
320         test $KILLSERVERS != no && kill -HUP $KILLPIDS
321         exit 1
322 fi
323
324 BASEDN="o=Example,c=US"
325 echo "Changing password to database \"$BASEDN\"..."
326 $LDAPPASSWD -h $LOCALHOST -p $PORT3 -D "cn=Manager,$BASEDN" -w $PASSWD \
327         -s $PASSWD "cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN" \
328         >> $TESTOUT 2>&1
329 RC=$?
330 if test $RC != 0 ; then
331         echo "Passwd ExOp failed ($RC)!"
332         test $KILLSERVERS != no && kill -HUP $KILLPIDS
333         exit $RC
334 fi
335
336 echo "Binding with newly changed password to database \"$BASEDN\"..."
337 $LDAPWHOAMI -h $LOCALHOST -p $PORT3 \
338         -D "cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN" \
339         -w $PASSWD >> $TESTOUT 2>&1
340 RC=$?
341 if test $RC != 0 ; then
342         echo "WhoAmI failed ($RC)!"
343         test $KILLSERVERS != no && kill -HUP $KILLPIDS
344         exit $RC
345 fi
346
347 echo "Binding as newly added user to database \"$BASEDN\"..."
348 $LDAPWHOAMI -h $LOCALHOST -p $PORT3 \
349         -D "cn=Added User,ou=Same as above,ou=Meta,$BASEDN" \
350         -w $PASSWD >> $TESTOUT 2>&1
351 RC=$?
352 if test $RC != 0 ; then
353         echo "WhoAmI failed ($RC)!"
354         test $KILLSERVERS != no && kill -HUP $KILLPIDS
355         exit $RC
356 fi
357
358 echo "Changing password to database \"$BASEDN\"..."
359 $LDAPPASSWD -h $LOCALHOST -p $PORT3 -D "cn=Manager,$BASEDN" -w $PASSWD \
360         -s meta "cn=Added User,ou=Same as above,ou=Meta,$BASEDN" \
361         >> $TESTOUT 2>&1
362 RC=$?
363 if test $RC != 0 ; then
364         echo "Passwd ExOp failed ($RC)!"
365         test $KILLSERVERS != no && kill -HUP $KILLPIDS
366         exit $RC
367 fi
368
369 echo "Binding with newly changed password to database \"$BASEDN\"..."
370 $LDAPWHOAMI -h $LOCALHOST -p $PORT3 \
371         -D "cn=Added User,ou=Same as above,ou=Meta,$BASEDN" \
372         -w meta >> $TESTOUT 2>&1
373 RC=$?
374 if test $RC != 0 ; then
375         echo "WhoAmI failed ($RC)!"
376         test $KILLSERVERS != no && kill -HUP $KILLPIDS
377         exit $RC
378 fi
379
380 echo "Comparing to database \"$BASEDN\"..."
381 $LDAPCOMPARE -h $LOCALHOST -p $PORT3 \
382         "cn=Another Added Group,ou=Groups,$BASEDN" \
383         "member:cn=Added Group,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
384 RC=$?
385 if test $RC != 6 ; then
386         echo "Compare failed ($RC)!"
387         test $KILLSERVERS != no && kill -HUP $KILLPIDS
388         exit $RC
389 fi
390
391 test $KILLSERVERS != no && kill -HUP $KILLPIDS
392
393 echo ">>>>> Test succeeded"
394 exit 0
395