3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2005 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>.
19 . $SRCDIR/scripts/defines.sh
21 if test $PROXYCACHE = pcacheno; then
22 echo "Proxy cache overlay not available, test skipped"
26 if test $BACKLDAP = "ldapno" ; then
27 echo "LDAP backend not available, test skipped"
31 if test "x$LVL" = "x0" ; then
32 echo "test020 needs a minimal log level; setting to LDAP_DEBUG_NONE..."
36 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
42 # - perform first set of searches at the proxy
43 # - verify cacheability
44 # - perform second set of searches at the proxy
45 # - verify answerability
47 echo "Starting master slapd on TCP/IP port $PORT1..."
48 . $CONFFILTER < $CACHEMASTERCONF > $CONF1
49 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
51 if test $WAIT != 0 ; then
59 echo "Using ldapsearch to check that master slapd is running..."
60 for i in 0 1 2 3 4 5; do
61 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
62 'objectclass=*' > /dev/null 2>&1
64 if test $RC = 0 ; then
67 echo "Waiting 5 seconds for slapd to start..."
71 if test $RC != 0 ; then
72 echo "ldapsearch failed ($RC)!"
73 test $KILLSERVERS != no && kill -HUP $KILLPIDS
77 echo "Using ldapadd to populate the master directory..."
78 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
79 $LDIFORDERED > /dev/null 2>&1
81 if test $RC != 0 ; then
82 echo "ldapadd failed ($RC)!"
83 test $KILLSERVERS != no && kill -HUP $KILLPIDS
87 echo "Starting proxy cache on TCP/IP port $PORT2..."
88 . $CONFFILTER < $PROXYCACHECONF > $CONF2
89 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
91 if test $WAIT != 0 ; then
92 echo CACHEPID $CACHEPID
95 KILLPIDS="$KILLPIDS $CACHEPID"
99 echo "Using ldapsearch to check that proxy slapd is running..."
100 for i in 0 1 2 3 4 5; do
101 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
102 'objectclass=*' > /dev/null 2>&1
104 if test $RC = 0 ; then
107 echo "Waiting 5 seconds for slapd to start..."
111 if test $RC != 0 ; then
112 echo "ldapsearch failed ($RC)!"
113 test $KILLSERVERS != no && kill -HUP $KILLPIDS
117 echo "Making queries on the proxy cache..."
118 echo "Query 1: filter:(sn=Jon) attrs: all"
119 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
120 'sn=Jon' > $SLAVEOUT 2>&1
122 if test $RC != 0 ; then
123 echo "ldapsearch failed ($RC)!"
124 test $KILLSERVERS != no && kill -HUP $KILLPIDS
128 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"
129 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
130 '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
132 if test $RC != 0 ; then
133 echo "ldapsearch failed ($RC)!"
134 test $KILLSERVERS != no && kill -HUP $KILLPIDS
138 echo "Query 3: filter:(sn=Smith*) attrs:cn sn title uid"
139 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
140 'sn=Smith*' cn sn title uid >> $SLAVEOUT 2>&1
142 if test $RC != 0 ; then
143 echo "ldapsearch failed ($RC)!"
144 test $KILLSERVERS != no && kill -HUP $KILLPIDS
148 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"
149 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
150 'sn=Doe' cn sn title uid >> $SLAVEOUT 2>&1
152 if test $RC != 0 ; then
153 echo "ldapsearch failed ($RC)!"
154 test $KILLSERVERS != no && kill -HUP $KILLPIDS
158 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"
159 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
160 'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
162 if test $RC != 0 ; then
163 echo "ldapsearch failed ($RC)!"
164 test $KILLSERVERS != no && kill -HUP $KILLPIDS
168 echo "Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid"
169 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
170 'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
172 if test $RC != 0 ; then
173 echo "ldapsearch failed ($RC)!"
174 test $KILLSERVERS != no && kill -HUP $KILLPIDS
178 echo "Query 7: filter:(mail=*) cn sn title uid"
179 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
180 'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
182 if test $RC != 0 ; then
183 echo "ldapsearch failed ($RC)!"
184 test $KILLSERVERS != no && kill -HUP $KILLPIDS
188 # queries 2-6 are cacheable
190 grep CACHEABLE $LOG2 | awk '{
192 printf "Query %d not cacheable\n",NR
194 printf "Query %d cacheable\n",NR
196 CACHED=`grep CACHEABLE $LOG2 | awk '{
203 if test "$CACHEABILITY" = "$CACHED" ; then
204 echo "Successfully verified cacheability"
206 echo "Error in verifying cacheability"
207 test $KILLSERVERS != no && kill -HUP $KILLPIDS
211 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"
212 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
213 '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
215 if test $RC != 0 ; then
216 echo "ldapsearch failed ($RC)!"
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
221 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"
222 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
223 'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
225 if test $RC != 0 ; then
226 echo "ldapsearch failed ($RC)!"
227 test $KILLSERVERS != no && kill -HUP $KILLPIDS
231 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"
232 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
233 'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
235 if test $RC != 0 ; then
236 echo "ldapsearch failed ($RC)!"
237 test $KILLSERVERS != no && kill -HUP $KILLPIDS
241 echo "Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"
242 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
243 'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
246 if test $RC != 0 ; then
247 echo "ldapsearch failed ($RC)!"
248 test $KILLSERVERS != no && kill -HUP $KILLPIDS
252 #queries 8-11 are answerable
254 grep ANSWERABLE $LOG2 | awk '{
257 printf "Query %d not answerable\n",NR
259 printf "Query %d answerable\n",NR
262 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{
271 test $KILLSERVERS != no && kill -HUP $KILLPIDS
273 if test "$ANSWERABILITY" = "$ANSWERED" ; then
274 echo "Successfully verified answerability"
276 echo "Error in verifying answerability"
280 echo "Filtering ldapsearch results..."
281 . $LDIFFILTER < $SLAVEOUT > $SEARCHFLT
282 echo "Comparing filter output..."
283 $CMP $SEARCHFLT $PROXYCACHEOUT > $CMPOUT
285 if test $? != 0 ; then
286 echo "Comparison failed"
290 echo ">>>>> Test succeeded"