]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
More fixes from HEAD
[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-2006 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 trace > $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 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
127 echo "# Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid" >> $SLAVEOUT
128 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
129         '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
130 RC=$?
131 if test $RC != 0 ; then
132         echo "ldapsearch failed ($RC)!"
133         test $KILLSERVERS != no && kill -HUP $KILLPIDS
134         exit $RC
135 fi
136
137 echo "Query 3: filter:(sn=Smith*) attrs:cn sn uid"  
138 echo "# Query 3: filter:(sn=Smith*) attrs:cn sn uid" >> $SLAVEOUT
139 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
140         'sn=Smith*' cn sn uid >> $SLAVEOUT 2>&1
141 RC=$?
142 if test $RC != 0 ; then
143         echo "ldapsearch failed ($RC)!"
144         test $KILLSERVERS != no && kill -HUP $KILLPIDS
145         exit $RC
146 fi
147
148 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"  
149 echo "# Query 4: filter:(sn=Doe*) attrs:cn sn title uid" >> $SLAVEOUT
150 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
151         'sn=Doe' cn sn title uid >> $SLAVEOUT 2>&1
152 RC=$?
153 if test $RC != 0 ; then
154         echo "ldapsearch failed ($RC)!"
155         test $KILLSERVERS != no && kill -HUP $KILLPIDS
156         exit $RC
157 fi
158  
159 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
160 echo "# Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid" >> $SLAVEOUT
161 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
162         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
163 RC=$?
164 if test $RC != 0 ; then
165         echo "ldapsearch failed ($RC)!"
166         test $KILLSERVERS != no && kill -HUP $KILLPIDS
167         exit $RC
168 fi
169
170 echo "Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid"  
171 echo "# Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid" >> $SLAVEOUT
172 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
173         'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
174 RC=$?
175 if test $RC != 0 ; then
176         echo "ldapsearch failed ($RC)!"
177         test $KILLSERVERS != no && kill -HUP $KILLPIDS
178         exit $RC
179 fi
180
181 echo "Query 7: filter:(mail=*) cn sn title uid"  
182 echo "# Query 7: filter:(mail=*) cn sn title uid" >> $SLAVEOUT
183 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
184         'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
185 RC=$?
186 if test $RC != 0 ; then
187         echo "ldapsearch failed ($RC)!"
188         test $KILLSERVERS != no && kill -HUP $KILLPIDS
189         exit $RC
190 fi
191
192 # queries 2-6 are cacheable
193 CACHEABILITY=0111110
194 grep CACHEABLE $LOG2 | awk '{ 
195                 if ($2 == "NOT") 
196                         printf "Query %d not cacheable\n",NR
197                 else 
198                         printf "Query %d cacheable\n",NR
199         }' 
200 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
201                 if ($2 == "NOT") 
202                         printf "0" 
203                 else 
204                         printf "1" 
205         }'`
206
207 if test "$CACHEABILITY" = "$CACHED" ; then
208         echo "Successfully verified cacheability"
209 else 
210         echo "Error in verifying cacheability"
211         test $KILLSERVERS != no && kill -HUP $KILLPIDS
212         exit 1
213 fi
214
215 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
216 echo "# Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid" >> $SLAVEOUT
217 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
218         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
219 RC=$?
220 if test $RC != 0 ; then
221         echo "ldapsearch failed ($RC)!"
222         test $KILLSERVERS != no && kill -HUP $KILLPIDS
223         exit $RC
224 fi
225
226 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
227 echo "# Query 9: filter:(sn=Smith) attrs:cn sn title uid" >> $SLAVEOUT
228 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
229         'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
230 RC=$?
231 if test $RC != 0 ; then
232         echo "ldapsearch failed ($RC)!"
233         test $KILLSERVERS != no && kill -HUP $KILLPIDS
234         exit $RC
235 fi
236
237 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
238 echo "# Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid" >> $SLAVEOUT
239 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
240         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
241 RC=$?
242 if test $RC != 0 ; then
243         echo "ldapsearch failed ($RC)!"
244         test $KILLSERVERS != no && kill -HUP $KILLPIDS
245         exit $RC
246 fi
247
248 echo "Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"  
249 echo "# Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid" >> $SLAVEOUT
250 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
251         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
252 RC=$?
253
254 if test $RC != 0 ; then
255         echo "ldapsearch failed ($RC)!"
256         test $KILLSERVERS != no && kill -HUP $KILLPIDS
257         exit $RC
258 fi
259
260 #queries 8-11 are answerable
261 ANSWERABILITY=1111
262 grep ANSWERABLE $LOG2 | awk '{ 
263                 if (NR > 7) { 
264                         if ($2 == "NOT") 
265                                 printf "Query %d not answerable\n",NR
266                         else 
267                                 printf "Query %d answerable\n",NR 
268                 }
269         }' 
270 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
271                 if (NR > 7) { 
272                         if ($2 == "NOT") 
273                                 printf "0" 
274                         else 
275                                 printf "1"
276                 } 
277         }'`
278
279 test $KILLSERVERS != no && kill -HUP $KILLPIDS
280
281 if test "$ANSWERABILITY" = "$ANSWERED" ; then
282         echo "Successfully verified answerability"
283 else 
284         echo "Error in verifying answerability"
285         exit 1
286 fi
287
288 echo "Filtering ldapsearch results..."
289 . $LDIFFILTER < $SLAVEOUT > $SEARCHFLT
290 echo "Filtering original ldif..."
291 . $LDIFFILTER < $PROXYCACHEOUT > $LDIFFLT
292 echo "Comparing filter output..."
293 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
294
295 if test $? != 0 ; then
296         echo "Comparison failed"
297         exit 1
298 fi
299
300 echo ">>>>> Test succeeded"
301 exit 0