]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
f53fcf5c83ae96e891e33e8958a523794bf6cb75
[openldap] / tests / scripts / test020-proxycache
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2007 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
16 CACHETTL="1m"
17 CACHE_ENTRY_LIMIT=10
18
19 . $SRCDIR/scripts/defines.sh
20
21 if test $PROXYCACHE = pcacheno; then 
22         echo "Proxy cache overlay not available, test skipped"
23         exit 0
24 fi 
25
26 if test $BACKLDAP = "ldapno" ; then 
27         echo "LDAP backend not available, test skipped"
28         exit 0
29 fi 
30
31 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
32
33 # Test proxy caching:
34 # - start master
35 # - start proxy cache
36 # - populate master 
37 # - perform first set of searches at the proxy
38 # - verify cacheability
39 # - perform second set of searches at the proxy 
40 # - verify answerability
41
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 &
45 PID=$!
46 if test $WAIT != 0 ; then
47         echo PID $PID
48         read foo
49 fi
50 KILLPIDS="$PID"
51
52 sleep 1
53
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
58         RC=$?
59         if test $RC = 0 ; then
60                 break
61         fi
62         echo "Waiting 5 seconds for slapd to start..."
63         sleep 5
64 done
65
66 if test $RC != 0 ; then
67         echo "ldapsearch failed ($RC)!"
68         test $KILLSERVERS != no && kill -HUP $KILLPIDS
69         exit $RC
70 fi
71
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
75 RC=$?
76 if test $RC != 0 ; then
77         echo "ldapadd failed ($RC)!"
78         test $KILLSERVERS != no && kill -HUP $KILLPIDS
79         exit $RC
80 fi
81
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 &
85 CACHEPID=$!
86 if test $WAIT != 0 ; then
87         echo CACHEPID $CACHEPID
88         read foo
89 fi
90 KILLPIDS="$KILLPIDS $CACHEPID"
91
92 sleep 1
93
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
98         RC=$?
99         if test $RC = 0 ; then
100                 break
101         fi
102         echo "Waiting 5 seconds for slapd to start..."
103         sleep 5
104 done
105
106 if test $RC != 0 ; then
107         echo "ldapsearch failed ($RC)!"
108         test $KILLSERVERS != no && kill -HUP $KILLPIDS
109         exit $RC
110 fi
111
112 cat /dev/null > $SLAVEOUT
113
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
119 RC=$?
120 if test $RC != 0 ; then
121         echo "ldapsearch failed ($RC)!"
122         test $KILLSERVERS != no && kill -HUP $KILLPIDS
123         exit $RC
124 fi
125
126 # ITS#4491, if debug messages are unavailable, we can't verify the tests.
127 grep "query template" $LOG2 > /dev/null
128 RC=$?
129 if test $RC != 0 ; then
130         echo "Debug messages unavailable, test aborted..."
131         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
132         exit 0
133 fi
134
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
139 RC=$?
140 if test $RC != 0 ; then
141         echo "ldapsearch failed ($RC)!"
142         test $KILLSERVERS != no && kill -HUP $KILLPIDS
143         exit $RC
144 fi
145
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
150 RC=$?
151 if test $RC != 0 ; then
152         echo "ldapsearch failed ($RC)!"
153         test $KILLSERVERS != no && kill -HUP $KILLPIDS
154         exit $RC
155 fi
156
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
161 RC=$?
162 if test $RC != 0 ; then
163         echo "ldapsearch failed ($RC)!"
164         test $KILLSERVERS != no && kill -HUP $KILLPIDS
165         exit $RC
166 fi
167  
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
172 RC=$?
173 if test $RC != 0 ; then
174         echo "ldapsearch failed ($RC)!"
175         test $KILLSERVERS != no && kill -HUP $KILLPIDS
176         exit $RC
177 fi
178
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
183 RC=$?
184 if test $RC != 0 ; then
185         echo "ldapsearch failed ($RC)!"
186         test $KILLSERVERS != no && kill -HUP $KILLPIDS
187         exit $RC
188 fi
189
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
194 RC=$?
195 if test $RC != 0 ; then
196         echo "ldapsearch failed ($RC)!"
197         test $KILLSERVERS != no && kill -HUP $KILLPIDS
198         exit $RC
199 fi
200
201 # queries 2-6 are cacheable
202 CACHEABILITY=0111110
203 grep CACHEABLE $LOG2 | awk '{ 
204                 if ($2 == "NOT") 
205                         printf "Query %d not cacheable\n",NR
206                 else 
207                         printf "Query %d cacheable\n",NR
208         }' 
209 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
210                 if ($2 == "NOT") 
211                         printf "0" 
212                 else 
213                         printf "1" 
214         }'`
215
216 if test "$CACHEABILITY" = "$CACHED" ; then
217         echo "Successfully verified cacheability"
218 else 
219         echo "Error in verifying cacheability"
220         test $KILLSERVERS != no && kill -HUP $KILLPIDS
221         exit 1
222 fi
223
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
228 RC=$?
229 if test $RC != 0 ; then
230         echo "ldapsearch failed ($RC)!"
231         test $KILLSERVERS != no && kill -HUP $KILLPIDS
232         exit $RC
233 fi
234
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
239 RC=$?
240 if test $RC != 0 ; then
241         echo "ldapsearch failed ($RC)!"
242         test $KILLSERVERS != no && kill -HUP $KILLPIDS
243         exit $RC
244 fi
245
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
250 RC=$?
251 if test $RC != 0 ; then
252         echo "ldapsearch failed ($RC)!"
253         test $KILLSERVERS != no && kill -HUP $KILLPIDS
254         exit $RC
255 fi
256
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
261 RC=$?
262
263 if test $RC != 0 ; then
264         echo "ldapsearch failed ($RC)!"
265         test $KILLSERVERS != no && kill -HUP $KILLPIDS
266         exit $RC
267 fi
268
269 #queries 8-11 are answerable
270 ANSWERABILITY=1111
271 grep ANSWERABLE $LOG2 | awk '{ 
272                 if (NR > 7) { 
273                         if ($2 == "NOT") 
274                                 printf "Query %d not answerable\n",NR
275                         else 
276                                 printf "Query %d answerable\n",NR 
277                 }
278         }' 
279 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
280                 if (NR > 7) { 
281                         if ($2 == "NOT") 
282                                 printf "0" 
283                         else 
284                                 printf "1"
285                 } 
286         }'`
287
288 test $KILLSERVERS != no && kill -HUP $KILLPIDS
289
290 if test "$ANSWERABILITY" = "$ANSWERED" ; then
291         echo "Successfully verified answerability"
292 else 
293         echo "Error in verifying answerability"
294         exit 1
295 fi
296
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
303
304 if test $? != 0 ; then
305         echo "Comparison failed"
306         exit 1
307 fi
308
309 echo ">>>>> Test succeeded"
310 exit 0