]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
c428601b13b37bf40b1a3fc4f5a61768709a462b
[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-2004 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=60
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 echo "Using ldapsearch to check that master slapd is running..."
53 for i in 0 1 2 3 4 5; do
54         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
55                 'objectclass=*' > /dev/null 2>&1
56         RC=$?
57         if test $RC = 0 ; then
58                 break
59         fi
60         echo "Waiting 5 seconds for slapd to start..."
61         sleep 5
62 done
63
64 if test $RC != 0 ; then
65         echo "ldapsearch failed ($RC)!"
66         test $KILLSERVERS != no && kill -HUP $KILLPIDS
67         exit $RC
68 fi
69
70 echo "Using ldapadd to populate the master directory..."
71 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
72         $LDIFORDERED > /dev/null 2>&1
73 RC=$?
74 if test $RC != 0 ; then
75         echo "ldapadd failed ($RC)!"
76         test $KILLSERVERS != no && kill -HUP $KILLPIDS
77         exit $RC
78 fi
79
80 echo "Starting proxy cache on TCP/IP port $PORT2..."
81 . $CONFFILTER < $PROXYCACHECONF > $CONF2
82 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
83 CACHEPID=$!
84 if test $WAIT != 0 ; then
85         echo CACHEPID $CACHEPID
86         read foo
87 fi
88 KILLPIDS="$KILLPIDS $CACHEPID"
89
90 echo "Using ldapsearch to check that proxy slapd is running..."
91 for i in 0 1 2 3 4 5; do
92         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
93                 'objectclass=*' > /dev/null 2>&1
94         RC=$?
95         if test $RC = 0 ; then
96                 break
97         fi
98         echo "Waiting 5 seconds for slapd to start..."
99         sleep 5
100 done
101
102 if test $RC != 0 ; then
103         echo "ldapsearch failed ($RC)!"
104         test $KILLSERVERS != no && kill -HUP $KILLPIDS
105         exit $RC
106 fi
107
108 echo "Making queries on the proxy cache..." 
109 echo "Query 1: filter:(sn=Jon) attrs: all" 
110 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
111         'sn=Jon' > $SLAVEOUT 2>&1
112 RC=$?
113 if test $RC != 0 ; then
114         echo "ldapsearch failed ($RC)!"
115         test $KILLSERVERS != no && kill -HUP $KILLPIDS
116         exit $RC
117 fi
118
119 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
120 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
121         '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
122 RC=$?
123 if test $RC != 0 ; then
124         echo "ldapsearch failed ($RC)!"
125         test $KILLSERVERS != no && kill -HUP $KILLPIDS
126         exit $RC
127 fi
128
129 echo "Query 3: filter:(sn=Smith*) attrs:cn sn title uid"  
130 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
131         'sn=Smith*' cn sn title uid >> $SLAVEOUT 2>&1
132 RC=$?
133 if test $RC != 0 ; then
134         echo "ldapsearch failed ($RC)!"
135         test $KILLSERVERS != no && kill -HUP $KILLPIDS
136         exit $RC
137 fi
138
139 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"  
140 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
141         'sn=Doe' cn sn title uid >> $SLAVEOUT 2>&1
142 RC=$?
143 if test $RC != 0 ; then
144         echo "ldapsearch failed ($RC)!"
145         test $KILLSERVERS != no && kill -HUP $KILLPIDS
146         exit $RC
147 fi
148  
149 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
150 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
151         'uid=bjorn' mail postaladdress telephonenumber cn 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 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid"  
160 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
161         'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
162 RC=$?
163 if test $RC != 0 ; then
164         echo "ldapsearch failed ($RC)!"
165         test $KILLSERVERS != no && kill -HUP $KILLPIDS
166         exit $RC
167 fi
168
169 echo "Query 7: filter:(mail=*) cn sn title uid"  
170 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
171         'mail=*' cn sn title 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 # queries 2-6 are cacheable
180 CACHEABILITY=0111110
181 grep CACHEABLE $LOG2 | awk '{ 
182                 if ($2 == "NOT") 
183                         printf "Query %d not cacheable\n",NR
184                 else 
185                         printf "Query %d cacheable\n",NR
186         }' 
187 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
188                 if ($2 == "NOT") 
189                         printf "0" 
190                 else 
191                         printf "1" 
192         }'`
193
194 if test "$CACHEABILITY" = "$CACHED" ; then
195         echo "Successfully verified cacheability"
196 else 
197         echo "Error in verifying cacheability"
198         test $KILLSERVERS != no && kill -HUP $KILLPIDS
199         exit 1
200 fi
201
202 echo "ANSWERABILITY RESULTS" >> $SLAVEOUT
203 echo "" >> $SLAVEOUT
204
205 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
206 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
207         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
208 RC=$?
209 if test $RC != 0 ; then
210         echo "ldapsearch failed ($RC)!"
211         test $KILLSERVERS != no && kill -HUP $KILLPIDS
212         exit $RC
213 fi
214
215 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
216 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
217         'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
218 RC=$?
219 if test $RC != 0 ; then
220         echo "ldapsearch failed ($RC)!"
221         test $KILLSERVERS != no && kill -HUP $KILLPIDS
222         exit $RC
223 fi
224
225 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
226 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
227         'uid=bjorn' mail postaladdress telephonenumber cn 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 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"  
236 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
237         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
238 RC=$?
239
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 #queries 8-11 are answerable
247 ANSWERABILITY=1111
248 grep ANSWERABLE $LOG2 | awk '{ 
249                 if (NR > 7) { 
250                         if ($2 == "NOT") 
251                                 printf "Query %d not answerable\n",NR
252                         else 
253                                 printf "Query %d answerable\n",NR 
254                 }
255         }' 
256 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
257                 if (NR > 7) { 
258                         if ($2 == "NOT") 
259                                 printf "0" 
260                         else 
261                                 printf "1"
262                 } 
263         }'`
264
265 test $KILLSERVERS != no && kill -HUP $KILLPIDS
266
267 if test "$ANSWERABILITY" = "$ANSWERED" ; then
268         echo "Successfully verified answerability"
269 else 
270         echo "Error in verifying answerability"
271         exit 1
272 fi
273
274 echo "Comparing cache output..."
275 $CMP $SLAVEOUT $PROXYCACHEOUT > $CMPOUT
276
277 if test $? != 0 ; then
278         echo "Comparison failed"
279         exit 1
280 fi
281
282 echo ">>>>> Test succeeded"
283 exit 0