]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
f1370aedb0fbb2652f2ded7d1c244ba338115346
[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 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
27
28 # Test proxy caching:
29 # - start master
30 # - start proxy cache
31 # - populate master 
32 # - perform first set of searches at the proxy
33 # - verify cacheability
34 # - perform second set of searches at the proxy 
35 # - verify answerability
36
37 echo "Starting master slapd on TCP/IP port $PORT1..."
38 . $CONFFILTER < $CACHEMASTERCONF > $CONF1
39 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
40 PID=$!
41 if test $WAIT != 0 ; then
42         echo PID $PID
43         read foo
44 fi
45 KILLPIDS="$PID"
46
47 echo "Using ldapsearch to check that master slapd is running..."
48 for i in 0 1 2 3 4 5; do
49         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
50                 'objectclass=*' > /dev/null 2>&1
51         RC=$?
52         if test $RC = 0 ; then
53                 break
54         fi
55         echo "Waiting 5 seconds for slapd to start..."
56         sleep 5
57 done
58
59 if test $RC != 0 ; then
60         echo "ldapsearch failed ($RC)!"
61         test $KILLSERVERS != no && kill -HUP $KILLPIDS
62         exit $RC
63 fi
64
65 echo "Using ldapadd to populate the master directory..."
66 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
67         $LDIFORDERED > /dev/null 2>&1
68 RC=$?
69 if test $RC != 0 ; then
70         echo "ldapadd failed ($RC)!"
71         test $KILLSERVERS != no && kill -HUP $KILLPIDS
72         exit $RC
73 fi
74
75 echo "Starting proxy cache on TCP/IP port $PORT2..."
76 . $CONFFILTER < $PROXYCACHECONF > $CONF2
77 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
78 CACHEPID=$!
79 if test $WAIT != 0 ; then
80         echo CACHEPID $CACHEPID
81         read foo
82 fi
83 KILLPIDS="$KILLPIDS $CACHEPID"
84
85 echo "Using ldapsearch to check that proxy slapd is running..."
86 for i in 0 1 2 3 4 5; do
87         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
88                 'objectclass=*' > /dev/null 2>&1
89         RC=$?
90         if test $RC = 0 ; then
91                 break
92         fi
93         echo "Waiting 5 seconds for slapd to start..."
94         sleep 5
95 done
96
97 echo "Making queries on the proxy cache..." 
98 echo "Query 1: filter:(sn=Jon) attrs: all" 
99 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
100         'sn=Jon' > $SLAVEOUT 2>&1
101 RC=$?
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 "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
109 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
110         '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
111 RC=$?
112 if test $RC != 0 ; then
113         echo "ldapsearch failed ($RC)!"
114         test $KILLSERVERS != no && kill -HUP $KILLPIDS
115         exit $RC
116 fi
117
118 echo "Query 3: filter:(sn=Smith*) attrs:cn sn title uid"  
119 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
120         'sn=Smith*' cn sn title uid >> $SLAVEOUT 2>&1
121 RC=$?
122 if test $RC != 0 ; then
123         echo "ldapsearch failed ($RC)!"
124         test $KILLSERVERS != no && kill -HUP $KILLPIDS
125         exit $RC
126 fi
127
128 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"  
129 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
130         'sn=Doe' cn sn title uid >> $SLAVEOUT 2>&1
131 RC=$?
132 if test $RC != 0 ; then
133         echo "ldapsearch failed ($RC)!"
134         test $KILLSERVERS != no && kill -HUP $KILLPIDS
135         exit $RC
136 fi
137  
138 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
139 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
140         'uid=bjorn' mail postaladdress telephonenumber cn 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 6: filter:(mail=*@example.com) cn sn title uid"  
149 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
150         'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
151 RC=$?
152 if test $RC != 0 ; then
153         echo "ldapsearch failed ($RC)!"
154         test $KILLSERVERS != no && kill -HUP $KILLPIDS
155         exit $RC
156 fi
157
158 echo "Query 7: filter:(mail=*) cn sn title uid"  
159 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
160         'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
161 RC=$?
162 if test $RC != 0 ; then
163         echo "ldapsearch failed ($RC)!"
164         test $KILLSERVERS != no && kill -HUP $KILLPIDS
165         exit $RC
166 fi
167
168 # queries 2-6 are cacheable
169 CACHEABILITY=0111110
170 grep CACHEABLE $LOG2 | awk '{ 
171                 if ($2 == "NOT") 
172                         printf "Query %d not cacheable\n",NR
173                 else 
174                         printf "Query %d cacheable\n",NR
175         }' 
176 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
177                 if ($2 == "NOT") 
178                         printf "0" 
179                 else 
180                         printf "1" 
181         }'`
182
183 if test "$CACHEABILITY" = "$CACHED" ; then
184         echo "Successfully verified cacheability"
185 else 
186         echo "Error in verifying cacheability"
187         test $KILLSERVERS != no && kill -HUP $KILLPIDS
188         exit 1
189 fi
190
191 echo "ANSWERABILITY RESULTS" >> $SLAVEOUT
192 echo "" >> $SLAVEOUT
193
194 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
195 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
196         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
197 RC=$?
198 if test $RC != 0 ; then
199         echo "ldapsearch failed ($RC)!"
200         test $KILLSERVERS != no && kill -HUP $KILLPIDS
201         exit $RC
202 fi
203
204 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
205 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
206         'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
207 RC=$?
208 if test $RC != 0 ; then
209         echo "ldapsearch failed ($RC)!"
210         test $KILLSERVERS != no && kill -HUP $KILLPIDS
211         exit $RC
212 fi
213
214 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
215 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
216         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
217 RC=$?
218 if test $RC != 0 ; then
219         echo "ldapsearch failed ($RC)!"
220         test $KILLSERVERS != no && kill -HUP $KILLPIDS
221         exit $RC
222 fi
223
224 echo "Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"  
225 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
226         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
227 RC=$?
228
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 #queries 8-11 are answerable
236 ANSWERABILITY=1111
237 grep ANSWERABLE $LOG2 | awk '{ 
238                 if (NR > 7) { 
239                         if ($2 == "NOT") 
240                                 printf "Query %d not answerable\n",NR
241                         else 
242                                 printf "Query %d answerable\n",NR 
243                 }
244         }' 
245 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
246                 if (NR > 7) { 
247                         if ($2 == "NOT") 
248                                 printf "0" 
249                         else 
250                                 printf "1"
251                 } 
252         }'`
253
254 test $KILLSERVERS != no && kill -HUP $KILLPIDS
255
256 if test "$ANSWERABILITY" = "$ANSWERED" ; then
257         echo "Successfully verified answerability"
258 else 
259         echo "Error in verifying answerability"
260         exit 1
261 fi
262
263 echo "Comparing cache output..."
264 $CMP $SLAVEOUT $PROXYCACHEOUT > $CMPOUT
265
266 if test $? != 0 ; then
267         echo "Comparison failed"
268         exit 1
269 fi
270
271 echo ">>>>> Test succeeded"
272 exit 0