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/>.
5 ## Copyright 1998-2008 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
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>.
21 .
$SRCDIR/scripts
/defines.sh
23 if test $PROXYCACHE = pcacheno
; then
24 echo "Proxy cache overlay not available, test skipped"
28 if test $BACKLDAP = "ldapno" ; then
29 echo "LDAP backend not available, test skipped"
33 mkdir
-p $TESTDIR $DBDIR1 $DBDIR2
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 &
48 if test $WAIT != 0 ; then
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
61 if test $RC = 0 ; then
64 echo "Waiting 5 seconds for slapd to start..."
68 if test $RC != 0 ; then
69 echo "ldapsearch failed ($RC)!"
70 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
78 if test $RC != 0 ; then
79 echo "ldapadd failed ($RC)!"
80 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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 &
88 if test $WAIT != 0 ; then
89 echo CACHEPID
$CACHEPID
92 KILLPIDS
="$KILLPIDS $CACHEPID"
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
101 if test $RC = 0 ; then
104 echo "Waiting 5 seconds for slapd to start..."
108 if test $RC != 0 ; then
109 echo "ldapsearch failed ($RC)!"
110 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
114 cat /dev
/null
> $SEARCHOUT
116 echo "Making queries on the proxy cache..."
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
126 if test $RC != 0 ; then
127 echo "ldapsearch failed ($RC)!"
128 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
132 # ITS#4491, if debug messages are unavailable, we can't verify the tests.
133 grep "query template" $LOG2 > /dev
/null
135 if test $RC != 0 ; then
136 echo "Debug messages unavailable, test aborted..."
137 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS && wait
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
149 if test $RC != 0 ; then
150 echo "ldapsearch failed ($RC)!"
151 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
163 if test $RC != 0 ; then
164 echo "ldapsearch failed ($RC)!"
165 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
177 if test $RC != 0 ; then
178 echo "ldapsearch failed ($RC)!"
179 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
191 if test $RC != 0 ; then
192 echo "ldapsearch failed ($RC)!"
193 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
205 if test $RC != 0 ; then
206 echo "ldapsearch failed ($RC)!"
207 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
219 if test $RC != 0 ; then
220 echo "ldapsearch failed ($RC)!"
221 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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"
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
238 echo "ldapsearch should have failed!"
239 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
243 echo "ldapsearch failed ($RC)"
246 echo "ldapsearch failed ($RC)!"
247 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
255 USERDN
="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
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
265 echo "ldapsearch should have failed!"
266 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
270 echo "ldapsearch failed ($RC)"
273 echo "ldapsearch failed ($RC)!"
274 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
281 # queries 2-6,8-9 are cacheable
282 CACHEABILITY
=011111011
283 grep CACHEABLE
$LOG2 |
awk '{
285 printf "Query %d not cacheable\n",NR
287 printf "Query %d cacheable\n",NR
289 CACHED
=`grep CACHEABLE $LOG2 | awk '{
296 if test "$CACHEABILITY" = "$CACHED" ; then
297 echo "Successfully verified cacheability"
299 echo "Error in verifying cacheability"
300 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
312 if test $RC != 0 ; then
313 echo "ldapsearch failed ($RC)!"
314 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
326 if test $RC != 0 ; then
327 echo "ldapsearch failed ($RC)!"
328 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
340 if test $RC != 0 ; then
341 echo "ldapsearch failed ($RC)!"
342 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
355 if test $RC != 0 ; then
356 echo "ldapsearch failed ($RC)!"
357 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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"
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
374 echo "ldapsearch should have failed!"
375 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
379 echo "ldapsearch failed ($RC)"
382 echo "ldapsearch failed ($RC)!"
383 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
391 USERDN
="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
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
401 echo "ldapsearch should have failed!"
402 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
406 echo "ldapsearch failed ($RC)"
409 echo "ldapsearch failed ($RC)!"
410 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
420 grep ANSWERABLE
$LOG2 |
awk "BEGIN {FIRST=$FIRST}"'{
423 printf "Query %d not answerable\n",NR
425 printf "Query %d answerable\n",NR
428 ANSWERED
=`grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{
437 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
439 if test "$ANSWERABILITY" = "$ANSWERED" ; then
440 echo "Successfully verified answerability"
442 echo "Error in verifying answerability"
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"
458 echo ">>>>> Test succeeded"
460 test $KILLSERVERS != no
&& wait