]> git.sur5r.net Git - openldap/blob - tests/scripts/test046-dds
Merge remote-tracking branch 'origin/mdb.RE/0.9'
[openldap] / tests / scripts / test046-dds
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2005-2015 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 case $BACKEND in ldif | null)
20         # LDIF lacks ACL support, NULL cannot hold dynamic entries
21         echo "Test does not support $BACKEND backend, test skipped"
22         exit 0
23 esac
24
25 if test $DDS = ddsno; then 
26         echo "Dynamic Directory Services overlay not available, test skipped"
27         exit 0
28 fi 
29
30 mkdir -p $TESTDIR $DBDIR1
31
32 echo "Running slapadd to build slapd database..."
33 . $CONFFILTER $BACKEND $MONITORDB < $MCONF > $ADDCONF
34 $SLAPADD -f $ADDCONF -l $LDIFORDERED
35 RC=$?
36 if test $RC != 0 ; then
37         echo "slapadd failed ($RC)!"
38         exit $RC
39 fi
40
41 echo "Running slapindex to index slapd database..."
42 . $CONFFILTER $BACKEND $MONITORDB < $DDSCONF > $CONF1
43 $SLAPINDEX -f $CONF1
44 RC=$?
45 if test $RC != 0 ; then
46         echo "warning: slapindex failed ($RC)"
47         echo "  assuming no indexing support"
48 fi
49
50 echo "Starting slapd on TCP/IP port $PORT1..."
51 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
52 PID=$!
53 if test $WAIT != 0 ; then
54     echo PID $PID
55     read foo
56 fi
57 KILLPIDS="$PID"
58
59 sleep 1
60
61 echo "Testing slapd searching..."
62 for i in 0 1 2 3 4 5; do
63         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
64                 '(objectclass=*)' > /dev/null 2>&1
65         RC=$?
66         if test $RC = 0 ; then
67                 break
68         fi
69         echo "Waiting 5 seconds for slapd to start..."
70         sleep 5
71 done
72
73 if test $RC != 0 ; then
74         echo "ldapsearch failed ($RC)!"
75         test $KILLSERVERS != no && kill -HUP $KILLPIDS
76         exit $RC
77 fi
78
79 cat /dev/null > $SEARCHOUT
80
81 echo "Creating a dynamic entry..."
82 $LDAPADD -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
83         >> $TESTOUT 2>&1 << EOMODS
84 dn: cn=Dynamic Object,dc=example,dc=com
85 objectClass: inetOrgPerson
86 objectClass: dynamicObject
87 cn: Dynamic Object
88 sn: Object
89 EOMODS
90 RC=$?
91 if test $RC != 0 ; then
92         echo "ldapadd failed ($RC)!"
93         test $KILLSERVERS != no && kill -HUP $KILLPIDS
94         exit $RC
95 fi
96
97 echo "Refreshing the newly created dynamic entry..."
98 $LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
99         "refresh" "cn=Dynamic Object,dc=example,dc=com" "120" \
100         >> $TESTOUT 2>&1
101 RC=$?
102 if test $RC != 0 ; then
103         echo "ldapexop failed ($RC)!"
104         test $KILLSERVERS != no && kill -HUP $KILLPIDS
105         exit $RC
106 fi
107
108 echo "Modifying the newly created dynamic entry..."
109 $LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
110         >> $TESTOUT 2>&1 << EOMODS
111 dn: cn=Dynamic Object,dc=example,dc=com
112 changetype: modify
113 add: userPassword
114 userPassword: dynamic
115 EOMODS
116 RC=$?
117 if test $RC != 0 ; then
118         echo "ldapadd failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 echo "Binding as the newly created dynamic entry..."
124 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
125         -D "cn=Dynamic Object,dc=example,dc=com" -w dynamic
126 RC=$?
127 if test $RC != 0 ; then
128         echo "ldapwhoami failed ($RC)!"
129         test $KILLSERVERS != no && kill -HUP $KILLPIDS
130         exit $RC
131 fi
132
133 echo "Creating a dynamic entry subordinate to another..."
134 $LDAPADD -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
135         >> $TESTOUT 2>&1 << EOMODS
136 dn: cn=Subordinate Dynamic Object,cn=Dynamic Object,dc=example,dc=com
137 objectClass: inetOrgPerson
138 objectClass: dynamicObject
139 cn: Subordinate Dynamic Object
140 sn: Object
141 userPassword: dynamic
142 EOMODS
143 RC=$?
144 if test $RC != 0 ; then
145         echo "ldapadd failed ($RC)!"
146         test $KILLSERVERS != no && kill -HUP $KILLPIDS
147         exit $RC
148 fi
149
150 SEARCH=0
151
152 SEARCH=`expr $SEARCH + 1`
153 echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
154 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
155         '(objectClass=dynamicObject)' '*' entryTtl \
156         >> $SEARCHOUT 2>&1
157 RC=$?
158 if test $RC != 0 ; then
159         echo "ldapsearch failed ($RC)!"
160         test $KILLSERVERS != no && kill -HUP $KILLPIDS
161         exit $RC
162 fi
163
164 echo "Creating a static entry subordinate to a dynamic one (should fail)..."
165 $LDAPADD -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
166         >> $TESTOUT 2>&1 << EOMODS
167 dn: cn=Subordinate Static Object,cn=Dynamic Object,dc=example,dc=com
168 objectClass: inetOrgPerson
169 cn: Subordinate Static Object
170 sn: Object
171 userPassword: static
172 EOMODS
173 RC=$?
174 case $RC in
175 0)
176         echo "ldapadd should have failed ($RC)!"
177         test $KILLSERVERS != no && kill -HUP $KILLPIDS
178         exit -1
179         ;;
180 19)
181         echo "ldapadd failed ($RC)"
182         ;;
183 *)
184         echo "ldapadd failed ($RC)!"
185         test $KILLSERVERS != no && kill -HUP $KILLPIDS
186         exit $RC
187         ;;
188 esac
189
190 echo "Turning a static into a dynamic entry (should fail)..."
191 $LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
192         >> $TESTOUT 2>&1 << EOMODS
193 dn: ou=People,dc=example,dc=com
194 changetype: modify
195 add: objectClass
196 objectClass: dynamicObject
197 EOMODS
198 RC=$?
199 case $RC in
200 0)
201         echo "ldapmodify should have failed ($RC)!"
202         test $KILLSERVERS != no && kill -HUP $KILLPIDS
203         exit -1
204         ;;
205 65)
206         echo "ldapmodify failed ($RC)"
207         ;;
208 *)
209         echo "ldapmodify failed ($RC)!"
210         test $KILLSERVERS != no && kill -HUP $KILLPIDS
211         exit $RC
212         ;;
213 esac
214
215 echo "Turning a dynamic into a static entry (should fail)..."
216 $LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
217         >> $TESTOUT 2>&1 << EOMODS
218 dn: cn=Dynamic Object,dc=example,dc=com
219 changetype: modify
220 delete: objectClass
221 objectClass: dynamicObject
222 EOMODS
223 RC=$?
224 case $RC in
225 0)
226         echo "ldapmodify should have failed ($RC)!"
227         test $KILLSERVERS != no && kill -HUP $KILLPIDS
228         exit -1
229         ;;
230 65)
231         echo "ldapmodify failed ($RC)"
232         ;;
233 *)
234         echo "ldapmodify failed ($RC)!"
235         test $KILLSERVERS != no && kill -HUP $KILLPIDS
236         exit $RC
237         ;;
238 esac
239
240 echo "Renaming a dynamic entry..."
241 $LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
242         >> $TESTOUT 2>&1 << EOMODS
243 dn: cn=Subordinate Dynamic Object,cn=Dynamic Object,dc=example,dc=com
244 changetype: modrdn
245 newrdn: cn=Renamed Dynamic Object
246 deleteoldrdn: 1
247 EOMODS
248 RC=$?
249 if test $RC != 0 ; then
250         echo "ldapmodrdn failed ($RC)!"
251         test $KILLSERVERS != no && kill -HUP $KILLPIDS
252         exit $RC
253 fi
254
255 SEARCH=`expr $SEARCH + 1`
256 echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
257 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
258         '(objectClass=dynamicObject)' '*' entryTtl \
259         >> $SEARCHOUT 2>&1
260 RC=$?
261 if test $RC != 0 ; then
262         echo "ldapsearch failed ($RC)!"
263         test $KILLSERVERS != no && kill -HUP $KILLPIDS
264         exit $RC
265 fi
266
267 echo "Refreshing the initial dynamic entry to make it expire earlier than the subordinate..."
268 $LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
269         "refresh" "cn=Dynamic Object,dc=example,dc=com" "1" \
270         >> $TESTOUT 2>&1
271 RC=$?
272 if test $RC != 0 ; then
273         echo "ldapexop failed ($RC)!"
274         test $KILLSERVERS != no && kill -HUP $KILLPIDS
275         exit $RC
276 fi
277
278 SLEEP=10
279 echo "Waiting $SLEEP seconds to force a subordinate/superior expiration conflict..."
280 sleep $SLEEP
281
282 echo "Re-vitalizing the initial dynamic entry..."
283 $LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
284         "refresh" "cn=Dynamic Object,dc=example,dc=com" "120" \
285         >> $TESTOUT 2>&1
286 RC=$?
287 if test $RC != 0 ; then
288         echo "ldapexop failed ($RC)!"
289         test $KILLSERVERS != no && kill -HUP $KILLPIDS
290         exit $RC
291 fi
292
293 echo "Re-renaming the subordinate dynamic entry (new superior)..."
294 $LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
295         >> $TESTOUT 2>&1 << EOMODS
296 dn: cn=Renamed Dynamic Object,cn=Dynamic Object,dc=example,dc=com
297 changetype: modrdn
298 newrdn: cn=Renamed Dynamic Object
299 deleteoldrdn: 1
300 newsuperior: dc=example,dc=com
301 EOMODS
302 RC=$?
303 if test $RC != 0 ; then
304         echo "ldapmodrdn failed ($RC)!"
305         test $KILLSERVERS != no && kill -HUP $KILLPIDS
306         exit $RC
307 fi
308
309 SEARCH=`expr $SEARCH + 1`
310 echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
311 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
312         '(objectClass=dynamicObject)' '*' entryTtl \
313         >> $SEARCHOUT 2>&1
314 RC=$?
315 if test $RC != 0 ; then
316         echo "ldapsearch failed ($RC)!"
317         test $KILLSERVERS != no && kill -HUP $KILLPIDS
318         exit $RC
319 fi
320
321 echo "Deleting a dynamic entry..."
322 $LDAPMODIFY -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
323         >> $TESTOUT 2>&1 << EOMODS
324 dn: cn=Dynamic Object,dc=example,dc=com
325 changetype: delete
326 EOMODS
327 RC=$?
328 if test $RC != 0 ; then
329         echo "ldapdelete failed ($RC)!"
330         test $KILLSERVERS != no && kill -HUP $KILLPIDS
331         exit $RC
332 fi
333
334 SEARCH=`expr $SEARCH + 1`
335 echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
336 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
337         '(objectClass=dynamicObject)' '*' entryTtl \
338         >> $SEARCHOUT 2>&1
339 RC=$?
340 if test $RC != 0 ; then
341         echo "ldapsearch failed ($RC)!"
342         test $KILLSERVERS != no && kill -HUP $KILLPIDS
343         exit $RC
344 fi
345
346 echo "Refreshing the remaining dynamic entry..."
347 $LDAPEXOP -D $MANAGERDN -w $PASSWD -h $LOCALHOST -p $PORT1 \
348         "refresh" "cn=Renamed Dynamic Object,dc=example,dc=com" "1" \
349         >> $TESTOUT 2>&1
350 RC=$?
351 if test $RC != 0 ; then
352         echo "ldapexop failed ($RC)!"
353         test $KILLSERVERS != no && kill -HUP $KILLPIDS
354         exit $RC
355 fi
356
357 SEARCH=`expr $SEARCH + 1`
358 echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
359 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
360         '(objectClass=dynamicObject)' '*' entryTtl \
361         >> $SEARCHOUT 2>&1
362 RC=$?
363 if test $RC != 0 ; then
364         echo "ldapsearch failed ($RC)!"
365         test $KILLSERVERS != no && kill -HUP $KILLPIDS
366         exit $RC
367 fi
368
369 SLEEP=15
370 echo "Waiting $SLEEP seconds for remaining entry to expire..."
371 sleep $SLEEP
372
373 SEARCH=`expr $SEARCH + 1`
374 echo "# [$SEARCH] Searching the dynamic portion of the database..." >> $SEARCHOUT
375 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
376         '(objectClass=dynamicObject)' '*' entryTtl \
377         >> $SEARCHOUT 2>&1
378 RC=$?
379 if test $RC != 0 ; then
380         echo "ldapsearch failed ($RC)!"
381         test $KILLSERVERS != no && kill -HUP $KILLPIDS
382         exit $RC
383 fi
384
385 # Meeting
386 MEETINGDN="cn=Meeting,ou=Groups,dc=example,dc=com"
387 echo "Creating a meeting as $BJORNSDN..."
388 $LDAPMODIFY -D "$BJORNSDN" -w bjorn -h $LOCALHOST -p $PORT1 \
389         >> $TESTOUT 2>&1 << EOMODS
390 dn: $MEETINGDN
391 changetype: add
392 objectClass: groupOfNames
393 objectClass: dynamicObject
394 cn: Meeting
395 member: $BJORNSDN
396
397 dn: $MEETINGDN
398 changetype: modify
399 add: member
400 member: $JOHNDDN
401 EOMODS
402 RC=$?
403 if test $RC != 0 ; then
404         echo "ldapmodify failed ($RC)!"
405         test $KILLSERVERS != no && kill -HUP $KILLPIDS
406         exit $RC
407 fi
408
409 echo "Refreshing the meeting as $BJORNSDN..."
410 $LDAPEXOP -D "$BJORNSDN" -w bjorn -h $LOCALHOST -p $PORT1 \
411         "refresh" "$MEETINGDN" "120" \
412         >> $TESTOUT 2>&1
413 RC=$?
414 if test $RC != 0 ; then
415         echo "ldapexop failed ($RC)!"
416         test $KILLSERVERS != no && kill -HUP $KILLPIDS
417         exit $RC
418 fi
419
420 echo "Joining the meeting as $BABSDN..."
421 $LDAPMODIFY -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
422         >> $TESTOUT 2>&1 << EOMODS
423 dn: $MEETINGDN
424 changetype: modify
425 add: member
426 member: $BABSDN
427 EOMODS
428 RC=$?
429 if test $RC != 0 ; then
430         echo "ldapmodify failed ($RC)!"
431         test $KILLSERVERS != no && kill -HUP $KILLPIDS
432         exit $RC
433 fi
434
435 echo "Trying to add a member as $BABSDN (should fail)..."
436 $LDAPMODIFY -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
437         >> $TESTOUT 2>&1 << EOMODS
438 dn: $MEETINGDN
439 changetype: modify
440 add: member
441 member: $MELLIOTDN
442 EOMODS
443 RC=$?
444 case $RC in
445 0)
446         echo "ldapmodify should have failed ($RC)!"
447         test $KILLSERVERS != no && kill -HUP $KILLPIDS
448         exit -1
449         ;;
450 50)
451         echo "ldapmodify failed ($RC)"
452         ;;
453 *)
454         echo "ldapmodify failed ($RC)!"
455         test $KILLSERVERS != no && kill -HUP $KILLPIDS
456         exit $RC
457         ;;
458 esac
459
460 echo "Refreshing the meeting as $BABSDN..."
461 $LDAPEXOP -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
462         "refresh" "$MEETINGDN" "180" \
463         >> $TESTOUT 2>&1
464 RC=$?
465 if test $RC != 0 ; then
466         echo "ldapexop failed ($RC)!"
467         test $KILLSERVERS != no && kill -HUP $KILLPIDS
468         exit $RC
469 fi
470
471 echo "Trying to refresh the meeting anonymously (should fail)..."
472 $LDAPEXOP -h $LOCALHOST -p $PORT1 \
473         "refresh" "$MEETINGDN" "240" \
474         >> $TESTOUT 2>&1
475 RC=$?
476 if test $RC = 0 ; then
477         echo "ldapexop should have failed ($RC)!"
478         test $KILLSERVERS != no && kill -HUP $KILLPIDS
479         exit -1
480 fi
481
482 echo "Trying to refresh the meeting as $JAJDN (should fail)..."
483 $LDAPEXOP -D "$JAJDN" -w "jaj" -h $LOCALHOST -p $PORT1 \
484         "refresh" "$MEETINGDN" "240" \
485         >> $TESTOUT 2>&1
486 RC=$?
487 if test $RC = 0 ; then
488         echo "ldapexop should have failed ($RC)!"
489         test $KILLSERVERS != no && kill -HUP $KILLPIDS
490         exit -1
491 fi
492
493 echo "Trying to delete the meeting as $BABSDN (should fail)..."
494 $LDAPMODIFY -D "$BABSDN" -w bjensen -h $LOCALHOST -p $PORT1 \
495         >> $TESTOUT 2>&1 << EOMODS
496 dn: $MEETINGDN
497 changetype: delete
498 EOMODS
499 RC=$?
500 case $RC in
501 0)
502         echo "ldapdelete should have failed ($RC)!"
503         test $KILLSERVERS != no && kill -HUP $KILLPIDS
504         exit -1
505         ;;
506 50)
507         echo "ldapdelete failed ($RC)"
508         ;;
509 *)
510         echo "ldapdelete failed ($RC)!"
511         test $KILLSERVERS != no && kill -HUP $KILLPIDS
512         exit $RC
513         ;;
514 esac
515
516 echo "Deleting the meeting as $BJORNSDN..."
517 $LDAPMODIFY -D "$BJORNSDN" -w bjorn -h $LOCALHOST -p $PORT1 \
518         >> $TESTOUT 2>&1 << EOMODS
519 dn: $MEETINGDN
520 changetype: delete
521 EOMODS
522 RC=$?
523 if test $RC != 0 ; then
524         echo "ldapdelete failed ($RC)!"
525         test $KILLSERVERS != no && kill -HUP $KILLPIDS
526         exit $RC
527 fi
528
529 test $KILLSERVERS != no && kill -HUP $KILLPIDS
530
531 LDIF=$DDSOUT
532
533 echo "Filtering ldapsearch results..."
534 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
535 echo "Filtering original ldif used to create database..."
536 $LDIFFILTER < $LDIF > $LDIFFLT
537 echo "Comparing filter output..."
538 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
539
540 if test $? != 0 ; then
541         echo "Comparison failed"
542         exit 1
543 fi
544
545 echo ">>>>> Test succeeded"
546
547 test $KILLSERVERS != no && wait
548
549 exit 0