]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
ITS#5810 skip test for LDIF backend
[openldap] / tests / scripts / test020-proxycache
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2009 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 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"}
23
24 . $SRCDIR/scripts/defines.sh
25
26 if test $PROXYCACHE = pcacheno; then 
27         echo "Proxy cache overlay not available, test skipped"
28         exit 0
29 fi 
30
31 if test $BACKLDAP = "ldapno" ; then 
32         echo "LDAP backend not available, test skipped"
33         exit 0
34 fi 
35
36 if test $BACKEND = ldif ; then
37         # The (mail=example.com*) queries hit a sizelimit, so which
38         # entry is returned depends on the ordering in the backend.
39         echo "Test does not support $BACKEND backend, test skipped"
40         exit 0
41 fi
42
43 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
44
45 # Test proxy caching:
46 # - start master
47 # - start proxy cache
48 # - populate master 
49 # - perform first set of searches at the proxy
50 # - verify cacheability
51 # - perform second set of searches at the proxy 
52 # - verify answerability
53
54 echo "Starting master slapd on TCP/IP port $PORT1..."
55 . $CONFFILTER < $CACHEMASTERCONF > $CONF1
56 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
57 PID=$!
58 if test $WAIT != 0 ; then
59         echo PID $PID
60         read foo
61 fi
62 KILLPIDS="$PID"
63
64 sleep 1
65
66 echo "Using ldapsearch to check that master slapd is running..."
67 for i in 0 1 2 3 4 5; do
68         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
69                 'objectclass=*' > /dev/null 2>&1
70         RC=$?
71         if test $RC = 0 ; then
72                 break
73         fi
74         echo "Waiting 5 seconds for slapd to start..."
75         sleep 5
76 done
77
78 if test $RC != 0 ; then
79         echo "ldapsearch failed ($RC)!"
80         test $KILLSERVERS != no && kill -HUP $KILLPIDS
81         exit $RC
82 fi
83
84 echo "Using ldapadd to populate the master directory..."
85 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
86         $LDIFORDERED > /dev/null 2>&1
87 RC=$?
88 if test $RC != 0 ; then
89         echo "ldapadd failed ($RC)!"
90         test $KILLSERVERS != no && kill -HUP $KILLPIDS
91         exit $RC
92 fi
93
94 echo "Starting proxy cache on TCP/IP port $PORT2..."
95 . $CONFFILTER < $PROXYCACHECONF | sed \
96         -e "s/@TTL@/${PCACHETTL}/"                      \
97         -e "s/@NTTL@/${PCACHENTTL}/"            \
98         -e "s/@STTL@/${PCACHENTTL}/"            \
99         -e "s/@TTR@/${PCACHETTR}/"                      \
100         -e "s/@ENTRY_LIMIT@/${PCACHE_ENTRY_LIMIT}/"     \
101         -e "s/@CCPERIOD@/${PCACHE_CCPERIOD}/"                   \
102         -e "s/@BTTR@/${PCACHEBTTR}/"                    \
103         > $CONF2
104
105 $SLAPD -f $CONF2 -h $URI2 -d $LVL -d pcache > $LOG2 2>&1 &
106 CACHEPID=$!
107 if test $WAIT != 0 ; then
108         echo CACHEPID $CACHEPID
109         read foo
110 fi
111 KILLPIDS="$KILLPIDS $CACHEPID"
112
113 sleep 1
114
115 echo "Using ldapsearch to check that proxy slapd is running..."
116 for i in 0 1 2 3 4 5; do
117         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
118                 'objectclass=*' > /dev/null 2>&1
119         RC=$?
120         if test $RC = 0 ; then
121                 break
122         fi
123         echo "Waiting 5 seconds for slapd to start..."
124         sleep 5
125 done
126
127 if test $RC != 0 ; then
128         echo "ldapsearch failed ($RC)!"
129         test $KILLSERVERS != no && kill -HUP $KILLPIDS
130         exit $RC
131 fi
132
133 cat /dev/null > $SEARCHOUT
134
135 echo "Making queries on the proxy cache..." 
136 CNT=0
137
138 CNT=`expr $CNT + 1`
139 FILTER="(sn=Jon)"
140 echo "Query $CNT: filter:$FILTER attrs:all (expect nothing)" 
141 echo "# Query $CNT: filter:$FILTER attrs:all (expect nothing)" >> $SEARCHOUT
142 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
143         "$FILTER" >> $SEARCHOUT 2>> $TESTOUT
144 RC=$?
145 if test $RC != 0 ; then
146         echo "ldapsearch failed ($RC)!"
147         test $KILLSERVERS != no && kill -HUP $KILLPIDS
148         exit $RC
149 fi
150
151 # ITS#4491, if debug messages are unavailable, we can't verify the tests.
152 grep "query template" $LOG2 > /dev/null
153 RC=$?
154 if test $RC != 0 ; then
155         echo "Debug messages unavailable, test aborted..."
156         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
157         exit 0
158 fi
159
160 CNT=`expr $CNT + 1`
161 FILTER="(|(cn=*Jon*)(sn=Jon*))"
162 ATTRS="cn sn title uid"
163 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
164 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
165 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
166         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
167 RC=$?
168 if test $RC != 0 ; then
169         echo "ldapsearch failed ($RC)!"
170         test $KILLSERVERS != no && kill -HUP $KILLPIDS
171         exit $RC
172 fi
173
174 CNT=`expr $CNT + 1`
175 FILTER="(sn=Smith*)"
176 ATTRS="cn sn uid"
177 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
178 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
179 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
180         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
181 RC=$?
182 if test $RC != 0 ; then
183         echo "ldapsearch failed ($RC)!"
184         test $KILLSERVERS != no && kill -HUP $KILLPIDS
185         exit $RC
186 fi
187
188 CNT=`expr $CNT + 1`
189 FILTER="(sn=Doe*)"
190 ATTRS="cn sn title uid"
191 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
192 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
193 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
194         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
195 RC=$?
196 if test $RC != 0 ; then
197         echo "ldapsearch failed ($RC)!"
198         test $KILLSERVERS != no && kill -HUP $KILLPIDS
199         exit $RC
200 fi
201
202 CNT=`expr $CNT + 1`
203 FILTER="(uid=johnd)"
204 ATTRS="mail postaladdress telephonenumber cn uid"
205 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
206 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
207 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
208         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
209 RC=$?
210 if test $RC != 0 ; then
211         echo "ldapsearch failed ($RC)!"
212         test $KILLSERVERS != no && kill -HUP $KILLPIDS
213         exit $RC
214 fi
215
216 CNT=`expr $CNT + 1`
217 FILTER="(mail=*@mail.alumni.example.com)"
218 ATTRS="cn sn title uid"
219 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
220 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
221 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
222         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
223 RC=$?
224 if test $RC != 0 ; then
225         echo "ldapsearch failed ($RC)!"
226         test $KILLSERVERS != no && kill -HUP $KILLPIDS
227         exit $RC
228 fi
229
230 CNT=`expr $CNT + 1`
231 FILTER="(mail=*)"
232 ATTRS="cn sn title uid"
233 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
234 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
235 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
236         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
237 RC=$?
238 if test $RC != 0 ; then
239         echo "ldapsearch failed ($RC)!"
240         test $KILLSERVERS != no && kill -HUP $KILLPIDS
241         exit $RC
242 fi
243
244 CNT=`expr $CNT + 1`
245 FILTER="(mail=*example.com)"
246 ATTRS="cn sn title uid"
247 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
248 UPASSWD="bjorn"
249 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
250 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
251 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
252         -D "$USERDN" -w "$UPASSWD" \
253         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
254 RC=$?
255 case $RC in
256 0)
257         echo "ldapsearch should have failed!"
258         test $KILLSERVERS != no && kill -HUP $KILLPIDS
259         exit $RC
260         ;;
261 4)
262         echo "ldapsearch failed ($RC)"
263         ;;
264 *)
265         echo "ldapsearch failed ($RC)!"
266         test $KILLSERVERS != no && kill -HUP $KILLPIDS
267         exit $RC
268         ;;
269 esac
270
271 CNT=`expr $CNT + 1`
272 FILTER="(uid=b*)"
273 ATTRS="mail"
274 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
275 UPASSWD="bjorn"
276 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
277 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
278 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
279         -D "$USERDN" -w "$UPASSWD" \
280         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
281 RC=$?
282 case $RC in
283 0)
284         echo "ldapsearch should have failed!"
285         test $KILLSERVERS != no && kill -HUP $KILLPIDS
286         exit $RC
287         ;;
288 4)
289         echo "ldapsearch failed ($RC)"
290         ;;
291 *)
292         echo "ldapsearch failed ($RC)!"
293         test $KILLSERVERS != no && kill -HUP $KILLPIDS
294         exit $RC
295         ;;
296 esac
297
298 FIRST=$CNT
299
300 # queries 2-6,8-9 are cacheable
301 CACHEABILITY=011111011
302 grep CACHEABLE $LOG2 | awk '{ 
303                 if ($2 == "NOT") 
304                         printf "Query %d not cacheable\n",NR
305                 else 
306                         printf "Query %d cacheable\n",NR
307         }' 
308 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
309                 if ($2 == "NOT") 
310                         printf "0" 
311                 else 
312                         printf "1" 
313         }'`
314
315 if test "$CACHEABILITY" = "$CACHED" ; then
316         echo "Successfully verified cacheability"
317 else 
318         echo "Error in verifying cacheability"
319         test $KILLSERVERS != no && kill -HUP $KILLPIDS
320         exit 1
321 fi
322
323 CNT=`expr $CNT + 1`
324 FILTER="(|(cn=*Jones)(sn=Jones))"
325 ATTRS="cn sn title uid"
326 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
327 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
328 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
329         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
330 RC=$?
331 if test $RC != 0 ; then
332         echo "ldapsearch failed ($RC)!"
333         test $KILLSERVERS != no && kill -HUP $KILLPIDS
334         exit $RC
335 fi
336
337 CNT=`expr $CNT + 1`
338 FILTER="(sn=Smith)"
339 ATTRS="cn sn title uid"
340 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
341 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
342 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
343         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
344 RC=$?
345 if test $RC != 0 ; then
346         echo "ldapsearch failed ($RC)!"
347         test $KILLSERVERS != no && kill -HUP $KILLPIDS
348         exit $RC
349 fi
350
351 CNT=`expr $CNT + 1`
352 FILTER="(uid=bjorn)"
353 ATTRS="mail postaladdress telephonenumber cn uid"
354 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
355 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
356 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
357         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
358 RC=$?
359 if test $RC != 0 ; then
360         echo "ldapsearch failed ($RC)!"
361         test $KILLSERVERS != no && kill -HUP $KILLPIDS
362         exit $RC
363 fi
364
365 CNT=`expr $CNT + 1`
366 FILTER="(mail=jaj@mail.alumni.example.com)"
367 ATTRS="cn sn title uid"
368 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
369 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
370 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
371         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
372 RC=$?
373
374 if test $RC != 0 ; then
375         echo "ldapsearch failed ($RC)!"
376         test $KILLSERVERS != no && kill -HUP $KILLPIDS
377         exit $RC
378 fi
379
380 CNT=`expr $CNT + 1`
381 FILTER="(mail=*example.com)"
382 ATTRS="cn sn title uid"
383 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
384 UPASSWD="bjorn"
385 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
386 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
387 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
388         -D "$USERDN" -w "$UPASSWD" \
389         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
390 RC=$?
391 case $RC in
392 0)
393         echo "ldapsearch should have failed!"
394         test $KILLSERVERS != no && kill -HUP $KILLPIDS
395         exit $RC
396         ;;
397 4)
398         echo "ldapsearch failed ($RC)"
399         ;;
400 *)
401         echo "ldapsearch failed ($RC)!"
402         test $KILLSERVERS != no && kill -HUP $KILLPIDS
403         exit $RC
404         ;;
405 esac
406
407 CNT=`expr $CNT + 1`
408 FILTER="(uid=b*)"
409 ATTRS="mail"
410 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
411 UPASSWD="bjorn"
412 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
413 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
414 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
415         -D "$USERDN" -w "$UPASSWD" \
416         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
417 RC=$?
418 case $RC in
419 0)
420         echo "ldapsearch should have failed!"
421         test $KILLSERVERS != no && kill -HUP $KILLPIDS
422         exit $RC
423         ;;
424 4)
425         echo "ldapsearch failed ($RC)"
426         ;;
427 *)
428         echo "ldapsearch failed ($RC)!"
429         test $KILLSERVERS != no && kill -HUP $KILLPIDS
430         exit $RC
431         ;;
432 esac
433
434 #queries 10-12,15 are answerable, 13-14 are not
435 #actually, 12 would be answerable, but since 8 made mail=*example.com
436 #not answerable because of sizelimit, queries contained in it are no longer
437 #answerable as well
438 ANSWERABILITY=111001
439 grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{ 
440                 if (NR > FIRST) { 
441                         if ($2 == "NOT") 
442                                 printf "Query %d not answerable\n",NR
443                         else 
444                                 printf "Query %d answerable\n",NR 
445                 }
446         }' 
447 ANSWERED=`grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{ 
448                 if (NR > FIRST) { 
449                         if ($2 == "NOT") 
450                                 printf "0" 
451                         else 
452                                 printf "1"
453                 } 
454         }'`
455
456 if test "$ANSWERABILITY" = "$ANSWERED" ; then
457         echo "Successfully verified answerability"
458 else 
459         echo "Error in verifying answerability"
460         test $KILLSERVERS != no && kill -HUP $KILLPIDS
461         exit 1
462 fi
463
464 echo "Filtering ldapsearch results..."
465 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
466 echo "Filtering original ldif..."
467 $LDIFFILTER < $PROXYCACHEOUT > $LDIFFLT
468 echo "Comparing filter output..."
469 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
470
471 if test $? != 0 ; then
472         echo "Comparison failed"
473         test $KILLSERVERS != no && kill -HUP $KILLPIDS
474         exit 1
475 fi
476
477 echo ""
478 echo "Testing cache refresh"
479
480 CNT=`expr $CNT + 1`
481 FILTER="(&(objectclass=person)(uid=dots))"
482 ATTRS="cn mail telephonenumber"
483 echo "Query $CNT: filter:$FILTER attrs:$ATTRS" 
484 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
485 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
486         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
487 RC=$?
488 if test $RC != 0 ; then
489         echo "ldapsearch failed ($RC)!"
490         test $KILLSERVERS != no && kill -HUP $KILLPIDS
491         exit $RC
492 fi
493
494 $LDAPMODIFY -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD <<EOF \
495         > /dev/null 2>&1
496 dn: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com
497 changetype: modify
498 replace: mail
499 mail: dots@admin.example2.com
500 -
501
502 EOF
503 RC=$?
504 if test $RC != 0 ; then
505         echo "ldapmodify failed ($RC)!"
506         test $KILLSERVERS != no && kill -HUP $KILLPIDS
507         exit $RC
508 fi
509
510 SLEEP=`expr $PCACHETTR + $PCACHE_CCPERIOD`
511 echo "Waiting $SLEEP seconds for cache to refresh"
512
513 sleep $SLEEP
514
515 echo "Checking entry again"
516 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
517         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
518 RC=$?
519 if test $RC != 0 ; then
520         echo "ldapsearch failed ($RC)!"
521         test $KILLSERVERS != no && kill -HUP $KILLPIDS
522         exit $RC
523 fi
524
525 grep "^mail: dots@admin" $SEARCHOUT > /dev/null
526 RC=$?
527 if test $RC != 0 ; then
528         echo "Refresh failed"
529         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
530         exit 0
531 fi
532
533 echo ""
534 echo "Testing Bind caching"
535
536 CNT=`expr $CNT + 1`
537 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
538 UPASSWD="jaj"
539 echo "Query $CNT: $USERDN"
540 echo "# Query $CNT: $USERDN" >> $SEARCHOUT
541 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
542         -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
543 RC=$?
544 if test $RC != 0 ; then
545         echo "ldapsearch failed ($RC)!"
546         test $KILLSERVERS != no && kill -HUP $KILLPIDS
547         exit $RC
548 fi
549
550 grep "CACHING BIND" $LOG2 > /dev/null
551 RC=$?
552 if test $RC != 0 ; then
553         echo "Refresh failed"
554         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
555         exit 0
556 fi
557
558 CNT=`expr $CNT + 1`
559 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
560 UPASSWD="jaj"
561 echo "Query $CNT: (Bind should be cached)"
562 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
563 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
564         -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
565 RC=$?
566 if test $RC != 0 ; then
567         echo "ldapsearch failed ($RC)!"
568         test $KILLSERVERS != no && kill -HUP $KILLPIDS
569         exit $RC
570 fi
571
572 grep "CACHED BIND" $LOG2 > /dev/null
573 RC=$?
574 if test $RC != 0 ; then
575         echo "Refresh failed"
576         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
577         exit 0
578 fi
579
580 echo ""
581 echo "Testing pwdModify"
582 $LDAPPASSWD -h $LOCALHOST -p $PORT2 \
583         -D "$MANAGERDN" -w "$PASSWD" -s newpw "$USERDN" >> $TESTOUT 2>&1
584 RC=$?
585 if test $RC != 0 ; then
586         echo "ldappasswd failed ($RC)!"
587         test $KILLSERVERS != no && kill -HUP $KILLPIDS
588         exit $RC
589 fi
590
591 RC=`grep "CACH.* BIND" $LOG2 | wc -l`
592 if test $RC != 3 ; then
593         echo "ldappasswd didn't update the cache"
594         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
595         exit 0
596 fi
597
598 CNT=`expr $CNT + 1`
599 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
600 UPASSWD=newpw
601 echo "Query $CNT: (Bind should be cached)"
602 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
603 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
604         -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
605 RC=$?
606 if test $RC != 0 ; then
607         echo "ldapsearch failed ($RC)!"
608         test $KILLSERVERS != no && kill -HUP $KILLPIDS
609         exit $RC
610 fi
611
612 RC=`grep "CACH.* BIND" $LOG2 | wc -l`
613 if test $RC != 4 ; then
614         echo "Bind wasn't answered from cache"
615         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
616         exit 0
617 fi
618 test $KILLSERVERS != no && kill -HUP $KILLPIDS
619
620 echo ">>>>> Test succeeded"
621
622 test $KILLSERVERS != no && wait
623
624 exit 0