]> git.sur5r.net Git - openldap/blob - tests/scripts/test024-unique
Happy New Year (belated)
[openldap] / tests / scripts / test024-unique
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2004-2008 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
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>.
15
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $UNIQUE = uniqueno; then
20         echo "Attribute Uniqueness overlay not available, test skipped"
21         exit 0
22 fi
23
24 mkdir -p $TESTDIR $DBDIR1
25
26 $SLAPPASSWD -g -n >$CONFIGPWF
27 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
28
29 echo "Running slapadd to build slapd database..."
30 . $CONFFILTER $BACKEND $MONITORDB < $UNIQUECONF > $CONF1
31 $SLAPADD -f $CONF1 -l $LDIFUNIQUE
32 RC=$?
33 if test $RC != 0 ; then
34         echo "slapadd failed ($RC)!"
35         exit $RC
36 fi
37
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 &
41 PID=$!
42 if test $WAIT != 0 ; then
43     echo PID $PID
44     read foo
45 fi
46 KILLPIDS="$PID"
47
48 sleep 1
49
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
54         RC=$?
55         if test $RC = 0 ; then
56                 break
57         fi
58         echo "Waiting 5 seconds for slapd to start..."
59         sleep 5
60 done
61
62 if test $RC != 0 ; then
63         echo "ldapsearch failed ($RC)!"
64         test $KILLSERVERS != no && kill -HUP $KILLPIDS
65         exit $RC
66 fi
67
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
73 uid: dave
74 sn: nothere
75 cn: dave
76 businessCategory: otest
77 carLicense: TEST
78 departmentNumber: 42
79 # NOTE: use special chars in attr value to be used
80 # in internal searches ITS#4212
81 displayName: Dave (ITS#4212)
82 employeeNumber: 69
83 employeeType: contractor
84 givenName: Dave
85 EOTUNIQ1
86 RC=$?
87 if test $RC != 0 ; then
88         echo "ldapadd failed ($RC)!"
89         test $KILLSERVERS != no && kill -HUP $KILLPIDS
90         exit $RC
91 fi
92
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
98 uid: bill
99 sn: johnson
100 cn: bill
101 businessCategory: rtest
102 carLicense: ABC123
103 departmentNumber: 42
104 displayName: Bill
105 employeeNumber: 5150
106 employeeType: contractor
107 givenName: Bill
108 EOTUNIQ2
109 RC=$?
110 if test $RC != 19 ; then
111         echo "unique check failed ($RC)!"
112         test $KILLSERVERS != no && kill -HUP $KILLPIDS
113         exit -1
114 fi
115
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
126
127 EOF
128 diff $TESTDIR/initial-config.ldif $TESTDIR/initial-reference.ldif > /dev/null 2>&1
129 RC=$?
130 if test $RC != 0 ; then
131     echo "Initial configuration is not reported correctly."
132     test $KILLSERVERS != no && kill -HUP $KILLPIDS
133     exit -1
134 fi
135
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
140 changetype: modify
141 add: olcUniqueURI
142 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
143 EOF
144 RC=$?
145 if test $RC != 80 ; then
146         echo "legacy and unique_uri allowed together"
147         test $KILLSERVERS != no && kill -HUP $KILLPIDS
148         exit -1
149 fi
150
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
155 changetype: modify
156 add: olcUniqueIgnore
157 olcUniqueIgnore: objectClass
158 EOF
159 RC=$?
160 if test $RC != 80 ; then
161         echo "legacy attrs and legacy ignore attrs allowed together"
162         test $KILLSERVERS != no && kill -HUP $KILLPIDS
163         exit -1
164 fi
165
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
169 RC=$?
170 if test $RC != 0 ; then
171     echo "Initial configuration damaged by unsuccessful modifies."
172     test $KILLSERVERS != no && kill -HUP $KILLPIDS
173     exit -1
174 fi
175
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
180 changetype: modify
181 delete: olcUniqueBase
182 EOF
183 RC=$?
184 if test $RC != 0 ; then
185         echo "base removal failed"
186         test $KILLSERVERS != no && kill -HUP $KILLPIDS
187         exit -1
188 fi
189
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
199
200 EOF
201 diff $TESTDIR/baseremoval-config.ldif $TESTDIR/baseremoval-reference.ldif > /dev/null 2>&1
202 RC=$?
203 if test $RC != 0 ; then
204     echo "Configuration damaged by base removal"
205     test $KILLSERVERS != no && kill -HUP $KILLPIDS
206     exit -1
207 fi
208
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
214 uid: bill
215 sn: johnson
216 cn: bill
217 businessCategory: rtest
218 carLicense: ABC123
219 departmentNumber: 42
220 displayName: Bill
221 employeeNumber: 5150
222 employeeType: contractor
223 givenName: Bill
224 EOTUNIQ2
225 RC=$?
226 if test $RC != 19 ; then
227         echo "unique check failed ($RC)!"
228         test $KILLSERVERS != no && kill -HUP $KILLPIDS
229         exit -1
230 fi
231
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
236 changetype: modify
237 add: olcUniqueBase
238 olcUniqueBase: cn=config
239 EOF
240 RC=$?
241 if test $RC != 80 ; then
242         echo "out of backend scope base allowed"
243         test $KILLSERVERS != no && kill -HUP $KILLPIDS
244         exit -1
245 fi
246
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
251 changetype: modify
252 add: olcUniqueAttribute
253 olcUniqueAttribute: description
254 olcUniqueAttribute: telephoneNumber
255 -
256 delete: olcUniqueAttribute
257 olcUniqueAttribute: displayName
258 EOF
259 RC=$?
260 if test $RC != 0 ; then
261         echo "Unable to remove an attribute"
262         test $KILLSERVERS != no && kill -HUP $KILLPIDS
263         exit -1
264 fi
265
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
271 uid: bill
272 sn: johnson
273 cn: bill
274 businessCategory: rtest
275 carLicense: ABC123
276 departmentNumber: 42
277 displayName: Bill
278 employeeNumber: 5150
279 employeeType: contractor
280 givenName: Bill
281 EOTUNIQ2
282 RC=$?
283 if test $RC != 19 ; then
284         echo "olcUniqueAttribtue single deletion hit the wrong value"
285         test $KILLSERVERS != no && kill -HUP $KILLPIDS
286         exit -1
287 fi
288
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
293 changetype: modify
294 delete: olcUniqueAttribute
295 -
296 add: olcUniqueURI
297 olcUniqueURI: ldap:///?employeeNumber,displayName?sub
298 olcUniqueURI: ldap:///?description?one
299 EOF
300 RC=$?
301 if test $RC != 0 ; then
302         echo "Reconfiguration to URIs failed"
303         test $KILLSERVERS != no && kill -HUP $KILLPIDS
304         exit -1
305 fi
306
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
316
317 EOF
318 diff $TESTDIR/second-config.ldif $TESTDIR/second-reference.ldif > /dev/null 2>&1
319 RC=$?
320 if test $RC != 0 ; then
321     echo "Second configuration is not reported correctly."
322     test $KILLSERVERS != no && kill -HUP $KILLPIDS
323     exit -1
324 fi
325
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
331 uid: bill
332 sn: johnson
333 cn: bill
334 businessCategory: rtest
335 carLicense: ABC123
336 departmentNumber: 42
337 displayName: Bill
338 employeeNumber: 5150
339 employeeType: contractor
340 givenName: Bill
341 EOTUNIQ2
342 RC=$?
343 if test $RC != 19 ; then
344         echo "unique check failed ($RC)!"
345         test $KILLSERVERS != no && kill -HUP $KILLPIDS
346         exit -1
347 fi
348
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
353 changetype: modify
354 add: olcUniqueBase
355 olcUniqueBase: o=unique
356 EOF
357 RC=$?
358 if test $RC != 80 ; then
359         echo "legacy base allowed with URIs"
360         test $KILLSERVERS != no && kill -HUP $KILLPIDS
361         exit -1
362 fi
363
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
368 changetype: modify
369 add: olcUniqueAttribute
370 olcUniqueAttribute: description
371 EOF
372 RC=$?
373 if test $RC != 80 ; then
374         echo "legacy attributes allowed with URIs"
375         test $KILLSERVERS != no && kill -HUP $KILLPIDS
376         exit -1
377 fi
378
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
383 changetype: modify
384 add: olcUniqueStrict
385 olcUniqueStrict: TRUE
386 EOF
387 RC=$?
388 if test $RC != 80 ; then
389         echo "legacy strictness allowed with URIs"
390         test $KILLSERVERS != no && kill -HUP $KILLPIDS
391         exit -1
392 fi
393
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
399 changetype: modify
400 replace: olcUniqueURI
401 olcUniqueURI: ldap:///?sn?sub?((cn=e*))
402 EOF
403 RC=$?
404 if test $RC != 80 ; then
405         echo "bad filter allowed"
406         test $KILLSERVERS != no && kill -HUP $KILLPIDS
407         exit -1
408 fi
409
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
413 RC=$?
414 if test $RC != 0 ; then
415     echo "Second configuration damaged by rejected modifies."
416     test $KILLSERVERS != no && kill -HUP $KILLPIDS
417     exit -1
418 fi
419
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
425 changetype: modify
426 add: olcUniqueURI
427 olcUniqueURI: ldap:///?sn?sub?(cn=e*)
428 -
429 delete: olcUniqueURI
430 olcUniqueURI: ldap:///?description?one
431 EOF
432 RC=$?
433 if test $RC != 0 ; then
434         echo "unable to reconfigure"
435         test $KILLSERVERS != no && kill -HUP $KILLPIDS
436         exit -1
437 fi
438
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*)
448
449 EOF
450 diff $TESTDIR/third-config.ldif $TESTDIR/third-reference.ldif > /dev/null 2>&1
451 RC=$?
452 if test $RC != 0 ; then
453     echo "Third configuration is not reported correctly."
454     test $KILLSERVERS != no && kill -HUP $KILLPIDS
455     exit -1
456 fi
457
458 echo "Adding a record unique in both domains if filtered..."
459
460 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
461          $TESTOUT 2>&1 << EOF
462 dn: uid=edgar,ou=users,o=unique
463 objectClass: inetOrgPerson
464 uid: edgar
465 sn: johnson
466 cn: edgar
467 EOF
468
469 RC=$?
470 if test $RC != 0 ; then
471         echo "unique check failed ($RC)!"
472         test $KILLSERVERS != no && kill -HUP $KILLPIDS
473         exit -1
474 fi
475
476 echo "Adding a record unique in one domain, non-unique in the filtered domain..."
477
478 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
479          $TESTOUT 2>&1 << EOF
480 dn: uid=elvis,ou=users,o=unique
481 objectClass: inetOrgPerson
482 uid: elvis
483 sn: johnson
484 cn: elvis
485 EOF
486
487 RC=$?
488 if test $RC != 19 ; then
489         echo "unique check failed ($RC)!"
490         test $KILLSERVERS != no && kill -HUP $KILLPIDS
491         exit -1
492 fi
493
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
499 changetype: modify
500 replace: olcUniqueURI
501 olcUniqueURI: ignore ldap:///?objectClass,uid,cn,sn?sub
502 EOF
503 RC=$?
504 if test $RC != 0 ; then
505         echo "unable to reconfigure"
506         test $KILLSERVERS != no && kill -HUP $KILLPIDS
507         exit -1
508 fi
509
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
518
519 EOF
520 diff $TESTDIR/fourth-config.ldif $TESTDIR/fourth-reference.ldif > /dev/null 2>&1
521 RC=$?
522 if test $RC != 0 ; then
523     echo "Fourth configuration is not reported correctly."
524     test $KILLSERVERS != no && kill -HUP $KILLPIDS
525     exit -1
526 fi
527
528 echo "Adding a record unique in the ignore-domain..."
529
530 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
531          $TESTOUT 2>&1 << EOF
532 dn: uid=elvis,ou=users,o=unique
533 objectClass: inetOrgPerson
534 uid: elvis
535 sn: johnson
536 cn: elvis
537 description: left the building
538 EOF
539
540 RC=$?
541 if test $RC != 0 ; then
542         echo "unique check failed ($RC)!"
543         test $KILLSERVERS != no && kill -HUP $KILLPIDS
544         exit -1
545 fi
546
547 echo "Adding a record non-unique in the ignore-domain..."
548
549 $LDAPADD -D "$UNIQUEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
550          $TESTOUT 2>&1 << EOF
551 dn: uid=harry,ou=users,o=unique
552 objectClass: inetOrgPerson
553 uid: harry
554 sn: johnson
555 cn: harry
556 description: left the building
557 EOF
558
559 RC=$?
560 if test $RC != 19 ; then
561         echo "unique check failed ($RC)!"
562         test $KILLSERVERS != no && kill -HUP $KILLPIDS
563         exit -1
564 fi
565
566 test $KILLSERVERS != no && kill -HUP $KILLPIDS
567
568 echo ">>>>> Test succeeded"
569
570 test $KILLSERVERS != no && wait
571
572 exit 0