]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
allow writable dirs to be user-relocated
[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 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 echo "Making queries on the proxy cache..." 
118 echo "Query 1: filter:(sn=Jon) attrs: all" 
119 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
120         'sn=Jon' > $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 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
129 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
130         '(|(cn=*Jon*)(sn=Jon*))' 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 3: filter:(sn=Smith*) attrs:cn sn title uid"  
139 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
140         'sn=Smith*' cn sn title 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 4: filter:(sn=Doe*) attrs:cn sn title uid"  
149 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
150         'sn=Doe' 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 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
159 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
160         'uid=bjorn' mail postaladdress telephonenumber cn 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 echo "Query 6: filter:(mail=*@mail.alumni.example.com) cn sn title uid"  
169 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
170         'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
171 RC=$?
172 if test $RC != 0 ; then
173         echo "ldapsearch failed ($RC)!"
174         test $KILLSERVERS != no && kill -HUP $KILLPIDS
175         exit $RC
176 fi
177
178 echo "Query 7: filter:(mail=*) cn sn title uid"  
179 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
180         'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
181 RC=$?
182 if test $RC != 0 ; then
183         echo "ldapsearch failed ($RC)!"
184         test $KILLSERVERS != no && kill -HUP $KILLPIDS
185         exit $RC
186 fi
187
188 # queries 2-6 are cacheable
189 CACHEABILITY=0111110
190 grep CACHEABLE $LOG2 | awk '{ 
191                 if ($2 == "NOT") 
192                         printf "Query %d not cacheable\n",NR
193                 else 
194                         printf "Query %d cacheable\n",NR
195         }' 
196 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
197                 if ($2 == "NOT") 
198                         printf "0" 
199                 else 
200                         printf "1" 
201         }'`
202
203 if test "$CACHEABILITY" = "$CACHED" ; then
204         echo "Successfully verified cacheability"
205 else 
206         echo "Error in verifying cacheability"
207         test $KILLSERVERS != no && kill -HUP $KILLPIDS
208         exit 1
209 fi
210
211 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
212 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
213         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
214 RC=$?
215 if test $RC != 0 ; then
216         echo "ldapsearch failed ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219 fi
220
221 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
222 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
223         'sn=Smith' 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 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
232 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
233         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
234 RC=$?
235 if test $RC != 0 ; then
236         echo "ldapsearch failed ($RC)!"
237         test $KILLSERVERS != no && kill -HUP $KILLPIDS
238         exit $RC
239 fi
240
241 echo "Query 11: filter:(mail=jaj@mail.alumni.example.com) cn sn title uid"  
242 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
243         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
244 RC=$?
245
246 if test $RC != 0 ; then
247         echo "ldapsearch failed ($RC)!"
248         test $KILLSERVERS != no && kill -HUP $KILLPIDS
249         exit $RC
250 fi
251
252 #queries 8-11 are answerable
253 ANSWERABILITY=1111
254 grep ANSWERABLE $LOG2 | awk '{ 
255                 if (NR > 7) { 
256                         if ($2 == "NOT") 
257                                 printf "Query %d not answerable\n",NR
258                         else 
259                                 printf "Query %d answerable\n",NR 
260                 }
261         }' 
262 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
263                 if (NR > 7) { 
264                         if ($2 == "NOT") 
265                                 printf "0" 
266                         else 
267                                 printf "1"
268                 } 
269         }'`
270
271 test $KILLSERVERS != no && kill -HUP $KILLPIDS
272
273 if test "$ANSWERABILITY" = "$ANSWERED" ; then
274         echo "Successfully verified answerability"
275 else 
276         echo "Error in verifying answerability"
277         exit 1
278 fi
279
280 echo "Filtering ldapsearch results..."
281 . $LDIFFILTER < $SLAVEOUT > $SEARCHFLT
282 echo "Comparing filter output..."
283 $CMP $SEARCHFLT $PROXYCACHEOUT > $CMPOUT
284
285 if test $? != 0 ; then
286         echo "Comparison failed"
287         exit 1
288 fi
289
290 echo ">>>>> Test succeeded"
291 exit 0