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 mkdir -p $TESTDIR $DBDIR1
26 $SLAPPASSWD -g -n >$CONFIGPWF
27 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
29 echo "Running slapadd to build slapd database..."
30 . $CONFFILTER $BACKEND $MONITORDB < $UNIQUECONF > $CONF1
31 $SLAPADD -f $CONF1 -l $LDIFUNIQUE
33 if test $RC != 0 ; then
34 echo "slapadd failed ($RC)!"
38 echo "Starting slapd on TCP/IP port $PORT1..."
39 mkdir $TESTDIR/confdir
40 $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
42 if test $WAIT != 0 ; then
50 echo "Testing slapd attribute uniqueness operations..."
51 for i in 0 1 2 3 4 5; do
52 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
53 'objectclass=*' > /dev/null 2>&1
55 if test $RC = 0 ; then
58 echo "Waiting 5 seconds for slapd to start..."
62 if test $RC != 0 ; then
63 echo "ldapsearch failed ($RC)!"
64 test $KILLSERVERS != no && kill -HUP $KILLPIDS
68 echo "Adding a unique record..."
69 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
70 > /dev/null << EOTUNIQ1
71 dn: uid=dave,ou=users,o=unique
72 objectClass: inetOrgPerson
76 businessCategory: otest
79 # NOTE: use special chars in attr value to be used
80 # in internal searches ITS#4212
81 displayName: Dave (ITS#4212)
83 employeeType: contractor
87 if test $RC != 0 ; then
88 echo "ldapadd failed ($RC)!"
89 test $KILLSERVERS != no && kill -HUP $KILLPIDS
93 echo "Adding a non-unique record..."
94 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
95 $TESTOUT 2>&1 << EOTUNIQ2
96 dn: uid=bill,ou=users,o=unique
97 objectClass: inetOrgPerson
101 businessCategory: rtest
106 employeeType: contractor
110 if test $RC != 19 ; then
111 echo "unique check failed ($RC)!"
112 test $KILLSERVERS != no && kill -HUP $KILLPIDS
116 echo Dynamically retrieving initial configuration...
117 $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
118 cat <<EOF >$TESTDIR/initial-reference.ldif
119 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
120 objectClass: olcOverlayConfig
121 objectClass: olcUniqueConfig
122 olcOverlay: {0}unique
123 olcUniqueBase: o=unique
124 olcUniqueAttribute: employeeNumber
125 olcUniqueAttribute: displayName
128 diff $TESTDIR/initial-config.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
130 if test $RC != 0 ; then
131 echo "Initial configuration is not reported correctly."
132 test $KILLSERVERS != no && kill -HUP $KILLPIDS
136 echo Dynamically trying to add a URI with legacy attrs present...
137 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
138 > $TESTOUT 2>&1 <<EOF
139 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
142 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
145 if test $RC != 80 ; then
146 echo "legacy and unique_uri allowed together"
147 test $KILLSERVERS != no && kill -HUP $KILLPIDS
151 echo Dynamically trying to add legacy ignored attrs with legacy attrs present...
152 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
153 > $TESTOUT 2>&1 <<EOF
154 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
157 olcUniqueIgnore: objectClass
160 if test $RC != 80 ; then
161 echo "legacy attrs and legacy ignore attrs allowed together"
162 test $KILLSERVERS != no && kill -HUP $KILLPIDS
166 echo Verifying initial configuration intact...
167 $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
168 diff $TESTDIR/initial-config-recheck.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
170 if test $RC != 0 ; then
171 echo "Initial configuration damaged by unsuccessful modifies."
172 test $KILLSERVERS != no && kill -HUP $KILLPIDS
176 echo Dynamically removing legacy base...
177 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
178 > $TESTOUT 2>&1 <<EOF
179 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
181 delete: olcUniqueBase
184 if test $RC != 0 ; then
185 echo "base removal failed"
186 test $KILLSERVERS != no && kill -HUP $KILLPIDS
190 echo Verifying base removal...
191 $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
192 cat >$TESTDIR/baseremoval-reference.ldif <<EOF
193 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
194 objectClass: olcOverlayConfig
195 objectClass: olcUniqueConfig
196 olcOverlay: {0}unique
197 olcUniqueAttribute: employeeNumber
198 olcUniqueAttribute: displayName
201 diff $TESTDIR/baseremoval-config.ldif $TESTDIR/baseremoval-reference.ldif > /dev/null 2>&1
203 if test $RC != 0 ; then
204 echo "Configuration damaged by base removal"
205 test $KILLSERVERS != no && kill -HUP $KILLPIDS
209 echo "Adding a non-unique record..."
210 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
211 $TESTOUT 2>&1 << EOTUNIQ2
212 dn: uid=bill,ou=users,o=unique
213 objectClass: inetOrgPerson
217 businessCategory: rtest
222 employeeType: contractor
226 if test $RC != 19 ; then
227 echo "unique check failed ($RC)!"
228 test $KILLSERVERS != no && kill -HUP $KILLPIDS
232 echo Trying a legacy base outside of the backend...
233 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
234 > $TESTOUT 2>&1 <<EOF
235 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
238 olcUniqueBase: cn=config
241 if test $RC != 80 ; then
242 echo "out of backend scope base allowed"
243 test $KILLSERVERS != no && kill -HUP $KILLPIDS
247 echo "Adding and removing attrs..."
248 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
249 > $TESTOUT 2>&1 <<EOF
250 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
252 add: olcUniqueAttribute
253 olcUniqueAttribute: description
254 olcUniqueAttribute: telephoneNumber
256 delete: olcUniqueAttribute
257 olcUniqueAttribute: displayName
260 if test $RC != 0 ; then
261 echo "Unable to remove an attribute"
262 test $KILLSERVERS != no && kill -HUP $KILLPIDS
266 echo "Verifying we removed the right attr..."
267 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
268 $TESTOUT 2>&1 << EOTUNIQ2
269 dn: uid=bill,ou=users,o=unique
270 objectClass: inetOrgPerson
274 businessCategory: rtest
279 employeeType: contractor
283 if test $RC != 19 ; then
284 echo "olcUniqueAttribtue single deletion hit the wrong value"
285 test $KILLSERVERS != no && kill -HUP $KILLPIDS
289 echo Removing legacy config and adding URIs...
290 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
291 > $TESTOUT 2>&1 <<EOF
292 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
294 delete: olcUniqueAttribute
297 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
298 olcUniqueURI: ldap:///?description?one
301 if test $RC != 0 ; then
302 echo "Reconfiguration to URIs failed"
303 test $KILLSERVERS != no && kill -HUP $KILLPIDS
307 echo Dynamically retrieving second configuration...
308 $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
309 cat >$TESTDIR/second-reference.ldif <<EOF
310 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
311 objectClass: olcOverlayConfig
312 objectClass: olcUniqueConfig
313 olcOverlay: {0}unique
314 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
315 olcUniqueURI: ldap:///?description?one
318 diff $TESTDIR/second-config.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
320 if test $RC != 0 ; then
321 echo "Second configuration is not reported correctly."
322 test $KILLSERVERS != no && kill -HUP $KILLPIDS
326 echo "Adding a non-unique record..."
327 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
328 $TESTOUT 2>&1 << EOTUNIQ2
329 dn: uid=bill,ou=users,o=unique
330 objectClass: inetOrgPerson
334 businessCategory: rtest
339 employeeType: contractor
343 if test $RC != 19 ; then
344 echo "unique check failed ($RC)!"
345 test $KILLSERVERS != no && kill -HUP $KILLPIDS
349 echo Dynamically trying to add legacy base
350 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
351 > $TESTOUT 2>&1 <<EOF
352 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
355 olcUniqueBase: o=unique
358 if test $RC != 80 ; then
359 echo "legacy base allowed with URIs"
360 test $KILLSERVERS != no && kill -HUP $KILLPIDS
364 echo Dynamically trying to add legacy attrs
365 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
366 > $TESTOUT 2>&1 <<EOF
367 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
369 add: olcUniqueAttribute
370 olcUniqueAttribute: description
373 if test $RC != 80 ; then
374 echo "legacy attributes allowed with URIs"
375 test $KILLSERVERS != no && kill -HUP $KILLPIDS
379 echo Dynamically trying to add legacy strictness
380 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
381 > $TESTOUT 2>&1 <<EOF
382 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
385 olcUniqueStrict: TRUE
388 if test $RC != 80 ; then
389 echo "legacy strictness allowed with URIs"
390 test $KILLSERVERS != no && kill -HUP $KILLPIDS
394 #echo ----------------------
395 echo Dynamically trying a bad filter...
396 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
397 > $TESTOUT 2>&1 <<EOF
398 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
400 replace: olcUniqueURI
401 olcUniqueURI: ldap:///?sn?sub?((cn=e*))
404 if test $RC != 80 ; then
405 echo "bad filter allowed"
406 test $KILLSERVERS != no && kill -HUP $KILLPIDS
410 echo Verifying second configuration intact...
411 $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
412 diff $TESTDIR/second-config-recheck.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
414 if test $RC != 0 ; then
415 echo "Second configuration damaged by rejected modifies."
416 test $KILLSERVERS != no && kill -HUP $KILLPIDS
420 #echo ----------------------
421 echo Dynamically reconfiguring to use different URIs...
422 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
423 > $TESTOUT 2>&1 <<EOF
424 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
427 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
428 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
431 olcUniqueURI: ldap:///?description?one
434 if test $RC != 0 ; then
435 echo "unable to reconfigure"
436 test $KILLSERVERS != no && kill -HUP $KILLPIDS
440 echo Dynamically retrieving third configuration...
441 $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
442 cat >$TESTDIR/third-reference.ldif <<EOF
443 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
444 objectClass: olcOverlayConfig
445 objectClass: olcUniqueConfig
446 olcOverlay: {0}unique
447 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
448 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
449 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
452 diff $TESTDIR/third-config.ldif $TESTDIR/third-reference.ldif > /dev/null 2>&1
454 if test $RC != 0 ; then
455 echo "Third configuration is not reported correctly."
456 test $KILLSERVERS != no && kill -HUP $KILLPIDS
460 echo "Adding a record unique in both domains if filtered..."
462 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
464 dn: uid=edgar,ou=users,o=unique
465 objectClass: inetOrgPerson
472 if test $RC != 0 ; then
473 echo "unique check failed ($RC)!"
474 test $KILLSERVERS != no && kill -HUP $KILLPIDS
478 echo "Adding a record unique in all domains because of filter conditions "
479 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
481 dn: uid=empty,ou=users,o=unique
482 objectClass: inetOrgPerson
489 if test $RC != 0 ; then
490 echo "spurious unique error ($RC)!"
491 test $KILLSERVERS != no && kill -HUP $KILLPIDS
496 echo "Adding a record unique in one domain, non-unique in the filtered domain..."
498 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
500 dn: uid=elvis,ou=users,o=unique
501 objectClass: inetOrgPerson
508 if test $RC != 19 ; then
509 echo "unique check failed ($RC)!"
510 test $KILLSERVERS != no && kill -HUP $KILLPIDS
514 #echo ----------------------
515 echo Dynamically reconfiguring to use attribute-ignore URIs...
516 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
517 > $TESTOUT 2>&1 <<EOF
518 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
520 replace: olcUniqueURI
521 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
524 if test $RC != 0 ; then
525 echo "unable to reconfigure"
526 test $KILLSERVERS != no && kill -HUP $KILLPIDS
530 echo Dynamically retrieving fourth configuration...
531 $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
532 cat >$TESTDIR/fourth-reference.ldif <<EOF
533 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
534 objectClass: olcOverlayConfig
535 objectClass: olcUniqueConfig
536 olcOverlay: {0}unique
537 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
540 diff $TESTDIR/fourth-config.ldif $TESTDIR/fourth-reference.ldif > /dev/null 2>&1
542 if test $RC != 0 ; then
543 echo "Fourth configuration is not reported correctly."
544 test $KILLSERVERS != no && kill -HUP $KILLPIDS
548 echo "Adding a record unique in the ignore-domain..."
550 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
552 dn: uid=elvis,ou=users,o=unique
553 objectClass: inetOrgPerson
557 description: left the building
561 if test $RC != 0 ; then
562 echo "unique check failed ($RC)!"
563 test $KILLSERVERS != no && kill -HUP $KILLPIDS
567 echo "Adding a record non-unique in the ignore-domain..."
569 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
571 dn: uid=harry,ou=users,o=unique
572 objectClass: inetOrgPerson
576 description: left the building
580 if test $RC != 19 ; then
581 echo "unique check failed ($RC)!"
582 test $KILLSERVERS != no && kill -HUP $KILLPIDS
586 test $KILLSERVERS != no && kill -HUP $KILLPIDS
588 echo ">>>>> Test succeeded"
590 test $KILLSERVERS != no && wait