]> git.sur5r.net Git - openldap/blob - tests/scripts/test020-proxycache
c4779f33bf781ca88cd0620411d695e8d0ecdccc
[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 if test $RC != 0 ; then
98         echo "ldapsearch failed ($RC)!"
99         test $KILLSERVERS != no && kill -HUP $KILLPIDS
100         exit $RC
101 fi
102
103 echo "Making queries on the proxy cache..." 
104 echo "Query 1: filter:(sn=Jon) attrs: all" 
105 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
106         'sn=Jon' > $SLAVEOUT 2>&1
107 RC=$?
108 if test $RC != 0 ; then
109         echo "ldapsearch failed ($RC)!"
110         test $KILLSERVERS != no && kill -HUP $KILLPIDS
111         exit $RC
112 fi
113
114 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
115 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
116         '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $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 3: filter:(sn=Smith*) attrs:cn sn title uid"  
125 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
126         'sn=Smith*' 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 4: filter:(sn=Doe*) attrs:cn sn title uid"  
135 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
136         'sn=Doe' 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 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
145 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
146         'uid=bjorn' mail postaladdress telephonenumber cn 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 6: filter:(mail=*@example.com) cn sn title uid"  
155 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
156         'mail=*@mail.alumni.example.com' cn sn title 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 7: filter:(mail=*) cn sn title uid"  
165 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
166         'mail=*' 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 # queries 2-6 are cacheable
175 CACHEABILITY=0111110
176 grep CACHEABLE $LOG2 | awk '{ 
177                 if ($2 == "NOT") 
178                         printf "Query %d not cacheable\n",NR
179                 else 
180                         printf "Query %d cacheable\n",NR
181         }' 
182 CACHED=`grep CACHEABLE $LOG2 | awk '{ 
183                 if ($2 == "NOT") 
184                         printf "0" 
185                 else 
186                         printf "1" 
187         }'`
188
189 if test "$CACHEABILITY" = "$CACHED" ; then
190         echo "Successfully verified cacheability"
191 else 
192         echo "Error in verifying cacheability"
193         test $KILLSERVERS != no && kill -HUP $KILLPIDS
194         exit 1
195 fi
196
197 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
198 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
199         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
200 RC=$?
201 if test $RC != 0 ; then
202         echo "ldapsearch failed ($RC)!"
203         test $KILLSERVERS != no && kill -HUP $KILLPIDS
204         exit $RC
205 fi
206
207 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
208 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
209         'sn=Smith' 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 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
218 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
219         'uid=bjorn' mail postaladdress telephonenumber cn 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 11: filter:(mail=*@example.com) cn sn title uid"  
228 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
229         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
230 RC=$?
231
232 if test $RC != 0 ; then
233         echo "ldapsearch failed ($RC)!"
234         test $KILLSERVERS != no && kill -HUP $KILLPIDS
235         exit $RC
236 fi
237
238 #queries 8-11 are answerable
239 ANSWERABILITY=1111
240 grep ANSWERABLE $LOG2 | awk '{ 
241                 if (NR > 7) { 
242                         if ($2 == "NOT") 
243                                 printf "Query %d not answerable\n",NR
244                         else 
245                                 printf "Query %d answerable\n",NR 
246                 }
247         }' 
248 ANSWERED=`grep ANSWERABLE $LOG2 | awk '{ 
249                 if (NR > 7) { 
250                         if ($2 == "NOT") 
251                                 printf "0" 
252                         else 
253                                 printf "1"
254                 } 
255         }'`
256
257 test $KILLSERVERS != no && kill -HUP $KILLPIDS
258
259 if test "$ANSWERABILITY" = "$ANSWERED" ; then
260         echo "Successfully verified answerability"
261 else 
262         echo "Error in verifying answerability"
263         exit 1
264 fi
265
266 echo ">>>>> Test succeeded"
267 exit 0