]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
763057975b785c0d80899cc9a08e19a06f2eaf74
[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-2011 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, remaining test skipped..."
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 1
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 1
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 CNT=`expr $CNT + 1`
299 FILTER="(|(cn=All Staff)(sn=All Staff))"
300 ATTRS="sn cn title uid undefinedAttr"
301 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
302 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
303 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
304         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
305 RC=$?
306 if test $RC != 0 ; then
307         echo "ldapsearch failed ($RC)!"
308         test $KILLSERVERS != no && kill -HUP $KILLPIDS
309         exit $RC
310 fi
311
312 FIRST=$CNT
313
314 # queries 2-6,8-10 are cacheable
315 CACHEABILITY=0111110111
316 grep CACHEABLE $LOG2 | awk '{ 
317                 if ($2 == "NOT") 
318                         printf "Query %d not cacheable\n",NR
319                 else 
320                         printf "Query %d cacheable\n",NR
321         }' 
322 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
323                 if ($2 == "NOT") 
324                         printf "0" 
325                 else 
326                         printf "1" 
327         }'`
328
329 if test "$CACHEABILITY" = "$CACHED" ; then
330         echo "Successfully verified cacheability"
331 else 
332         echo "Error in verifying cacheability"
333         test $KILLSERVERS != no && kill -HUP $KILLPIDS
334         exit 1
335 fi
336
337 CNT=`expr $CNT + 1`
338 FILTER="(|(cn=*Jones)(sn=Jones))"
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 -x -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="(sn=Smith)"
353 ATTRS="cn sn title 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="(uid=bjorn)"
367 ATTRS="mail postaladdress telephonenumber cn 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 if test $RC != 0 ; then
374         echo "ldapsearch failed ($RC)!"
375         test $KILLSERVERS != no && kill -HUP $KILLPIDS
376         exit $RC
377 fi
378
379 CNT=`expr $CNT + 1`
380 FILTER="(mail=jaj@mail.alumni.example.com)"
381 ATTRS="cn sn title uid"
382 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
383 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
384 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
385         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
386 RC=$?
387
388 if test $RC != 0 ; then
389         echo "ldapsearch failed ($RC)!"
390         test $KILLSERVERS != no && kill -HUP $KILLPIDS
391         exit $RC
392 fi
393
394 CNT=`expr $CNT + 1`
395 FILTER="(mail=*example.com)"
396 ATTRS="cn sn title uid"
397 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
398 UPASSWD="bjorn"
399 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
400 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
401 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
402         -D "$USERDN" -w "$UPASSWD" \
403         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
404 RC=$?
405 case $RC in
406 0)
407         echo "ldapsearch should have failed!"
408         test $KILLSERVERS != no && kill -HUP $KILLPIDS
409         exit 1
410         ;;
411 4)
412         echo "ldapsearch failed ($RC)"
413         ;;
414 *)
415         echo "ldapsearch failed ($RC)!"
416         test $KILLSERVERS != no && kill -HUP $KILLPIDS
417         exit $RC
418         ;;
419 esac
420
421 CNT=`expr $CNT + 1`
422 FILTER="(uid=b*)"
423 ATTRS="mail"
424 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
425 UPASSWD="bjorn"
426 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
427 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
428 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
429         -D "$USERDN" -w "$UPASSWD" \
430         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
431 RC=$?
432 case $RC in
433 0)
434         echo "ldapsearch should have failed!"
435         test $KILLSERVERS != no && kill -HUP $KILLPIDS
436         exit 1
437         ;;
438 4)
439         echo "ldapsearch failed ($RC)"
440         ;;
441 *)
442         echo "ldapsearch failed ($RC)!"
443         test $KILLSERVERS != no && kill -HUP $KILLPIDS
444         exit $RC
445         ;;
446 esac
447
448 CNT=`expr $CNT + 1`
449 FILTER="(|(cn=All Staff)(sn=All Staff))"
450 ATTRS="sn cn title uid undefinedAttr"
451 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"  
452 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
453 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
454         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
455 RC=$?
456 if test $RC != 0 ; then
457         echo "ldapsearch failed ($RC)!"
458         test $KILLSERVERS != no && kill -HUP $KILLPIDS
459         exit $RC
460 fi
461
462 #queries 11-13,16-17 are answerable, 14-15 are not
463 #actually, 14 would be answerable, but since 8 made mail=*example.com
464 #not answerable because of sizelimit, queries contained in it are no longer
465 #answerable as well
466 ANSWERABILITY=1110011
467 grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{ 
468                 if (NR > FIRST) { 
469                         if ($2 == "NOT") 
470                                 printf "Query %d not answerable\n",NR
471                         else 
472                                 printf "Query %d answerable\n",NR 
473                 }
474         }' 
475 ANSWERED=`grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{ 
476                 if (NR > FIRST) { 
477                         if ($2 == "NOT") 
478                                 printf "0" 
479                         else 
480                                 printf "1"
481                 } 
482         }'`
483
484 if test "$ANSWERABILITY" = "$ANSWERED" ; then
485         echo "Successfully verified answerability"
486 else 
487         echo "Error in verifying answerability"
488         test $KILLSERVERS != no && kill -HUP $KILLPIDS
489         exit 1
490 fi
491
492 echo "Filtering ldapsearch results..."
493 $LDIFFILTER -s ldif=a < $SEARCHOUT > $SEARCHFLT
494 echo "Filtering original ldif..."
495 $LDIFFILTER -s ldif=a < $PROXYCACHEOUT > $LDIFFLT
496 echo "Comparing filter output..."
497 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
498
499 if test $? != 0 ; then
500         echo "Comparison failed"
501         test $KILLSERVERS != no && kill -HUP $KILLPIDS
502         exit 1
503 fi
504
505 echo ""
506 echo "Testing cache refresh"
507
508 CNT=`expr $CNT + 1`
509 FILTER="(&(objectclass=person)(uid=dots))"
510 ATTRS="cn mail telephonenumber"
511 echo "Query $CNT: filter:$FILTER attrs:$ATTRS" 
512 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
513 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
514         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
515 RC=$?
516 if test $RC != 0 ; then
517         echo "ldapsearch failed ($RC)!"
518         test $KILLSERVERS != no && kill -HUP $KILLPIDS
519         exit $RC
520 fi
521
522 $LDAPMODIFY -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD <<EOF \
523         > /dev/null 2>&1
524 dn: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com
525 changetype: modify
526 replace: mail
527 mail: dots@admin.example2.com
528 -
529
530 EOF
531 RC=$?
532 if test $RC != 0 ; then
533         echo "ldapmodify failed ($RC)!"
534         test $KILLSERVERS != no && kill -HUP $KILLPIDS
535         exit $RC
536 fi
537
538 SLEEP=`expr $PCACHETTR + $PCACHE_CCPERIOD`
539 echo "Waiting $SLEEP seconds for cache to refresh"
540
541 sleep $SLEEP
542
543 echo "Checking entry again"
544 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
545         "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
546 RC=$?
547 if test $RC != 0 ; then
548         echo "ldapsearch failed ($RC)!"
549         test $KILLSERVERS != no && kill -HUP $KILLPIDS
550         exit $RC
551 fi
552
553 grep "^mail: dots@admin" $SEARCHOUT > /dev/null
554 RC=$?
555 if test $RC != 0 ; then
556         echo "Refresh failed"
557         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
558         exit 1
559 fi
560
561 echo ""
562 echo "Testing Bind caching"
563
564 CNT=`expr $CNT + 1`
565 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
566 UPASSWD="jaj"
567 echo "Query $CNT: $USERDN"
568 echo "# Query $CNT: $USERDN" >> $SEARCHOUT
569 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
570         -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
571 RC=$?
572 if test $RC != 0 ; then
573         echo "ldapsearch failed ($RC)!"
574         test $KILLSERVERS != no && kill -HUP $KILLPIDS
575         exit $RC
576 fi
577
578 grep "CACHING BIND" $LOG2 > /dev/null
579 RC=$?
580 if test $RC != 0 ; then
581         echo "Refresh failed"
582         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
583         exit 1
584 fi
585
586 CNT=`expr $CNT + 1`
587 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
588 UPASSWD="jaj"
589 echo "Query $CNT: (Bind should be cached)"
590 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
591 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
592         -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
593 RC=$?
594 if test $RC != 0 ; then
595         echo "ldapsearch failed ($RC)!"
596         test $KILLSERVERS != no && kill -HUP $KILLPIDS
597         exit $RC
598 fi
599
600 grep "CACHED BIND" $LOG2 > /dev/null
601 RC=$?
602 if test $RC != 0 ; then
603         echo "Refresh failed"
604         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
605         exit 1
606 fi
607
608 echo ""
609 echo "Testing pwdModify"
610 $LDAPPASSWD -h $LOCALHOST -p $PORT2 \
611         -D "$MANAGERDN" -w "$PASSWD" -s newpw "$USERDN" >> $TESTOUT 2>&1
612 RC=$?
613 if test $RC != 0 ; then
614         echo "ldappasswd failed ($RC)!"
615         test $KILLSERVERS != no && kill -HUP $KILLPIDS
616         exit $RC
617 fi
618
619 RC=`grep "CACH.* BIND" $LOG2 | wc -l`
620 if test $RC != 3 ; then
621         echo "ldappasswd didn't update the cache"
622         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
623         exit 1
624 fi
625
626 CNT=`expr $CNT + 1`
627 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
628 UPASSWD=newpw
629 echo "Query $CNT: (Bind should be cached)"
630 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
631 $LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \
632         -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT
633 RC=$?
634 if test $RC != 0 ; then
635         echo "ldapsearch failed ($RC)!"
636         test $KILLSERVERS != no && kill -HUP $KILLPIDS
637         exit $RC
638 fi
639
640 RC=`grep "CACH.* BIND" $LOG2 | wc -l`
641 if test $RC != 4 ; then
642         echo "Bind wasn't answered from cache"
643         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
644         exit 1
645 fi
646 test $KILLSERVERS != no && kill -HUP $KILLPIDS
647
648 echo ">>>>> Test succeeded"
649
650 test $KILLSERVERS != no && wait
651
652 exit 0