3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 2004-2012 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"
25 test $BACKEND = null && RCODEconstraint=0
27 mkdir -p $TESTDIR $DBDIR1
29 $SLAPPASSWD -g -n >$CONFIGPWF
30 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
32 echo "Running slapadd to build slapd database..."
33 . $CONFFILTER $BACKEND $MONITORDB < $UNIQUECONF > $CONF1
34 $SLAPADD -f $CONF1 -l $LDIFUNIQUE
36 if test $RC != 0 ; then
37 echo "slapadd failed ($RC)!"
41 echo "Starting slapd on TCP/IP port $PORT1..."
42 mkdir $TESTDIR/confdir
43 $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
45 if test $WAIT != 0 ; then
53 echo "Testing slapd attribute uniqueness operations..."
54 for i in 0 1 2 3 4 5; do
55 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
56 'objectclass=*' > /dev/null 2>&1
58 if test $RC = 0 ; then
61 echo "Waiting 5 seconds for slapd to start..."
65 if test $RC != 0 ; then
66 echo "ldapsearch failed ($RC)!"
67 test $KILLSERVERS != no && kill -HUP $KILLPIDS
71 echo "Adding a unique record..."
72 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
73 > /dev/null << EOTUNIQ1
74 dn: uid=dave,ou=users,o=unique
75 objectClass: inetOrgPerson
79 businessCategory: otest
82 # NOTE: use special chars in attr value to be used
83 # in internal searches ITS#4212
84 displayName: Dave (ITS#4212)
86 employeeType: contractor
90 if test $RC != 0 ; then
91 echo "ldapadd failed ($RC)!"
92 test $KILLSERVERS != no && kill -HUP $KILLPIDS
96 echo "Adding a non-unique record..."
97 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
98 $TESTOUT 2>&1 << EOTUNIQ2
99 dn: uid=bill,ou=users,o=unique
100 objectClass: inetOrgPerson
104 businessCategory: rtest
109 employeeType: contractor
113 if test $RC != $RCODEconstraint ; then
114 echo "unique check failed ($RC)!"
115 test $KILLSERVERS != no && kill -HUP $KILLPIDS
119 echo Dynamically retrieving initial configuration...
120 $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
121 cat <<EOF >$TESTDIR/initial-reference.ldif
122 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
123 objectClass: olcOverlayConfig
124 objectClass: olcUniqueConfig
125 olcOverlay: {0}unique
126 olcUniqueBase: o=unique
127 olcUniqueAttribute: employeeNumber
128 olcUniqueAttribute: displayName
131 diff $TESTDIR/initial-config.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
133 if test $RC != 0 ; then
134 echo "Initial configuration is not reported correctly."
135 test $KILLSERVERS != no && kill -HUP $KILLPIDS
139 echo Dynamically trying to add a URI with legacy attrs present...
140 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
141 > $TESTOUT 2>&1 <<EOF
142 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
145 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
148 if test $RC != 80 ; then
149 echo "legacy and unique_uri allowed together"
150 test $KILLSERVERS != no && kill -HUP $KILLPIDS
154 echo Dynamically trying to add legacy ignored attrs with legacy attrs present...
155 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
156 > $TESTOUT 2>&1 <<EOF
157 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
160 olcUniqueIgnore: objectClass
163 if test $RC != 80 ; then
164 echo "legacy attrs and legacy ignore attrs allowed together"
165 test $KILLSERVERS != no && kill -HUP $KILLPIDS
169 echo Verifying initial configuration intact...
170 $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
171 diff $TESTDIR/initial-config-recheck.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
173 if test $RC != 0 ; then
174 echo "Initial configuration damaged by unsuccessful modifies."
175 test $KILLSERVERS != no && kill -HUP $KILLPIDS
179 echo Dynamically removing legacy base...
180 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
181 > $TESTOUT 2>&1 <<EOF
182 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
184 delete: olcUniqueBase
187 if test $RC != 0 ; then
188 echo "base removal failed"
189 test $KILLSERVERS != no && kill -HUP $KILLPIDS
193 echo Verifying base removal...
194 $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
195 cat >$TESTDIR/baseremoval-reference.ldif <<EOF
196 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
197 objectClass: olcOverlayConfig
198 objectClass: olcUniqueConfig
199 olcOverlay: {0}unique
200 olcUniqueAttribute: employeeNumber
201 olcUniqueAttribute: displayName
204 diff $TESTDIR/baseremoval-config.ldif $TESTDIR/baseremoval-reference.ldif > /dev/null 2>&1
206 if test $RC != 0 ; then
207 echo "Configuration damaged by base removal"
208 test $KILLSERVERS != no && kill -HUP $KILLPIDS
212 echo "Adding a non-unique record..."
213 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
214 $TESTOUT 2>&1 << EOTUNIQ2
215 dn: uid=bill,ou=users,o=unique
216 objectClass: inetOrgPerson
220 businessCategory: rtest
225 employeeType: contractor
229 if test $RC != $RCODEconstraint ; then
230 echo "unique check failed ($RC)!"
231 test $KILLSERVERS != no && kill -HUP $KILLPIDS
235 echo Trying a legacy base outside of the backend...
236 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
237 > $TESTOUT 2>&1 <<EOF
238 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
241 olcUniqueBase: cn=config
244 if test $RC != 80 ; then
245 echo "out of backend scope base allowed"
246 test $KILLSERVERS != no && kill -HUP $KILLPIDS
250 echo "Adding and removing attrs..."
251 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
252 > $TESTOUT 2>&1 <<EOF
253 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
255 add: olcUniqueAttribute
256 olcUniqueAttribute: description
257 olcUniqueAttribute: telephoneNumber
259 delete: olcUniqueAttribute
260 olcUniqueAttribute: displayName
263 if test $RC != 0 ; then
264 echo "Unable to remove an attribute"
265 test $KILLSERVERS != no && kill -HUP $KILLPIDS
269 echo "Verifying we removed the right attr..."
270 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
271 $TESTOUT 2>&1 << EOTUNIQ2
272 dn: uid=bill,ou=users,o=unique
273 objectClass: inetOrgPerson
277 businessCategory: rtest
282 employeeType: contractor
286 if test $RC != $RCODEconstraint ; then
287 echo "olcUniqueAttribtue single deletion hit the wrong value"
288 test $KILLSERVERS != no && kill -HUP $KILLPIDS
292 echo Removing legacy config and adding URIs...
293 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
294 > $TESTOUT 2>&1 <<EOF
295 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
297 delete: olcUniqueAttribute
300 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
301 olcUniqueURI: ldap:///?description?one
304 if test $RC != 0 ; then
305 echo "Reconfiguration to URIs failed"
306 test $KILLSERVERS != no && kill -HUP $KILLPIDS
310 echo Dynamically retrieving second configuration...
311 $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
312 cat >$TESTDIR/second-reference.ldif <<EOF
313 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
314 objectClass: olcOverlayConfig
315 objectClass: olcUniqueConfig
316 olcOverlay: {0}unique
317 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
318 olcUniqueURI: ldap:///?description?one
321 diff $TESTDIR/second-config.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
323 if test $RC != 0 ; then
324 echo "Second configuration is not reported correctly."
325 test $KILLSERVERS != no && kill -HUP $KILLPIDS
329 echo "Adding a non-unique record..."
330 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
331 $TESTOUT 2>&1 << EOTUNIQ2
332 dn: uid=bill,ou=users,o=unique
333 objectClass: inetOrgPerson
337 businessCategory: rtest
342 employeeType: contractor
346 if test $RC != $RCODEconstraint ; then
347 echo "unique check failed ($RC)!"
348 test $KILLSERVERS != no && kill -HUP $KILLPIDS
352 echo Dynamically trying to add legacy base
353 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
354 > $TESTOUT 2>&1 <<EOF
355 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
358 olcUniqueBase: o=unique
361 if test $RC != 80 ; then
362 echo "legacy base allowed with URIs"
363 test $KILLSERVERS != no && kill -HUP $KILLPIDS
367 echo Dynamically trying to add legacy attrs
368 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
369 > $TESTOUT 2>&1 <<EOF
370 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
372 add: olcUniqueAttribute
373 olcUniqueAttribute: description
376 if test $RC != 80 ; then
377 echo "legacy attributes allowed with URIs"
378 test $KILLSERVERS != no && kill -HUP $KILLPIDS
382 echo Dynamically trying to add legacy strictness
383 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
384 > $TESTOUT 2>&1 <<EOF
385 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
388 olcUniqueStrict: TRUE
391 if test $RC != 80 ; then
392 echo "legacy strictness allowed with URIs"
393 test $KILLSERVERS != no && kill -HUP $KILLPIDS
397 #echo ----------------------
398 echo Dynamically trying a bad filter...
399 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
400 > $TESTOUT 2>&1 <<EOF
401 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
403 replace: olcUniqueURI
404 olcUniqueURI: ldap:///?sn?sub?((cn=e*))
407 if test $RC != 80 ; then
408 echo "bad filter allowed"
409 test $KILLSERVERS != no && kill -HUP $KILLPIDS
413 echo Verifying second configuration intact...
414 $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
415 diff $TESTDIR/second-config-recheck.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
417 if test $RC != 0 ; then
418 echo "Second configuration damaged by rejected modifies."
419 test $KILLSERVERS != no && kill -HUP $KILLPIDS
423 #echo ----------------------
424 echo Dynamically reconfiguring to use different URIs...
425 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
426 > $TESTOUT 2>&1 <<EOF
427 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
430 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
431 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
434 olcUniqueURI: ldap:///?description?one
437 if test $RC != 0 ; then
438 echo "unable to reconfigure"
439 test $KILLSERVERS != no && kill -HUP $KILLPIDS
443 echo Dynamically retrieving third configuration...
444 $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
445 cat >$TESTDIR/third-reference.ldif <<EOF
446 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
447 objectClass: olcOverlayConfig
448 objectClass: olcUniqueConfig
449 olcOverlay: {0}unique
450 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
451 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
452 olcUniqueURI: ldap:///?uid?sub?(cn=edgar)
455 diff $TESTDIR/third-config.ldif $TESTDIR/third-reference.ldif > /dev/null 2>&1
457 if test $RC != 0 ; then
458 echo "Third configuration is not reported correctly."
459 test $KILLSERVERS != no && kill -HUP $KILLPIDS
463 echo "Adding a record unique in both domains if filtered..."
465 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
467 dn: uid=edgar,ou=users,o=unique
468 objectClass: inetOrgPerson
475 if test $RC != 0 ; then
476 echo "unique check failed ($RC)!"
477 test $KILLSERVERS != no && kill -HUP $KILLPIDS
481 echo "Adding a record unique in all domains because of filter conditions "
482 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
484 dn: uid=empty,ou=users,o=unique
485 objectClass: inetOrgPerson
492 if test $RC != 0 ; then
493 echo "spurious unique error ($RC)!"
494 test $KILLSERVERS != no && kill -HUP $KILLPIDS
499 echo "Adding a record unique in one domain, non-unique in the filtered domain..."
501 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
503 dn: uid=elvis,ou=users,o=unique
504 objectClass: inetOrgPerson
511 if test $RC != $RCODEconstraint ; then
512 echo "unique check failed ($RC)!"
513 test $KILLSERVERS != no && kill -HUP $KILLPIDS
517 #echo ----------------------
518 echo Dynamically reconfiguring to use attribute-ignore URIs...
519 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
520 > $TESTOUT 2>&1 <<EOF
521 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
523 replace: olcUniqueURI
524 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
527 if test $RC != 0 ; then
528 echo "unable to reconfigure"
529 test $KILLSERVERS != no && kill -HUP $KILLPIDS
533 echo Dynamically retrieving fourth configuration...
534 $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
535 cat >$TESTDIR/fourth-reference.ldif <<EOF
536 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
537 objectClass: olcOverlayConfig
538 objectClass: olcUniqueConfig
539 olcOverlay: {0}unique
540 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
543 diff $TESTDIR/fourth-config.ldif $TESTDIR/fourth-reference.ldif > /dev/null 2>&1
545 if test $RC != 0 ; then
546 echo "Fourth configuration is not reported correctly."
547 test $KILLSERVERS != no && kill -HUP $KILLPIDS
551 echo "Adding a record unique in the ignore-domain..."
553 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
555 dn: uid=elvis,ou=users,o=unique
556 objectClass: inetOrgPerson
560 description: left the building
564 if test $RC != 0 ; then
565 echo "unique check failed ($RC)!"
566 test $KILLSERVERS != no && kill -HUP $KILLPIDS
570 echo "Adding a record non-unique in the ignore-domain..."
572 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
574 dn: uid=harry,ou=users,o=unique
575 objectClass: inetOrgPerson
579 description: left the building
583 if test $RC != $RCODEconstraint ; then
584 echo "unique check failed ($RC)!"
585 test $KILLSERVERS != no && kill -HUP $KILLPIDS
589 test $KILLSERVERS != no && kill -HUP $KILLPIDS
591 echo ">>>>> Test succeeded"
593 test $KILLSERVERS != no && wait