3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 2004-2009 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 $UNIQUE = uniqueno; then
20 echo "Attribute Uniqueness overlay not available, test skipped"
24 if test $BACKEND = null; then
25 echo "Test does not support $BACKEND backend, test skipped"
29 mkdir -p $TESTDIR $DBDIR1
31 $SLAPPASSWD -g -n >$CONFIGPWF
32 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
34 echo "Running slapadd to build slapd database..."
35 . $CONFFILTER $BACKEND $MONITORDB < $UNIQUECONF > $CONF1
36 $SLAPADD -f $CONF1 -l $LDIFUNIQUE
38 if test $RC != 0 ; then
39 echo "slapadd failed ($RC)!"
43 echo "Starting slapd on TCP/IP port $PORT1..."
44 mkdir $TESTDIR/confdir
45 $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
47 if test $WAIT != 0 ; then
55 echo "Testing slapd attribute uniqueness operations..."
56 for i in 0 1 2 3 4 5; do
57 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
58 'objectclass=*' > /dev/null 2>&1
60 if test $RC = 0 ; then
63 echo "Waiting 5 seconds for slapd to start..."
67 if test $RC != 0 ; then
68 echo "ldapsearch failed ($RC)!"
69 test $KILLSERVERS != no && kill -HUP $KILLPIDS
73 echo "Adding a unique record..."
74 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
75 > /dev/null << EOTUNIQ1
76 dn: uid=dave,ou=users,o=unique
77 objectClass: inetOrgPerson
81 businessCategory: otest
84 # NOTE: use special chars in attr value to be used
85 # in internal searches ITS#4212
86 displayName: Dave (ITS#4212)
88 employeeType: contractor
92 if test $RC != 0 ; then
93 echo "ldapadd failed ($RC)!"
94 test $KILLSERVERS != no && kill -HUP $KILLPIDS
98 echo "Adding a non-unique record..."
99 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
100 $TESTOUT 2>&1 << EOTUNIQ2
101 dn: uid=bill,ou=users,o=unique
102 objectClass: inetOrgPerson
106 businessCategory: rtest
111 employeeType: contractor
115 if test $RC != 19 ; then
116 echo "unique check failed ($RC)!"
117 test $KILLSERVERS != no && kill -HUP $KILLPIDS
121 echo Dynamically retrieving initial configuration...
122 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -h $LOCALHOST -p $PORT1 -LLL | tr -d \\r >$TESTDIR/initial-config.ldif
123 cat <<EOF >$TESTDIR/initial-reference.ldif
124 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
125 objectClass: olcOverlayConfig
126 objectClass: olcUniqueConfig
127 olcOverlay: {0}unique
128 olcUniqueBase: o=unique
129 olcUniqueAttribute: employeeNumber
130 olcUniqueAttribute: displayName
133 diff $TESTDIR/initial-config.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
135 if test $RC != 0 ; then
136 echo "Initial configuration is not reported correctly."
137 test $KILLSERVERS != no && kill -HUP $KILLPIDS
141 echo Dynamically trying to add a URI with legacy attrs present...
142 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
143 > $TESTOUT 2>&1 <<EOF
144 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
147 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
150 if test $RC != 80 ; then
151 echo "legacy and unique_uri allowed together"
152 test $KILLSERVERS != no && kill -HUP $KILLPIDS
156 echo Dynamically trying to add legacy ignored attrs with legacy attrs present...
157 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
158 > $TESTOUT 2>&1 <<EOF
159 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
162 olcUniqueIgnore: objectClass
165 if test $RC != 80 ; then
166 echo "legacy attrs and legacy ignore attrs allowed together"
167 test $KILLSERVERS != no && kill -HUP $KILLPIDS
171 echo Verifying initial configuration intact...
172 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -h $LOCALHOST -p $PORT1 -LLL | tr -d \\r >$TESTDIR/initial-config-recheck.ldif
173 diff $TESTDIR/initial-config-recheck.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
175 if test $RC != 0 ; then
176 echo "Initial configuration damaged by unsuccessful modifies."
177 test $KILLSERVERS != no && kill -HUP $KILLPIDS
181 echo Dynamically removing legacy base...
182 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
183 > $TESTOUT 2>&1 <<EOF
184 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
186 delete: olcUniqueBase
189 if test $RC != 0 ; then
190 echo "base removal failed"
191 test $KILLSERVERS != no && kill -HUP $KILLPIDS
195 echo Verifying base removal...
196 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -h $LOCALHOST -p $PORT1 -LLL | tr -d \\r >$TESTDIR/baseremoval-config.ldif
197 cat >$TESTDIR/baseremoval-reference.ldif <<EOF
198 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
199 objectClass: olcOverlayConfig
200 objectClass: olcUniqueConfig
201 olcOverlay: {0}unique
202 olcUniqueAttribute: employeeNumber
203 olcUniqueAttribute: displayName
206 diff $TESTDIR/baseremoval-config.ldif $TESTDIR/baseremoval-reference.ldif > /dev/null 2>&1
208 if test $RC != 0 ; then
209 echo "Configuration damaged by base removal"
210 test $KILLSERVERS != no && kill -HUP $KILLPIDS
214 echo "Adding a non-unique record..."
215 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
216 $TESTOUT 2>&1 << EOTUNIQ2
217 dn: uid=bill,ou=users,o=unique
218 objectClass: inetOrgPerson
222 businessCategory: rtest
227 employeeType: contractor
231 if test $RC != 19 ; then
232 echo "unique check failed ($RC)!"
233 test $KILLSERVERS != no && kill -HUP $KILLPIDS
237 echo Trying a legacy base outside of the backend...
238 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
239 > $TESTOUT 2>&1 <<EOF
240 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
243 olcUniqueBase: cn=config
246 if test $RC != 80 ; then
247 echo "out of backend scope base allowed"
248 test $KILLSERVERS != no && kill -HUP $KILLPIDS
252 echo "Adding and removing attrs..."
253 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
254 > $TESTOUT 2>&1 <<EOF
255 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
257 add: olcUniqueAttribute
258 olcUniqueAttribute: description
259 olcUniqueAttribute: telephoneNumber
261 delete: olcUniqueAttribute
262 olcUniqueAttribute: displayName
265 if test $RC != 0 ; then
266 echo "Unable to remove an attribute"
267 test $KILLSERVERS != no && kill -HUP $KILLPIDS
271 echo "Verifying we removed the right attr..."
272 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
273 $TESTOUT 2>&1 << EOTUNIQ2
274 dn: uid=bill,ou=users,o=unique
275 objectClass: inetOrgPerson
279 businessCategory: rtest
284 employeeType: contractor
288 if test $RC != 19 ; then
289 echo "olcUniqueAttribtue single deletion hit the wrong value"
290 test $KILLSERVERS != no && kill -HUP $KILLPIDS
294 echo Removing legacy config and adding URIs...
295 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
296 > $TESTOUT 2>&1 <<EOF
297 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
299 delete: olcUniqueAttribute
302 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
303 olcUniqueURI: ldap:///?description?one
306 if test $RC != 0 ; then
307 echo "Reconfiguration to URIs failed"
308 test $KILLSERVERS != no && kill -HUP $KILLPIDS
312 echo Dynamically retrieving second configuration...
313 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -h $LOCALHOST -p $PORT1 -LLL | tr -d \\r >$TESTDIR/second-config.ldif
314 cat >$TESTDIR/second-reference.ldif <<EOF
315 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
316 objectClass: olcOverlayConfig
317 objectClass: olcUniqueConfig
318 olcOverlay: {0}unique
319 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
320 olcUniqueURI: ldap:///?description?one
323 diff $TESTDIR/second-config.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
325 if test $RC != 0 ; then
326 echo "Second configuration is not reported correctly."
327 test $KILLSERVERS != no && kill -HUP $KILLPIDS
331 echo "Adding a non-unique record..."
332 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
333 $TESTOUT 2>&1 << EOTUNIQ2
334 dn: uid=bill,ou=users,o=unique
335 objectClass: inetOrgPerson
339 businessCategory: rtest
344 employeeType: contractor
348 if test $RC != 19 ; then
349 echo "unique check failed ($RC)!"
350 test $KILLSERVERS != no && kill -HUP $KILLPIDS
354 echo Dynamically trying to add legacy base
355 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
356 > $TESTOUT 2>&1 <<EOF
357 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
360 olcUniqueBase: o=unique
363 if test $RC != 80 ; then
364 echo "legacy base allowed with URIs"
365 test $KILLSERVERS != no && kill -HUP $KILLPIDS
369 echo Dynamically trying to add legacy attrs
370 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
371 > $TESTOUT 2>&1 <<EOF
372 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
374 add: olcUniqueAttribute
375 olcUniqueAttribute: description
378 if test $RC != 80 ; then
379 echo "legacy attributes allowed with URIs"
380 test $KILLSERVERS != no && kill -HUP $KILLPIDS
384 echo Dynamically trying to add legacy strictness
385 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
386 > $TESTOUT 2>&1 <<EOF
387 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
390 olcUniqueStrict: TRUE
393 if test $RC != 80 ; then
394 echo "legacy strictness allowed with URIs"
395 test $KILLSERVERS != no && kill -HUP $KILLPIDS
399 #echo ----------------------
400 echo Dynamically trying a bad filter...
401 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
402 > $TESTOUT 2>&1 <<EOF
403 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
405 replace: olcUniqueURI
406 olcUniqueURI: ldap:///?sn?sub?((cn=e*))
409 if test $RC != 80 ; then
410 echo "bad filter allowed"
411 test $KILLSERVERS != no && kill -HUP $KILLPIDS
415 echo Verifying second configuration intact...
416 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -h $LOCALHOST -p $PORT1 -LLL | tr -d \\r >$TESTDIR/second-config-recheck.ldif
417 diff $TESTDIR/second-config-recheck.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
419 if test $RC != 0 ; then
420 echo "Second configuration damaged by rejected modifies."
421 test $KILLSERVERS != no && kill -HUP $KILLPIDS
425 #echo ----------------------
426 echo Dynamically reconfiguring to use different URIs...
427 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
428 > $TESTOUT 2>&1 <<EOF
429 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
432 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
433 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
436 olcUniqueURI: ldap:///?description?one
439 if test $RC != 0 ; then
440 echo "unable to reconfigure"
441 test $KILLSERVERS != no && kill -HUP $KILLPIDS
445 echo Dynamically retrieving third configuration...
446 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -h $LOCALHOST -p $PORT1 -LLL | tr -d \\r >$TESTDIR/third-config.ldif
447 cat >$TESTDIR/third-reference.ldif <<EOF
448 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
449 objectClass: olcOverlayConfig
450 objectClass: olcUniqueConfig
451 olcOverlay: {0}unique
452 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
453 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
454 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
457 diff $TESTDIR/third-config.ldif $TESTDIR/third-reference.ldif > /dev/null 2>&1
459 if test $RC != 0 ; then
460 echo "Third configuration is not reported correctly."
461 test $KILLSERVERS != no && kill -HUP $KILLPIDS
465 echo "Adding a record unique in both domains if filtered..."
467 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
469 dn: uid=edgar,ou=users,o=unique
470 objectClass: inetOrgPerson
477 if test $RC != 0 ; then
478 echo "unique check failed ($RC)!"
479 test $KILLSERVERS != no && kill -HUP $KILLPIDS
483 echo "Adding a record unique in all domains because of filter conditions "
484 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
486 dn: uid=empty,ou=users,o=unique
487 objectClass: inetOrgPerson
494 if test $RC != 0 ; then
495 echo "spurious unique error ($RC)!"
496 test $KILLSERVERS != no && kill -HUP $KILLPIDS
501 echo "Adding a record unique in one domain, non-unique in the filtered domain..."
503 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
505 dn: uid=elvis,ou=users,o=unique
506 objectClass: inetOrgPerson
513 if test $RC != 19 ; then
514 echo "unique check failed ($RC)!"
515 test $KILLSERVERS != no && kill -HUP $KILLPIDS
519 #echo ----------------------
520 echo Dynamically reconfiguring to use attribute-ignore URIs...
521 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
522 > $TESTOUT 2>&1 <<EOF
523 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
525 replace: olcUniqueURI
526 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
529 if test $RC != 0 ; then
530 echo "unable to reconfigure"
531 test $KILLSERVERS != no && kill -HUP $KILLPIDS
535 echo Dynamically retrieving fourth configuration...
536 $LDAPSEARCH -S "" -b olcOverlay='{0}'unique,olcDatabase='{1}'$BACKEND,cn=config -D cn=config -y $CONFIGPWF -h $LOCALHOST -p $PORT1 -LLL | tr -d \\r >$TESTDIR/fourth-config.ldif
537 cat >$TESTDIR/fourth-reference.ldif <<EOF
538 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
539 objectClass: olcOverlayConfig
540 objectClass: olcUniqueConfig
541 olcOverlay: {0}unique
542 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
545 diff $TESTDIR/fourth-config.ldif $TESTDIR/fourth-reference.ldif > /dev/null 2>&1
547 if test $RC != 0 ; then
548 echo "Fourth configuration is not reported correctly."
549 test $KILLSERVERS != no && kill -HUP $KILLPIDS
553 echo "Adding a record unique in the ignore-domain..."
555 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
557 dn: uid=elvis,ou=users,o=unique
558 objectClass: inetOrgPerson
562 description: left the building
566 if test $RC != 0 ; then
567 echo "unique check failed ($RC)!"
568 test $KILLSERVERS != no && kill -HUP $KILLPIDS
572 echo "Adding a record non-unique in the ignore-domain..."
574 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
576 dn: uid=harry,ou=users,o=unique
577 objectClass: inetOrgPerson
581 description: left the building
585 if test $RC != 19 ; then
586 echo "unique check failed ($RC)!"
587 test $KILLSERVERS != no && kill -HUP $KILLPIDS
591 test $KILLSERVERS != no && kill -HUP $KILLPIDS
593 echo ">>>>> Test succeeded"
595 test $KILLSERVERS != no && wait