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