]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
20d7337777bc6f4cb1a0e2db4d0318a9863d9b09
[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 echo "Making queries on the proxy cache..." 
103 echo "Query 1: filter:(sn=Jon) attrs: all" 
104 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
105         'sn=Jon' > $SLAVEOUT 2>&1
106 RC=$?
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 "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
114 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
115         '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
116 RC=$?
117 if test $RC != 0 ; then
118         echo "ldapsearch failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 echo "Query 3: filter:(sn=Smith*) attrs:cn sn title uid"  
124 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
125         'sn=Smith*' cn sn title uid >> $SLAVEOUT 2>&1
126 RC=$?
127 if test $RC != 0 ; then
128         echo "ldapsearch failed ($RC)!"
129         test $KILLSERVERS != no && kill -HUP $KILLPIDS
130         exit $RC
131 fi
132
133 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"  
134 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
135         'sn=Doe' cn sn title uid >> $SLAVEOUT 2>&1
136 RC=$?
137 if test $RC != 0 ; then
138         echo "ldapsearch failed ($RC)!"
139         test $KILLSERVERS != no && kill -HUP $KILLPIDS
140         exit $RC
141 fi
142  
143 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
144 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
145         'uid=bjorn' mail postaladdress telephonenumber cn 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 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid"  
154 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
155         'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
156 RC=$?
157 if test $RC != 0 ; then
158         echo "ldapsearch failed ($RC)!"
159         test $KILLSERVERS != no && kill -HUP $KILLPIDS
160         exit $RC
161 fi
162
163 echo "Query 7: filter:(mail=*) cn sn title uid"  
164 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
165         'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
166 RC=$?
167 if test $RC != 0 ; then
168         echo "ldapsearch failed ($RC)!"
169         test $KILLSERVERS != no && kill -HUP $KILLPIDS
170         exit $RC
171 fi
172
173 # queries 2-6 are cacheable
174 CACHEABILITY=0111110
175 grep CACHEABLE $LOG2 | awk '{ 
176                 if ($2 == "NOT") 
177                         printf "Query %d not cacheable\n",NR
178                 else 
179                         printf "Query %d cacheable\n",NR
180         }' 
181 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
182                 if ($2 == "NOT") 
183                         printf "0" 
184                 else 
185                         printf "1" 
186         }'`
187
188 if test "$CACHEABILITY" = "$CACHED" ; then
189         echo "Successfully verified cacheability"
190 else 
191         echo "Error in verifying cacheability"
192         test $KILLSERVERS != no && kill -HUP $KILLPIDS
193         exit 1
194 fi
195
196 echo "ANSWERABILITY RESULTS" >> $SLAVEOUT
197 echo "" >> $SLAVEOUT
198
199 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
200 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
201         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
202 RC=$?
203 if test $RC != 0 ; then
204         echo "ldapsearch failed ($RC)!"
205         test $KILLSERVERS != no && kill -HUP $KILLPIDS
206         exit $RC
207 fi
208
209 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
210 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
211         'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
212 RC=$?
213 if test $RC != 0 ; then
214         echo "ldapsearch failed ($RC)!"
215         test $KILLSERVERS != no && kill -HUP $KILLPIDS
216         exit $RC
217 fi
218
219 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
220 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
221         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
222 RC=$?
223 if test $RC != 0 ; then
224         echo "ldapsearch failed ($RC)!"
225         test $KILLSERVERS != no && kill -HUP $KILLPIDS
226         exit $RC
227 fi
228
229 echo "Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"  
230 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
231         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
232 RC=$?
233
234 if test $RC != 0 ; then
235         echo "ldapsearch failed ($RC)!"
236         test $KILLSERVERS != no && kill -HUP $KILLPIDS
237         exit $RC
238 fi
239
240 #queries 8-11 are answerable
241 ANSWERABILITY=1111
242 grep ANSWERABLE $LOG2 | awk '{ 
243                 if (NR > 7) { 
244                         if ($2 == "NOT") 
245                                 printf "Query %d not answerable\n",NR
246                         else 
247                                 printf "Query %d answerable\n",NR 
248                 }
249         }' 
250 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
251                 if (NR > 7) { 
252                         if ($2 == "NOT") 
253                                 printf "0" 
254                         else 
255                                 printf "1"
256                 } 
257         }'`
258
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
260
261 if test "$ANSWERABILITY" = "$ANSWERED" ; then
262         echo "Successfully verified answerability"
263 else 
264         echo "Error in verifying answerability"
265         exit 1
266 fi
267
268 echo "Comparing cache output..."
269 $CMP $SLAVEOUT $PROXYCACHEOUT > $CMPOUT
270
271 if test $? != 0 ; then
272         echo "Comparison failed"
273         exit 1
274 fi
275
276 echo ">>>>> Test succeeded"
277 exit 0