]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
c6ec3db525b28933128a0edc797a9d6b8e3f7d70
[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-2005 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 if test "x$LVL" = "x0" ; then
32         echo "test020 needs a minimal log level; setting to LDAP_DEBUG_NONE..."
33         LVL=2048
34 fi
35
36 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
37
38 # Test proxy caching:
39 # - start master
40 # - start proxy cache
41 # - populate master 
42 # - perform first set of searches at the proxy
43 # - verify cacheability
44 # - perform second set of searches at the proxy 
45 # - verify answerability
46
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 &
50 PID=$!
51 if test $WAIT != 0 ; then
52         echo PID $PID
53         read foo
54 fi
55 KILLPIDS="$PID"
56
57 sleep 1
58
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
63         RC=$?
64         if test $RC = 0 ; then
65                 break
66         fi
67         echo "Waiting 5 seconds for slapd to start..."
68         sleep 5
69 done
70
71 if test $RC != 0 ; then
72         echo "ldapsearch failed ($RC)!"
73         test $KILLSERVERS != no && kill -HUP $KILLPIDS
74         exit $RC
75 fi
76
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
80 RC=$?
81 if test $RC != 0 ; then
82         echo "ldapadd failed ($RC)!"
83         test $KILLSERVERS != no && kill -HUP $KILLPIDS
84         exit $RC
85 fi
86
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 &
90 CACHEPID=$!
91 if test $WAIT != 0 ; then
92         echo CACHEPID $CACHEPID
93         read foo
94 fi
95 KILLPIDS="$KILLPIDS $CACHEPID"
96
97 sleep 1
98
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
103         RC=$?
104         if test $RC = 0 ; then
105                 break
106         fi
107         echo "Waiting 5 seconds for slapd to start..."
108         sleep 5
109 done
110
111 if test $RC != 0 ; then
112         echo "ldapsearch failed ($RC)!"
113         test $KILLSERVERS != no && kill -HUP $KILLPIDS
114         exit $RC
115 fi
116
117 cat /dev/null > $SLAVEOUT
118
119 echo "Making queries on the proxy cache..." 
120 echo "Query 1: filter:(sn=Jon) attrs: all" 
121 echo "# Query 1: filter:(sn=Jon) attrs: all" >> $SLAVEOUT
122 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
123         'sn=Jon' >> $SLAVEOUT 2>&1
124 RC=$?
125 if test $RC != 0 ; then
126         echo "ldapsearch failed ($RC)!"
127         test $KILLSERVERS != no && kill -HUP $KILLPIDS
128         exit $RC
129 fi
130
131 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
132 echo "# Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid" >> $SLAVEOUT
133 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
134         '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
135 RC=$?
136 if test $RC != 0 ; then
137         echo "ldapsearch failed ($RC)!"
138         test $KILLSERVERS != no && kill -HUP $KILLPIDS
139         exit $RC
140 fi
141
142 echo "Query 3: filter:(sn=Smith*) attrs:cn sn title uid"  
143 echo "# Query 3: filter:(sn=Smith*) attrs:cn sn title uid" >> $SLAVEOUT
144 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
145         'sn=Smith*' cn sn title uid >> $SLAVEOUT 2>&1
146 RC=$?
147 if test $RC != 0 ; then
148         echo "ldapsearch failed ($RC)!"
149         test $KILLSERVERS != no && kill -HUP $KILLPIDS
150         exit $RC
151 fi
152
153 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"  
154 echo "# Query 4: filter:(sn=Doe*) attrs:cn sn title uid" >> $SLAVEOUT
155 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
156         'sn=Doe' cn sn title uid >> $SLAVEOUT 2>&1
157 RC=$?
158 if test $RC != 0 ; then
159         echo "ldapsearch failed ($RC)!"
160         test $KILLSERVERS != no && kill -HUP $KILLPIDS
161         exit $RC
162 fi
163  
164 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
165 echo "# Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid" >> $SLAVEOUT
166 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
167         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
168 RC=$?
169 if test $RC != 0 ; then
170         echo "ldapsearch failed ($RC)!"
171         test $KILLSERVERS != no && kill -HUP $KILLPIDS
172         exit $RC
173 fi
174
175 echo "Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid"  
176 echo "# Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid" >> $SLAVEOUT
177 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
178         'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
179 RC=$?
180 if test $RC != 0 ; then
181         echo "ldapsearch failed ($RC)!"
182         test $KILLSERVERS != no && kill -HUP $KILLPIDS
183         exit $RC
184 fi
185
186 echo "Query 7: filter:(mail=*) cn sn title uid"  
187 echo "# Query 7: filter:(mail=*) cn sn title uid" >> $SLAVEOUT
188 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
189         'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
190 RC=$?
191 if test $RC != 0 ; then
192         echo "ldapsearch failed ($RC)!"
193         test $KILLSERVERS != no && kill -HUP $KILLPIDS
194         exit $RC
195 fi
196
197 # queries 2-6 are cacheable
198 CACHEABILITY=0111110
199 grep CACHEABLE $LOG2 | awk '{ 
200                 if ($2 == "NOT") 
201                         printf "Query %d not cacheable\n",NR
202                 else 
203                         printf "Query %d cacheable\n",NR
204         }' 
205 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
206                 if ($2 == "NOT") 
207                         printf "0" 
208                 else 
209                         printf "1" 
210         }'`
211
212 if test "$CACHEABILITY" = "$CACHED" ; then
213         echo "Successfully verified cacheability"
214 else 
215         echo "Error in verifying cacheability"
216         test $KILLSERVERS != no && kill -HUP $KILLPIDS
217         exit 1
218 fi
219
220 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
221 echo "# Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid" >> $SLAVEOUT
222 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
223         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
224 RC=$?
225 if test $RC != 0 ; then
226         echo "ldapsearch failed ($RC)!"
227         test $KILLSERVERS != no && kill -HUP $KILLPIDS
228         exit $RC
229 fi
230
231 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
232 echo "# Query 9: filter:(sn=Smith) attrs:cn sn title uid" >> $SLAVEOUT
233 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
234         'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
235 RC=$?
236 if test $RC != 0 ; then
237         echo "ldapsearch failed ($RC)!"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS
239         exit $RC
240 fi
241
242 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
243 echo "# Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid" >> $SLAVEOUT
244 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
245         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
246 RC=$?
247 if test $RC != 0 ; then
248         echo "ldapsearch failed ($RC)!"
249         test $KILLSERVERS != no && kill -HUP $KILLPIDS
250         exit $RC
251 fi
252
253 echo "Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"  
254 echo "# Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid" >> $SLAVEOUT
255 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
256         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
257 RC=$?
258
259 if test $RC != 0 ; then
260         echo "ldapsearch failed ($RC)!"
261         test $KILLSERVERS != no && kill -HUP $KILLPIDS
262         exit $RC
263 fi
264
265 #queries 8-11 are answerable
266 ANSWERABILITY=1111
267 grep ANSWERABLE $LOG2 | awk '{ 
268                 if (NR > 7) { 
269                         if ($2 == "NOT") 
270                                 printf "Query %d not answerable\n",NR
271                         else 
272                                 printf "Query %d answerable\n",NR 
273                 }
274         }' 
275 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
276                 if (NR > 7) { 
277                         if ($2 == "NOT") 
278                                 printf "0" 
279                         else 
280                                 printf "1"
281                 } 
282         }'`
283
284 test $KILLSERVERS != no && kill -HUP $KILLPIDS
285
286 if test "$ANSWERABILITY" = "$ANSWERED" ; then
287         echo "Successfully verified answerability"
288 else 
289         echo "Error in verifying answerability"
290         exit 1
291 fi
292
293 echo "Filtering ldapsearch results..."
294 . $LDIFFILTER < $SLAVEOUT > $SEARCHFLT
295 echo "Filtering original ldif..."
296 . $LDIFFILTER < $PROXYCACHEOUT > $LDIFFLT
297 echo "Comparing filter output..."
298 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
299
300 if test $? != 0 ; then
301         echo "Comparison failed"
302         exit 1
303 fi
304
305 echo ">>>>> Test succeeded"
306 exit 0