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