3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-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 PCACHETTL=${PCACHETTL-"1m"}
17 PCACHENTTL=${PCACHENTTL-"1m"}
18 PCACHESTTL=${PCACHESTTL-"1m"}
19 PCACHE_ENTRY_LIMIT=${PCACHE_ENTRY_LIMIT-"6"}
20 PCACHE_CCPERIOD=${PCACHE_CCPERIOD-"2"}
21 PCACHETTR=${PCACHETTR-"2"}
22 PCACHEBTTR=${PCACHEBTTR-"5"}
24 . $SRCDIR/scripts/defines.sh
26 if test $PROXYCACHE = pcacheno; then
27 echo "Proxy cache overlay not available, test skipped"
31 if test $BACKLDAP = "ldapno" ; then
32 echo "LDAP backend not available, test skipped"
36 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
42 # - perform first set of searches at the proxy
43 # - verify cacheability
44 # - perform second set of searches at the proxy
45 # - verify answerability
47 echo "Starting master slapd on TCP/IP port $PORT1..."
48 . $CONFFILTER < $CACHEMASTERCONF > $CONF1
49 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
51 if test $WAIT != 0 ; then
59 echo "Using ldapsearch to check that master slapd is running..."
60 for i in 0 1 2 3 4 5; do
61 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
62 'objectclass=*' > /dev/null 2>&1
64 if test $RC = 0 ; then
67 echo "Waiting 5 seconds for slapd to start..."
71 if test $RC != 0 ; then
72 echo "ldapsearch failed ($RC)!"
73 test $KILLSERVERS != no && kill -HUP $KILLPIDS
77 echo "Using ldapadd to populate the master directory..."
78 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
79 $LDIFORDERED > /dev/null 2>&1
81 if test $RC != 0 ; then
82 echo "ldapadd failed ($RC)!"
83 test $KILLSERVERS != no && kill -HUP $KILLPIDS
87 echo "Starting proxy cache on TCP/IP port $PORT2..."
88 . $CONFFILTER < $PROXYCACHECONF | sed \
89 -e "s/@TTL@/${PCACHETTL}/" \
90 -e "s/@NTTL@/${PCACHENTTL}/" \
91 -e "s/@STTL@/${PCACHENTTL}/" \
92 -e "s/@TTR@/${PCACHETTR}/" \
93 -e "s/@ENTRY_LIMIT@/${PCACHE_ENTRY_LIMIT}/" \
94 -e "s/@CCPERIOD@/${PCACHE_CCPERIOD}/" \
95 -e "s/@BTTR@/${PCACHEBTTR}/" \
98 $SLAPD -f $CONF2 -h $URI2 -d $LVL -d pcache > $LOG2 2>&1 &
100 if test $WAIT != 0 ; then
101 echo CACHEPID $CACHEPID
104 KILLPIDS="$KILLPIDS $CACHEPID"
108 echo "Using ldapsearch to check that proxy slapd is running..."
109 for i in 0 1 2 3 4 5; do
110 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
111 'objectclass=*' > /dev/null 2>&1
113 if test $RC = 0 ; then
116 echo "Waiting 5 seconds for slapd to start..."
120 if test $RC != 0 ; then
121 echo "ldapsearch failed ($RC)!"
122 test $KILLSERVERS != no && kill -HUP $KILLPIDS
126 cat /dev/null > $SEARCHOUT
128 echo "Making queries on the proxy cache..."
133 echo "Query $CNT: filter:$FILTER attrs:all (expect nothing)"
134 echo "# Query $CNT: filter:$FILTER attrs:all (expect nothing)" >> $SEARCHOUT
135 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
136 "$FILTER" >> $SEARCHOUT 2>> $TESTOUT
138 if test $RC != 0 ; then
139 echo "ldapsearch failed ($RC)!"
140 test $KILLSERVERS != no && kill -HUP $KILLPIDS
144 # ITS#4491, if debug messages are unavailable, we can't verify the tests.
145 grep "query template" $LOG2 > /dev/null
147 if test $RC != 0 ; then
148 echo "Debug messages unavailable, test aborted..."
149 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
154 FILTER="(|(cn=*Jon*)(sn=Jon*))"
155 ATTRS="cn sn title uid"
156 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
157 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
158 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
159 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
161 if test $RC != 0 ; then
162 echo "ldapsearch failed ($RC)!"
163 test $KILLSERVERS != no && kill -HUP $KILLPIDS
170 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
171 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
172 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
173 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
175 if test $RC != 0 ; then
176 echo "ldapsearch failed ($RC)!"
177 test $KILLSERVERS != no && kill -HUP $KILLPIDS
183 ATTRS="cn sn title uid"
184 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
185 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
186 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
187 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
189 if test $RC != 0 ; then
190 echo "ldapsearch failed ($RC)!"
191 test $KILLSERVERS != no && kill -HUP $KILLPIDS
197 ATTRS="mail postaladdress telephonenumber cn uid"
198 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
199 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
200 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
201 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
203 if test $RC != 0 ; then
204 echo "ldapsearch failed ($RC)!"
205 test $KILLSERVERS != no && kill -HUP $KILLPIDS
210 FILTER="(mail=*@mail.alumni.example.com)"
211 ATTRS="cn sn title uid"
212 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
213 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
214 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
215 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
217 if test $RC != 0 ; then
218 echo "ldapsearch failed ($RC)!"
219 test $KILLSERVERS != no && kill -HUP $KILLPIDS
225 ATTRS="cn sn title uid"
226 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
227 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
228 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
229 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
231 if test $RC != 0 ; then
232 echo "ldapsearch failed ($RC)!"
233 test $KILLSERVERS != no && kill -HUP $KILLPIDS
238 FILTER="(mail=*example.com)"
239 ATTRS="cn sn title uid"
240 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
242 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
243 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
244 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
245 -D "$USERDN" -w "$UPASSWD" \
246 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
250 echo "ldapsearch should have failed!"
251 test $KILLSERVERS != no && kill -HUP $KILLPIDS
255 echo "ldapsearch failed ($RC)"
258 echo "ldapsearch failed ($RC)!"
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
267 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
269 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
270 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
271 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
272 -D "$USERDN" -w "$UPASSWD" \
273 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
277 echo "ldapsearch should have failed!"
278 test $KILLSERVERS != no && kill -HUP $KILLPIDS
282 echo "ldapsearch failed ($RC)"
285 echo "ldapsearch failed ($RC)!"
286 test $KILLSERVERS != no && kill -HUP $KILLPIDS
293 # queries 2-6,8-9 are cacheable
294 CACHEABILITY=011111011
295 grep CACHEABLE $LOG2 | awk '{
297 printf "Query %d not cacheable\n",NR
299 printf "Query %d cacheable\n",NR
301 CACHED=`grep CACHEABLE $LOG2 | awk '{
308 if test "$CACHEABILITY" = "$CACHED" ; then
309 echo "Successfully verified cacheability"
311 echo "Error in verifying cacheability"
312 test $KILLSERVERS != no && kill -HUP $KILLPIDS
317 FILTER="(|(cn=*Jones)(sn=Jones))"
318 ATTRS="cn sn title uid"
319 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
320 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
321 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
322 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
324 if test $RC != 0 ; then
325 echo "ldapsearch failed ($RC)!"
326 test $KILLSERVERS != no && kill -HUP $KILLPIDS
332 ATTRS="cn sn title uid"
333 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
334 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
335 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
336 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
338 if test $RC != 0 ; then
339 echo "ldapsearch failed ($RC)!"
340 test $KILLSERVERS != no && kill -HUP $KILLPIDS
346 ATTRS="mail postaladdress telephonenumber cn uid"
347 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
348 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
349 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
350 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
352 if test $RC != 0 ; then
353 echo "ldapsearch failed ($RC)!"
354 test $KILLSERVERS != no && kill -HUP $KILLPIDS
359 FILTER="(mail=jaj@mail.alumni.example.com)"
360 ATTRS="cn sn title uid"
361 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
362 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
363 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
364 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
367 if test $RC != 0 ; then
368 echo "ldapsearch failed ($RC)!"
369 test $KILLSERVERS != no && kill -HUP $KILLPIDS
374 FILTER="(mail=*example.com)"
375 ATTRS="cn sn title uid"
376 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
378 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
379 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
380 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
381 -D "$USERDN" -w "$UPASSWD" \
382 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
386 echo "ldapsearch should have failed!"
387 test $KILLSERVERS != no && kill -HUP $KILLPIDS
391 echo "ldapsearch failed ($RC)"
394 echo "ldapsearch failed ($RC)!"
395 test $KILLSERVERS != no && kill -HUP $KILLPIDS
403 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
405 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
406 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
407 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
408 -D "$USERDN" -w "$UPASSWD" \
409 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
413 echo "ldapsearch should have failed!"
414 test $KILLSERVERS != no && kill -HUP $KILLPIDS
418 echo "ldapsearch failed ($RC)"
421 echo "ldapsearch failed ($RC)!"
422 test $KILLSERVERS != no && kill -HUP $KILLPIDS
427 #queries 10-12,15 are answerable, 13-14 are not
428 #actually, 12 would be answerable, but since 8 made mail=*example.com
429 #not answerable because of sizelimit, queries contained in it are no longer
432 grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{
435 printf "Query %d not answerable\n",NR
437 printf "Query %d answerable\n",NR
440 ANSWERED=`grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{
449 if test "$ANSWERABILITY" = "$ANSWERED" ; then
450 echo "Successfully verified answerability"
452 echo "Error in verifying answerability"
453 test $KILLSERVERS != no && kill -HUP $KILLPIDS
457 echo "Filtering ldapsearch results..."
458 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
459 echo "Filtering original ldif..."
460 . $LDIFFILTER < $PROXYCACHEOUT > $LDIFFLT
461 echo "Comparing filter output..."
462 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
464 if test $? != 0 ; then
465 echo "Comparison failed"
466 test $KILLSERVERS != no && kill -HUP $KILLPIDS
471 echo "Testing cache refresh"
474 FILTER="(&(objectclass=person)(uid=dots))"
475 ATTRS="cn mail telephonenumber"
476 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
477 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
478 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
479 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
481 if test $RC != 0 ; then
482 echo "ldapsearch failed ($RC)!"
483 test $KILLSERVERS != no && kill -HUP $KILLPIDS
487 $LDAPMODIFY -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD <<EOF \
489 dn: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com
492 mail: dots@admin.example2.com
497 if test $RC != 0 ; then
498 echo "ldapmodify failed ($RC)!"
499 test $KILLSERVERS != no && kill -HUP $KILLPIDS
503 SLEEP=`expr $PCACHETTR + $PCACHE_CCPERIOD`
504 echo "Waiting $SLEEP seconds for cache to refresh"
508 echo "Checking entry again"
509 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
510 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
512 if test $RC != 0 ; then
513 echo "ldapsearch failed ($RC)!"
514 test $KILLSERVERS != no && kill -HUP $KILLPIDS
518 grep "^mail: dots@admin" $SEARCHOUT > /dev/null
520 if test $RC != 0 ; then
521 echo "Refresh failed"
522 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
527 echo "Testing Bind caching"
530 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
532 echo "Query $CNT: $USERDN"
533 echo "# Query $CNT: $USERDN" >> $SEARCHOUT
534 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
535 -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
537 if test $RC != 0 ; then
538 echo "ldapsearch failed ($RC)!"
539 test $KILLSERVERS != no && kill -HUP $KILLPIDS
543 grep "CACHING BIND" $LOG2 > /dev/null
545 if test $RC != 0 ; then
546 echo "Refresh failed"
547 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
552 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
554 echo "Query $CNT: (Bind should be cached)"
555 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
556 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
557 -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
559 if test $RC != 0 ; then
560 echo "ldapsearch failed ($RC)!"
561 test $KILLSERVERS != no && kill -HUP $KILLPIDS
565 grep "CACHED BIND" $LOG2 > /dev/null
567 if test $RC != 0 ; then
568 echo "Refresh failed"
569 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
574 echo "Testing pwdModify"
575 $LDAPPASSWD -h $LOCALHOST -p $PORT2 \
576 -D "$MANAGERDN" -w "$PASSWD" -s newpw "$USERDN" >> $TESTOUT 2>&1
578 if test $RC != 0 ; then
579 echo "ldappasswd failed ($RC)!"
580 test $KILLSERVERS != no && kill -HUP $KILLPIDS
584 RC=`grep "CACH.* BIND" $LOG2 | wc -l`
585 if test $RC != 3 ; then
586 echo "ldappasswd didn't update the cache"
587 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
592 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
594 echo "Query $CNT: (Bind should be cached)"
595 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
596 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
597 -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
599 if test $RC != 0 ; then
600 echo "ldapsearch failed ($RC)!"
601 test $KILLSERVERS != no && kill -HUP $KILLPIDS
605 RC=`grep "CACH.* BIND" $LOG2 | wc -l`
606 if test $RC != 4 ; then
607 echo "Bind wasn't answered from cache"
608 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
611 test $KILLSERVERS != no && kill -HUP $KILLPIDS
613 echo ">>>>> Test succeeded"
615 test $KILLSERVERS != no && wait