3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2007 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 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
37 # - perform first set of searches at the proxy
38 # - verify cacheability
39 # - perform second set of searches at the proxy
40 # - verify answerability
42 echo "Starting master slapd on TCP/IP port $PORT1..."
43 . $CONFFILTER < $CACHEMASTERCONF > $CONF1
44 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
46 if test $WAIT != 0 ; then
54 echo "Using ldapsearch to check that master slapd is running..."
55 for i in 0 1 2 3 4 5; do
56 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
57 'objectclass=*' > /dev/null 2>&1
59 if test $RC = 0 ; then
62 echo "Waiting 5 seconds for slapd to start..."
66 if test $RC != 0 ; then
67 echo "ldapsearch failed ($RC)!"
68 test $KILLSERVERS != no && kill -HUP $KILLPIDS
72 echo "Using ldapadd to populate the master directory..."
73 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
74 $LDIFORDERED > /dev/null 2>&1
76 if test $RC != 0 ; then
77 echo "ldapadd failed ($RC)!"
78 test $KILLSERVERS != no && kill -HUP $KILLPIDS
82 echo "Starting proxy cache on TCP/IP port $PORT2..."
83 . $CONFFILTER < $PROXYCACHECONF > $CONF2
84 $SLAPD -f $CONF2 -h $URI2 -d $LVL -d pcache > $LOG2 2>&1 &
86 if test $WAIT != 0 ; then
87 echo CACHEPID $CACHEPID
90 KILLPIDS="$KILLPIDS $CACHEPID"
94 echo "Using ldapsearch to check that proxy slapd is running..."
95 for i in 0 1 2 3 4 5; do
96 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
97 'objectclass=*' > /dev/null 2>&1
99 if test $RC = 0 ; then
102 echo "Waiting 5 seconds for slapd to start..."
106 if test $RC != 0 ; then
107 echo "ldapsearch failed ($RC)!"
108 test $KILLSERVERS != no && kill -HUP $KILLPIDS
112 cat /dev/null > $SLAVEOUT
114 echo "Making queries on the proxy cache..."
115 echo "Query 1: filter:(sn=Jon) attrs: all"
116 echo "# Query 1: filter:(sn=Jon) attrs: all" >> $SLAVEOUT
117 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
118 'sn=Jon' >> $SLAVEOUT 2>&1
120 if test $RC != 0 ; then
121 echo "ldapsearch failed ($RC)!"
122 test $KILLSERVERS != no && kill -HUP $KILLPIDS
126 # ITS#4491, if debug messages are unavailable, we can't verify the tests.
127 grep "query template" $LOG2 > /dev/null
129 if test $RC != 0 ; then
130 echo "Debug messages unavailable, test aborted..."
131 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
135 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"
136 echo "# Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid" >> $SLAVEOUT
137 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
138 '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
140 if test $RC != 0 ; then
141 echo "ldapsearch failed ($RC)!"
142 test $KILLSERVERS != no && kill -HUP $KILLPIDS
146 echo "Query 3: filter:(sn=Smith*) attrs:cn sn uid"
147 echo "# Query 3: filter:(sn=Smith*) attrs:cn sn uid" >> $SLAVEOUT
148 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
149 'sn=Smith*' cn sn uid >> $SLAVEOUT 2>&1
151 if test $RC != 0 ; then
152 echo "ldapsearch failed ($RC)!"
153 test $KILLSERVERS != no && kill -HUP $KILLPIDS
157 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"
158 echo "# Query 4: filter:(sn=Doe*) attrs:cn sn title uid" >> $SLAVEOUT
159 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
160 'sn=Doe' cn sn title 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 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"
169 echo "# Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid" >> $SLAVEOUT
170 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
171 'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
173 if test $RC != 0 ; then
174 echo "ldapsearch failed ($RC)!"
175 test $KILLSERVERS != no && kill -HUP $KILLPIDS
179 echo "Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid"
180 echo "# Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid" >> $SLAVEOUT
181 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
182 'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
184 if test $RC != 0 ; then
185 echo "ldapsearch failed ($RC)!"
186 test $KILLSERVERS != no && kill -HUP $KILLPIDS
190 echo "Query 7: filter:(mail=*) cn sn title uid"
191 echo "# Query 7: filter:(mail=*) cn sn title uid" >> $SLAVEOUT
192 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
193 'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
195 if test $RC != 0 ; then
196 echo "ldapsearch failed ($RC)!"
197 test $KILLSERVERS != no && kill -HUP $KILLPIDS
201 # queries 2-6 are cacheable
203 grep CACHEABLE $LOG2 | awk '{
205 printf "Query %d not cacheable\n",NR
207 printf "Query %d cacheable\n",NR
209 CACHED=`grep CACHEABLE $LOG2 | awk '{
216 if test "$CACHEABILITY" = "$CACHED" ; then
217 echo "Successfully verified cacheability"
219 echo "Error in verifying cacheability"
220 test $KILLSERVERS != no && kill -HUP $KILLPIDS
224 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"
225 echo "# Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid" >> $SLAVEOUT
226 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
227 '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
229 if test $RC != 0 ; then
230 echo "ldapsearch failed ($RC)!"
231 test $KILLSERVERS != no && kill -HUP $KILLPIDS
235 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"
236 echo "# Query 9: filter:(sn=Smith) attrs:cn sn title uid" >> $SLAVEOUT
237 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
238 'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
240 if test $RC != 0 ; then
241 echo "ldapsearch failed ($RC)!"
242 test $KILLSERVERS != no && kill -HUP $KILLPIDS
246 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"
247 echo "# Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid" >> $SLAVEOUT
248 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
249 'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
251 if test $RC != 0 ; then
252 echo "ldapsearch failed ($RC)!"
253 test $KILLSERVERS != no && kill -HUP $KILLPIDS
257 echo "Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"
258 echo "# Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid" >> $SLAVEOUT
259 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
260 'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
263 if test $RC != 0 ; then
264 echo "ldapsearch failed ($RC)!"
265 test $KILLSERVERS != no && kill -HUP $KILLPIDS
269 #queries 8-11 are answerable
271 grep ANSWERABLE $LOG2 | awk '{
274 printf "Query %d not answerable\n",NR
276 printf "Query %d answerable\n",NR
279 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{
288 test $KILLSERVERS != no && kill -HUP $KILLPIDS
290 if test "$ANSWERABILITY" = "$ANSWERED" ; then
291 echo "Successfully verified answerability"
293 echo "Error in verifying answerability"
297 echo "Filtering ldapsearch results..."
298 . $LDIFFILTER < $SLAVEOUT > $SEARCHFLT
299 echo "Filtering original ldif..."
300 . $LDIFFILTER < $PROXYCACHEOUT > $LDIFFLT
301 echo "Comparing filter output..."
302 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
304 if test $? != 0 ; then
305 echo "Comparison failed"
309 echo ">>>>> Test succeeded"
311 test $KILLSERVERS != no && wait