Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test020-proxycache
blob7d413a67b9a1c2ca10461adac0eb283f20856ae1
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test020-proxycache,v 1.26.2.9 2008/02/11 23:26:51 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 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.
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 CACHETTL="1m"
17 NCACHETTL="1m"
18 SCACHETTL="1m"
19 CACHE_ENTRY_LIMIT=6
21 . $SRCDIR/scripts/defines.sh
23 if test $PROXYCACHE = pcacheno; then
24 echo "Proxy cache overlay not available, test skipped"
25 exit 0
26 fi
28 if test $BACKLDAP = "ldapno" ; then
29 echo "LDAP backend not available, test skipped"
30 exit 0
31 fi
33 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
35 # Test proxy caching:
36 # - start master
37 # - start proxy cache
38 # - populate master
39 # - perform first set of searches at the proxy
40 # - verify cacheability
41 # - perform second set of searches at the proxy
42 # - verify answerability
44 echo "Starting master slapd on TCP/IP port $PORT1..."
45 . $CONFFILTER < $CACHEMASTERCONF > $CONF1
46 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
47 PID=$!
48 if test $WAIT != 0 ; then
49 echo PID $PID
50 read foo
52 KILLPIDS="$PID"
54 sleep 1
56 echo "Using ldapsearch to check that master slapd is running..."
57 for i in 0 1 2 3 4 5; do
58 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
59 'objectclass=*' > /dev/null 2>&1
60 RC=$?
61 if test $RC = 0 ; then
62 break
64 echo "Waiting 5 seconds for slapd to start..."
65 sleep 5
66 done
68 if test $RC != 0 ; then
69 echo "ldapsearch failed ($RC)!"
70 test $KILLSERVERS != no && kill -HUP $KILLPIDS
71 exit $RC
74 echo "Using ldapadd to populate the master directory..."
75 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
76 $LDIFORDERED > /dev/null 2>&1
77 RC=$?
78 if test $RC != 0 ; then
79 echo "ldapadd failed ($RC)!"
80 test $KILLSERVERS != no && kill -HUP $KILLPIDS
81 exit $RC
84 echo "Starting proxy cache on TCP/IP port $PORT2..."
85 . $CONFFILTER < $PROXYCACHECONF > $CONF2
86 $SLAPD -f $CONF2 -h $URI2 -d $LVL -d pcache > $LOG2 2>&1 &
87 CACHEPID=$!
88 if test $WAIT != 0 ; then
89 echo CACHEPID $CACHEPID
90 read foo
92 KILLPIDS="$KILLPIDS $CACHEPID"
94 sleep 1
96 echo "Using ldapsearch to check that proxy slapd is running..."
97 for i in 0 1 2 3 4 5; do
98 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
99 'objectclass=*' > /dev/null 2>&1
100 RC=$?
101 if test $RC = 0 ; then
102 break
104 echo "Waiting 5 seconds for slapd to start..."
105 sleep 5
106 done
108 if test $RC != 0 ; then
109 echo "ldapsearch failed ($RC)!"
110 test $KILLSERVERS != no && kill -HUP $KILLPIDS
111 exit $RC
114 cat /dev/null > $SEARCHOUT
116 echo "Making queries on the proxy cache..."
117 CNT=0
119 CNT=`expr $CNT + 1`
120 FILTER="(sn=Jon)"
121 echo "Query $CNT: filter:$FILTER attrs:all (expect nothing)"
122 echo "# Query $CNT: filter:$FILTER attrs:all (expect nothing)" >> $SEARCHOUT
123 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
124 "$FILTER" >> $SEARCHOUT 2>> $TESTOUT
125 RC=$?
126 if test $RC != 0 ; then
127 echo "ldapsearch failed ($RC)!"
128 test $KILLSERVERS != no && kill -HUP $KILLPIDS
129 exit $RC
132 # ITS#4491, if debug messages are unavailable, we can't verify the tests.
133 grep "query template" $LOG2 > /dev/null
134 RC=$?
135 if test $RC != 0 ; then
136 echo "Debug messages unavailable, test aborted..."
137 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
138 exit 0
141 CNT=`expr $CNT + 1`
142 FILTER="(|(cn=*Jon*)(sn=Jon*))"
143 ATTRS="cn sn title uid"
144 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
145 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
146 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
147 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
148 RC=$?
149 if test $RC != 0 ; then
150 echo "ldapsearch failed ($RC)!"
151 test $KILLSERVERS != no && kill -HUP $KILLPIDS
152 exit $RC
155 CNT=`expr $CNT + 1`
156 FILTER="(sn=Smith*)"
157 ATTRS="cn sn uid"
158 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
159 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
160 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
161 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
162 RC=$?
163 if test $RC != 0 ; then
164 echo "ldapsearch failed ($RC)!"
165 test $KILLSERVERS != no && kill -HUP $KILLPIDS
166 exit $RC
169 CNT=`expr $CNT + 1`
170 FILTER="(sn=Doe*)"
171 ATTRS="cn sn title uid"
172 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
173 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
174 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
175 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
176 RC=$?
177 if test $RC != 0 ; then
178 echo "ldapsearch failed ($RC)!"
179 test $KILLSERVERS != no && kill -HUP $KILLPIDS
180 exit $RC
183 CNT=`expr $CNT + 1`
184 FILTER="(uid=johnd)"
185 ATTRS="mail postaladdress telephonenumber cn uid"
186 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
187 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
188 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
189 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
190 RC=$?
191 if test $RC != 0 ; then
192 echo "ldapsearch failed ($RC)!"
193 test $KILLSERVERS != no && kill -HUP $KILLPIDS
194 exit $RC
197 CNT=`expr $CNT + 1`
198 FILTER="(mail=*@mail.alumni.example.com)"
199 ATTRS="cn sn title uid"
200 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
201 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
202 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
203 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
204 RC=$?
205 if test $RC != 0 ; then
206 echo "ldapsearch failed ($RC)!"
207 test $KILLSERVERS != no && kill -HUP $KILLPIDS
208 exit $RC
211 CNT=`expr $CNT + 1`
212 FILTER="(mail=*)"
213 ATTRS="cn sn title uid"
214 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
215 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
216 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
217 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
218 RC=$?
219 if test $RC != 0 ; then
220 echo "ldapsearch failed ($RC)!"
221 test $KILLSERVERS != no && kill -HUP $KILLPIDS
222 exit $RC
225 CNT=`expr $CNT + 1`
226 FILTER="(mail=*example.com)"
227 ATTRS="cn sn title uid"
228 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
229 PASSWD="bjorn"
230 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
231 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
232 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
233 -D "$USERDN" -w "$PASSWD" \
234 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
235 RC=$?
236 case $RC in
238 echo "ldapsearch should have failed!"
239 test $KILLSERVERS != no && kill -HUP $KILLPIDS
240 exit $RC
243 echo "ldapsearch failed ($RC)"
246 echo "ldapsearch failed ($RC)!"
247 test $KILLSERVERS != no && kill -HUP $KILLPIDS
248 exit $RC
250 esac
252 CNT=`expr $CNT + 1`
253 FILTER="(uid=b*)"
254 ATTRS="mail"
255 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
256 PASSWD="bjorn"
257 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
258 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
259 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
260 -D "$USERDN" -w "$PASSWD" \
261 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
262 RC=$?
263 case $RC in
265 echo "ldapsearch should have failed!"
266 test $KILLSERVERS != no && kill -HUP $KILLPIDS
267 exit $RC
270 echo "ldapsearch failed ($RC)"
273 echo "ldapsearch failed ($RC)!"
274 test $KILLSERVERS != no && kill -HUP $KILLPIDS
275 exit $RC
277 esac
279 FIRST=$CNT
281 # queries 2-6,8-9 are cacheable
282 CACHEABILITY=011111011
283 grep CACHEABLE $LOG2 | awk '{
284 if ($2 == "NOT")
285 printf "Query %d not cacheable\n",NR
286 else
287 printf "Query %d cacheable\n",NR
289 CACHED=`grep CACHEABLE $LOG2 | awk '{
290 if ($2 == "NOT")
291 printf "0"
292 else
293 printf "1"
296 if test "$CACHEABILITY" = "$CACHED" ; then
297 echo "Successfully verified cacheability"
298 else
299 echo "Error in verifying cacheability"
300 test $KILLSERVERS != no && kill -HUP $KILLPIDS
301 exit 1
304 CNT=`expr $CNT + 1`
305 FILTER="(|(cn=*Jones)(sn=Jones))"
306 ATTRS="cn sn title uid"
307 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
308 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
309 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
310 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
311 RC=$?
312 if test $RC != 0 ; then
313 echo "ldapsearch failed ($RC)!"
314 test $KILLSERVERS != no && kill -HUP $KILLPIDS
315 exit $RC
318 CNT=`expr $CNT + 1`
319 FILTER="(sn=Smith)"
320 ATTRS="cn sn title uid"
321 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
322 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
323 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
324 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
325 RC=$?
326 if test $RC != 0 ; then
327 echo "ldapsearch failed ($RC)!"
328 test $KILLSERVERS != no && kill -HUP $KILLPIDS
329 exit $RC
332 CNT=`expr $CNT + 1`
333 FILTER="(uid=bjorn)"
334 ATTRS="mail postaladdress telephonenumber cn uid"
335 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
336 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
337 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
338 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
339 RC=$?
340 if test $RC != 0 ; then
341 echo "ldapsearch failed ($RC)!"
342 test $KILLSERVERS != no && kill -HUP $KILLPIDS
343 exit $RC
346 CNT=`expr $CNT + 1`
347 FILTER="(mail=jaj@mail.alumni.example.com)"
348 ATTRS="cn sn title uid"
349 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
350 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
351 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
352 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
353 RC=$?
355 if test $RC != 0 ; then
356 echo "ldapsearch failed ($RC)!"
357 test $KILLSERVERS != no && kill -HUP $KILLPIDS
358 exit $RC
361 CNT=`expr $CNT + 1`
362 FILTER="(mail=*example.com)"
363 ATTRS="cn sn title uid"
364 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
365 PASSWD="bjorn"
366 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
367 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
368 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
369 -D "$USERDN" -w "$PASSWD" \
370 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
371 RC=$?
372 case $RC in
374 echo "ldapsearch should have failed!"
375 test $KILLSERVERS != no && kill -HUP $KILLPIDS
376 exit $RC
379 echo "ldapsearch failed ($RC)"
382 echo "ldapsearch failed ($RC)!"
383 test $KILLSERVERS != no && kill -HUP $KILLPIDS
384 exit $RC
386 esac
388 CNT=`expr $CNT + 1`
389 FILTER="(uid=b*)"
390 ATTRS="mail"
391 USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
392 PASSWD="bjorn"
393 echo "Query $CNT: filter:$FILTER attrs:$ATTRS"
394 echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT
395 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
396 -D "$USERDN" -w "$PASSWD" \
397 "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT
398 RC=$?
399 case $RC in
401 echo "ldapsearch should have failed!"
402 test $KILLSERVERS != no && kill -HUP $KILLPIDS
403 exit $RC
406 echo "ldapsearch failed ($RC)"
409 echo "ldapsearch failed ($RC)!"
410 test $KILLSERVERS != no && kill -HUP $KILLPIDS
411 exit $RC
413 esac
415 #queries 10-12,15 are answerable, 13-14 are not
416 #actually, 12 would be answerable, but since 8 made mail=*example.com
417 #not answerable because of sizelimit, queries contained in it are no longer
418 #answerable as well
419 ANSWERABILITY=111001
420 grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{
421 if (NR > FIRST) {
422 if ($2 == "NOT")
423 printf "Query %d not answerable\n",NR
424 else
425 printf "Query %d answerable\n",NR
428 ANSWERED=`grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{
429 if (NR > FIRST) {
430 if ($2 == "NOT")
431 printf "0"
432 else
433 printf "1"
437 test $KILLSERVERS != no && kill -HUP $KILLPIDS
439 if test "$ANSWERABILITY" = "$ANSWERED" ; then
440 echo "Successfully verified answerability"
441 else
442 echo "Error in verifying answerability"
443 exit 1
446 echo "Filtering ldapsearch results..."
447 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
448 echo "Filtering original ldif..."
449 . $LDIFFILTER < $PROXYCACHEOUT > $LDIFFLT
450 echo "Comparing filter output..."
451 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
453 if test $? != 0 ; then
454 echo "Comparison failed"
455 exit 1
458 echo ">>>>> Test succeeded"
460 test $KILLSERVERS != no && wait
462 exit 0