3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2007 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
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>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $BACKSQL = "sqlno" ; then
20 echo "SQL backend not available, test skipped"
24 if test $RDBMS = "rdbmsno" ; then
25 echo "SQL test not requested, test skipped"
29 if test "${RDBMSWRITE}" != "yes"; then
30 echo "write test disabled for ${RDBMS}; set SLAPD_USE_SQLWRITE=yes to enable"
34 mkdir -p $TESTDIR $DBDIR2A
36 echo "Starting slapd on TCP/IP port $PORT1..."
37 . $CONFFILTER $BACKEND $MONITORDB < $SQLSRMASTERCONF > $CONF1
38 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
40 if test $WAIT != 0 ; then
46 echo "Testing SQL backend write operations..."
47 for i in 0 1 2 3 4 5; do
48 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
49 'objectclass=*' > /dev/null 2>&1
51 if test $RC = 0 ; then
54 echo "Waiting 5 seconds for slapd to start..."
58 if test $RC != 0 ; then
59 echo "ldapsearch failed ($RC)!"
60 test $KILLSERVERS != no && kill -HUP $KILLPIDS
64 echo "Starting slave slapd on TCP/IP port $PORT2..."
65 . $CONFFILTER $BACKEND $MONITORDB < $R1SRSLAVECONF > $CONF2
66 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
68 if test $WAIT != 0 ; then
69 echo SLAVEPID $SLAVEPID
72 KILLPIDS="$KILLPIDS $SLAVEPID"
74 echo "Using ldapsearch to check that slave slapd is running..."
75 for i in 0 1 2 3 4 5; do
76 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
77 'objectclass=*' > /dev/null 2>&1
79 if test $RC = 0 ; then
82 echo "Waiting 5 seconds for slapd to start..."
86 if test $RC != 0 ; then
87 echo "ldapsearch failed ($RC)!"
88 test $KILLSERVERS != no && kill -HUP $KILLPIDS
92 cat /dev/null > $SEARCHOUT
94 echo "Using ldapsearch to retrieve all the entries from the master..."
95 echo "# Using ldapsearch to retrieve all the entries from the master..." \
97 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
98 -D "$MANAGERDN" -w $PASSWD \
99 "(!(objectClass=referral))" >> $SEARCHOUT 2>&1
102 if test $RC != 0 ; then
103 echo "ldapsearch failed ($RC)!"
104 test $KILLSERVERS != no && kill -HUP $KILLPIDS
108 cat /dev/null > $SEARCHOUT2
110 echo "Using ldapsearch to retrieve all the entries from the slave..."
111 echo "# Using ldapsearch to retrieve all the entries from the slave..." \
113 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT2 -b "$BASEDN" \
114 -D "$UPDATEDN" -w $PASSWD \
115 "(objectClass=*)" >> $SEARCHOUT2 2>&1
118 if test $RC != 0 ; then
119 echo "ldapsearch failed ($RC)!"
120 test $KILLSERVERS != no && kill -HUP $KILLPIDS
124 echo "Filtering ldapsearch results from master..."
125 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
126 echo "Filtering ldapsearch results from slave..."
127 . $LDIFFILTER < $SEARCHOUT2 > $SEARCHFLT2
128 echo "Comparing filter output..."
129 $CMP $SEARCHFLT $SEARCHFLT2 > $CMPOUT
131 if test $? != 0 ; then
132 echo "Comparison failed"
133 test $KILLSERVERS != no && kill -HUP $KILLPIDS
137 cat /dev/null > $SEARCHOUT
139 echo "Using ldapsearch to retrieve all the entries..."
140 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
141 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
142 "objectClass=*" >> $SEARCHOUT 2>&1
145 if test $RC != 0 ; then
146 echo "ldapsearch failed ($RC)!"
147 test $KILLSERVERS != no && kill -HUP $KILLPIDS
152 # list here the RDBMSes whose mapping allows writes
154 MANAGERDN="cn=Manager,${BASEDN}"
155 echo "Testing add..."
156 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
157 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
160 # Adding an organization...
161 dn: o=An Org,${BASEDN}
163 objectClass: organization
166 # Adding an organization with an "auxiliary" objectClass..
167 dn: dc=subnet,${BASEDN}
169 objectClass: organization
170 objectClass: dcObject
174 # Adding another organization with an "auxiliary" objectClass..
175 dn: dc=subnet2,${BASEDN}
177 objectClass: organization
178 objectClass: dcObject
183 dn: cn=Lev Tolstoij,${BASEDN}
185 objectClass: inetOrgPerson
189 telephoneNumber: +39 02 XXXX YYYY
190 telephoneNumber: +39 02 XXXX ZZZZ
193 # Adding a person with an "auxiliary" objectClass...
194 dn: cn=Some One,${BASEDN}
196 objectClass: inetOrgPerson
197 objectClass: simpleSecurityObject
201 telephoneNumber: +1 800 900 1234
202 telephoneNumber: +1 800 900 1235
203 userPassword: someone
205 # Adding a person in another subtree...
206 dn: cn=SubNet User,dc=subnet,${BASEDN}
208 objectClass: inetOrgPerson
213 # Adding a document...
214 dn: documentTitle=War and Peace,${BASEDN}
216 objectClass: document
217 description: Historical novel
218 documentTitle: War and Peace
219 documentAuthor: cn=Lev Tolstoij,dc=example,dc=com
220 documentIdentifier: document 3
224 if test $RC != 0 ; then
225 echo "ldapmodify failed ($RC)!"
226 test $KILLSERVERS != no && kill -HUP $KILLPIDS
230 echo "Using ldapsearch to retrieve all the entries..."
231 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
232 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
233 "objectClass=*" >> $SEARCHOUT 2>&1
236 if test $RC != 0 ; then
237 echo "ldapsearch failed ($RC)!"
238 test $KILLSERVERS != no && kill -HUP $KILLPIDS
242 echo "Testing modify..."
243 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
244 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
247 # Deleting all telephone numbers...
248 dn: cn=Some One,${BASEDN}
250 delete: telephoneNumber
253 # Adding a telephone number...
254 dn: cn=Mitya Kovalev,${BASEDN}
257 telephoneNumber: +1 800 123 4567
260 # Deleting a specific telephone number and adding a new one...
261 dn: cn=Lev Tolstoij,${BASEDN}
263 delete: telephoneNumber
264 telephoneNumber: +39 02 XXXX YYYY
267 telephoneNumber: +39 333 ZZZ 1234
270 # Adding an author to a document...
271 dn: documentTitle=book1,${BASEDN}
274 documentAuthor: cn=Lev Tolstoij,${BASEDN}
277 # Adding an author to another document...
278 dn: documentTitle=book2,${BASEDN}
281 documentAuthor: cn=Lev Tolstoij,${BASEDN}
284 # Adding an "auxiliary" objectClass...
285 dn: cn=Mitya Kovalev,${BASEDN}
288 objectClass: simpleSecurityObject
291 # Deleting an "auxiliary" objectClass...
292 dn: cn=Some One,${BASEDN}
295 objectClass: simpleSecurityObject
298 # Deleting userPasswords
299 dn: cn=Lev Tolstoij,${BASEDN}
306 if test $RC != 0 ; then
307 echo "ldapmodify failed ($RC)!"
308 test $KILLSERVERS != no && kill -HUP $KILLPIDS
312 echo "Using ldapsearch to retrieve all the entries..."
313 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
314 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
315 "objectClass=*" >> $SEARCHOUT 2>&1
318 if test $RC != 0 ; then
319 echo "ldapsearch failed ($RC)!"
320 test $KILLSERVERS != no && kill -HUP $KILLPIDS
324 echo "Testing delete..."
325 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
326 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
329 # Deleting a person...
330 dn: cn=Torvlobnor Puzdoy,${BASEDN}
333 # Deleting a document...
334 dn: documentTitle=book1,${BASEDN}
337 # Deleting an organization with an "auxiliary" objectClass...
338 dn: dc=subnet2,${BASEDN}
343 if test $RC != 0 ; then
344 echo "ldapmodify failed ($RC)!"
345 test $KILLSERVERS != no && kill -HUP $KILLPIDS
349 echo "Using ldapsearch to retrieve all the entries..."
350 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
351 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
352 "objectClass=*" >> $SEARCHOUT 2>&1
355 if test $RC != 0 ; then
356 echo "ldapsearch failed ($RC)!"
357 test $KILLSERVERS != no && kill -HUP $KILLPIDS
361 echo "Testing rename..."
362 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
363 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
366 # Renaming an organization...
367 dn: o=An Org,${BASEDN}
369 newrdn: o=Renamed Org
372 # Moving a person to another subtree...
373 dn: cn=Lev Tolstoij,${BASEDN}
375 newrdn: cn=Lev Tolstoij
377 newsuperior: dc=subnet,${BASEDN}
380 dn: documentTitle=book2,${BASEDN}
382 newrdn: documentTitle=Renamed Book
387 if test $RC != 0 ; then
388 echo "ldapmodify failed ($RC)!"
389 test $KILLSERVERS != no && kill -HUP $KILLPIDS
393 echo "Using ldapsearch to retrieve all the entries..."
394 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
395 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
396 "objectClass=*" >> $SEARCHOUT 2>&1
399 if test $RC != 0 ; then
400 echo "ldapsearch failed ($RC)!"
401 test $KILLSERVERS != no && kill -HUP $KILLPIDS
405 echo "Adding a child to a referral (should fail)..."
406 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
407 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
410 dn: cn=Should Fail,ou=Referral,${BASEDN}
412 objectClass: inetOrgPerson
415 telephoneNumber: +39 02 23456789
419 if test $RC = 0 ; then
420 echo "ldapmodify should have failed ($RC)!"
421 test $KILLSERVERS != no && kill -HUP $KILLPIDS
425 echo "Modifying a referral (should fail)..."
426 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
427 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
430 dn: ou=Referral,${BASEDN}
433 ref: ldap://localhost:9009/
438 if test $RC = 0 ; then
439 echo "ldapmodify should have failed ($RC)!"
440 test $KILLSERVERS != no && kill -HUP $KILLPIDS
444 echo "Renaming a referral (should fail)..."
445 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
446 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
449 dn: ou=Referral,${BASEDN}
451 newrdn: ou=Renamed Referral
456 if test $RC = 0 ; then
457 echo "ldapmodify should have failed ($RC)!"
458 test $KILLSERVERS != no && kill -HUP $KILLPIDS
462 echo "Deleting a referral (should fail)..."
463 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
464 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
467 dn: ou=Referral,${BASEDN}
472 if test $RC = 0 ; then
473 echo "ldapmodify should have failed ($RC)!"
474 test $KILLSERVERS != no && kill -HUP $KILLPIDS
478 echo "Adding a referral..."
479 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
480 -h $LOCALHOST -p $PORT1 -M >> $TESTOUT 2>&1 << EOMODS
483 dn: ou=Another Referral,${BASEDN}
485 objectClass: referral
486 objectClass: extensibleObject
488 ref: ldap://localhost:9009/
492 if test $RC != 0 ; then
493 echo "ldapmodify failed ($RC)!"
494 test $KILLSERVERS != no && kill -HUP $KILLPIDS
498 echo "Modifying a referral with manageDSAit..."
499 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
500 -h $LOCALHOST -p $PORT1 -M >> $TESTOUT 2>&1 << EOMODS
503 dn: ou=Referral,${BASEDN}
506 ref: ldap://localhost:9009/
511 if test $RC != 0 ; then
512 echo "ldapmodify failed ($RC)!"
513 test $KILLSERVERS != no && kill -HUP $KILLPIDS
517 echo "Using ldapsearch to retrieve the modified entry..."
518 echo "# Using ldapsearch to retrieve the modified entry..." >> $SEARCHOUT
519 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "ou=Referral,$BASEDN" -M \
520 "objectClass=*" '*' ref >> $SEARCHOUT 2>&1
523 if test $RC != 0 ; then
524 echo "ldapsearch failed ($RC)!"
525 test $KILLSERVERS != no && kill -HUP $KILLPIDS
529 echo "Renaming a referral with manageDSAit..."
530 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
531 -h $LOCALHOST -p $PORT1 -M >> $TESTOUT 2>&1 << EOMODS
534 dn: ou=Referral,${BASEDN}
536 newrdn: ou=Renamed Referral
541 if test $RC != 0 ; then
542 echo "ldapmodify failed ($RC)!"
543 test $KILLSERVERS != no && kill -HUP $KILLPIDS
547 echo "Using ldapsearch to retrieve the renamed entry..."
548 echo "# Using ldapsearch to retrieve the renamed entry..." >> $SEARCHOUT
549 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "ou=Renamed Referral,$BASEDN" -M \
550 "objectClass=*" '*' ref >> $SEARCHOUT 2>&1
553 if test $RC != 0 ; then
554 echo "ldapsearch failed ($RC)!"
555 test $KILLSERVERS != no && kill -HUP $KILLPIDS
559 echo "Deleting a referral with manageDSAit..."
560 $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
561 -h $LOCALHOST -p $PORT1 -M >> $TESTOUT 2>&1 << EOMODS
564 dn: ou=Renamed Referral,${BASEDN}
569 if test $RC != 0 ; then
570 echo "ldapmodify failed ($RC)!"
571 test $KILLSERVERS != no && kill -HUP $KILLPIDS
575 BINDDN="cn=Mitya Kovalev,${BASEDN}"
578 echo "Testing passwd change..."
579 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
580 -D "${BINDDN}" -w ${BINDPW} -s ${NEWPW} \
581 "$BINDDN" >> $TESTOUT 2>&1
584 if test $RC != 0 ; then
585 echo "ldappasswd failed ($RC)!"
586 test $KILLSERVERS != no && kill -HUP $KILLPIDS
590 echo -n "Testing bind with new secret... "
591 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $NEWPW
593 if test $RC != 0 ; then
594 echo "ldapwhoami failed ($RC)!"
595 test $KILLSERVERS != no && kill -HUP $KILLPIDS
599 BINDDN="cn=Some One,${BASEDN}"
601 echo -n "Testing bind with newly added user... "
602 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
604 if test $RC != 0 ; then
605 echo "ldapwhoami failed ($RC)!"
606 test $KILLSERVERS != no && kill -HUP $KILLPIDS
610 echo "Using ldapsearch to retrieve all the entries..."
611 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
612 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
613 "objectClass=*" >> $SEARCHOUT 2>&1
616 if test $RC != 0 ; then
617 echo "ldapsearch failed ($RC)!"
618 test $KILLSERVERS != no && kill -HUP $KILLPIDS
622 echo "Filtering ldapsearch results..."
623 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
624 echo "Filtering modified ldif..."
625 . $LDIFFILTER < $SQLWRITE > $LDIFFLT
626 echo "Comparing filter output..."
627 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
629 if test $? != 0 ; then
630 echo "comparison failed - SQL mods search didn't succeed"
631 test $KILLSERVERS != no && kill -HUP $KILLPIDS
635 echo "Waiting 25 seconds for master to send changes..."
638 cat /dev/null > $SEARCHOUT
640 echo "Using ldapsearch to retrieve all the entries from the master..."
641 echo "# Using ldapsearch to retrieve all the entries from the master..." \
643 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
644 -D "$MANAGERDN" -w $PASSWD \
645 "(!(objectClass=referral))" >> $SEARCHOUT 2>&1
648 if test $RC != 0 ; then
649 echo "ldapsearch failed ($RC)!"
650 test $KILLSERVERS != no && kill -HUP $KILLPIDS
654 cat /dev/null > $SEARCHOUT2
656 echo "Using ldapsearch to retrieve all the entries from the slave..."
657 echo "# Using ldapsearch to retrieve all the entries from the slave..." \
659 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT2 -b "$BASEDN" \
660 -D "$UPDATEDN" -w $PASSWD \
661 "(objectClass=*)" >> $SEARCHOUT2 2>&1
664 if test $RC != 0 ; then
665 echo "ldapsearch failed ($RC)!"
666 test $KILLSERVERS != no && kill -HUP $KILLPIDS
670 echo "Filtering ldapsearch results from master..."
671 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
672 echo "Filtering ldapsearch results from slave..."
673 . $LDIFFILTER < $SEARCHOUT2 > $SEARCHFLT2
674 echo "Comparing filter output..."
675 $CMP $SEARCHFLT $SEARCHFLT2 > $CMPOUT
677 if test $? != 0 ; then
678 echo "Comparison failed"
679 test $KILLSERVERS != no && kill -HUP $KILLPIDS
685 echo "apparently ${RDBMS} does not support writes; skipping..."
689 test $KILLSERVERS != no && kill -HUP $KILLPIDS
691 echo ">>>>> Test succeeded"