2 # $OpenLDAP: pkg/ldap/tests/scripts/test024-unique,v 1.8.2.5 2008/02/11 23:26:51 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 2004-2008 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*)
430 olcUniqueURI: ldap:///?description?one
433 if test $RC != 0 ; then
434 echo "unable to reconfigure"
435 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
439 echo Dynamically retrieving third configuration...
440 $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
441 cat >$TESTDIR/third-reference.ldif
<<EOF
442 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
443 objectClass: olcOverlayConfig
444 objectClass: olcUniqueConfig
445 olcOverlay: {0}unique
446 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
447 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
450 diff $TESTDIR/third-config.ldif
$TESTDIR/third-reference.ldif
> /dev
/null
2>&1
452 if test $RC != 0 ; then
453 echo "Third configuration is not reported correctly."
454 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
458 echo "Adding a record unique in both domains if filtered..."
460 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
462 dn: uid=edgar,ou=users,o=unique
463 objectClass: inetOrgPerson
470 if test $RC != 0 ; then
471 echo "unique check failed ($RC)!"
472 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
476 echo "Adding a record unique in one domain, non-unique in the filtered domain..."
478 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
480 dn: uid=elvis,ou=users,o=unique
481 objectClass: inetOrgPerson
488 if test $RC != 19 ; then
489 echo "unique check failed ($RC)!"
490 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
494 #echo ----------------------
495 echo Dynamically reconfiguring to use attribute-ignore URIs...
496 $LDAPMODIFY -D cn
=config
-h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
497 > $TESTOUT 2>&1 <<EOF
498 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
500 replace: olcUniqueURI
501 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
504 if test $RC != 0 ; then
505 echo "unable to reconfigure"
506 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
510 echo Dynamically retrieving fourth configuration...
511 $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
512 cat >$TESTDIR/fourth-reference.ldif
<<EOF
513 dn: olcOverlay={0}unique,olcDatabase={1}$BACKEND,cn=config
514 objectClass: olcOverlayConfig
515 objectClass: olcUniqueConfig
516 olcOverlay: {0}unique
517 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
520 diff $TESTDIR/fourth-config.ldif
$TESTDIR/fourth-reference.ldif
> /dev
/null
2>&1
522 if test $RC != 0 ; then
523 echo "Fourth configuration is not reported correctly."
524 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
528 echo "Adding a record unique in the ignore-domain..."
530 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
532 dn: uid=elvis,ou=users,o=unique
533 objectClass: inetOrgPerson
537 description: left the building
541 if test $RC != 0 ; then
542 echo "unique check failed ($RC)!"
543 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
547 echo "Adding a record non-unique in the ignore-domain..."
549 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
551 dn: uid=harry,ou=users,o=unique
552 objectClass: inetOrgPerson
556 description: left the building
560 if test $RC != 19 ; then
561 echo "unique check failed ($RC)!"
562 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
566 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
568 echo ">>>>> Test succeeded"
570 test $KILLSERVERS != no
&& wait