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