]> git.sur5r.net Git - openldap/blob - tests/scripts/test019-proxycaching
for now, it runs with ldbm only
[openldap] / tests / scripts / test019-proxycaching
1 #! /bin/sh
2 # $OpenLDAP$
3
4 CACHETTL=60
5 CACHE_ENTRY_LIMIT=10
6
7 SRCDIR="."
8 if test $# -ge 1 ; then
9         SRCDIR=$1; shift
10 fi
11
12 . $SRCDIR/scripts/args.sh $*
13
14 if test "$BACKEND" != "ldbm"; then
15         echo "Test only valid for back-ldbm"
16         exit 0
17 fi
18
19 echo "running defines.sh"
20 . $SRCDIR/scripts/defines.sh
21
22 # Test proxy caching:
23 # - start master
24 # - start proxy cache
25 # - populate master 
26 # - perform first set of searches at the proxy
27 # - verify cacheability
28 # - perform second set of searches at the proxy 
29 # - verify answerability
30
31 #if test ! -x $SLAPD ; then
32 #       echo ">>>>> $SLAPD is not executable or does not exist."
33 #       echo ">>>>> Test skipped."
34 #       exit 0
35 #fi
36
37 if test ! -d $DBDIR
38 then 
39         mkdir $DBDIR
40 fi
41
42 if test ! -d $CACHEDIR
43 then 
44         mkdir $CACHEDIR
45 fi
46
47 echo "Cleaning up in $DBDIR..."
48 rm -f $DBDIR/[!C]*
49 echo "Cleaning up in $CACHEDIR..."
50 rm -rf $CACHEDIR/[!C]*
51 echo $DBDIR
52
53 echo "Starting master slapd on TCP/IP port $PORT..."
54 . $CONFFILTER < $CACHEMASTERCONF > $DBCONF
55 $SLAPD -f $DBCONF -h $MASTERURI -d $LVL > $MASTERLOG 2>&1 &
56 PID=$!
57 if test $WAIT != 0 ; then
58         echo PID $PID
59         read foo
60 fi
61
62 sleep 5
63
64 echo "Using ldapadd to populate the master directory..."
65 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT -w $PASSWD < \
66         $LDIFORDERED > /dev/null 2>&1
67 RC=$?
68 if test $RC != 0 ; then
69         echo "ldapadd failed ($RC)!"
70         kill -HUP $PID 
71         exit $RC
72 fi
73
74 echo "Starting proxy cache on TCP/IP port $SLAVEPORT..."
75 . $CONFFILTER < $PROXYCACHECONF > $CACHECONF
76 $SLAPD -f $CACHECONF -h $SLAVEURI -d $LVL > $SLAVELOG 2>&1 &
77 CACHEPID=$!
78 WAIT=1
79 if test $WAIT != 0 ; then
80         echo CACHEPID $CACHEPID
81         read foo
82 fi
83
84 sleep 8
85 echo "Making queries on the proxy cache..." 
86 echo "Query 1: filter:(sn=Jon) attrs: all" 
87 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
88         'sn=Jon' > $SLAVEOUT 2>&1
89 RC=$?
90 if test $RC != 0 ; then
91         echo "ldapsearch failed ($RC)!"
92         kill -HUP $PID $CACHEPID
93         exit $RC
94 fi
95 sleep 3
96
97 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title"  
98 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
99         '(|(cn=*Jon*)(sn=Jon*))' cn sn title >> $SLAVEOUT 2>&1
100 RC=$?
101 if test $RC != 0 ; then
102         echo "ldapsearch failed ($RC)!"
103         kill -HUP $PID $CACHEPID
104         exit $RC
105 fi
106 sleep 3
107
108 echo "Query 3: filter:(sn=Smith*) attrs:cn sn title"  
109 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
110         'sn=Smith*' cn sn title >> $SLAVEOUT 2>&1
111 RC=$?
112 if test $RC != 0 ; then
113         echo "ldapsearch failed ($RC)!"
114         kill -HUP $PID $CACHEPID
115         exit $RC
116 fi
117 sleep 3
118
119 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title"  
120 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
121         'sn=Doe' cn sn title >> $SLAVEOUT 2>&1
122 RC=$?
123 if test $RC != 0 ; then
124         echo "ldapsearch failed ($RC)!"
125         kill -HUP $PID $CACHEPID
126         exit $RC
127 fi
128 sleep 3
129  
130 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber"  
131 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
132         'uid=bjorn' mail postaladdress telephonenumber >> $SLAVEOUT 2>&1
133 RC=$?
134 if test $RC != 0 ; then
135         echo "ldapsearch failed ($RC)!"
136         kill -HUP $PID $CACHEPID
137         exit $RC
138 fi
139 sleep 3
140
141 echo "Query 6: filter:(mail=*@example.com) cn sn title"  
142 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
143         'mail=*@mail.alumni.example.com' cn sn title >> $SLAVEOUT 2>&1
144 RC=$?
145 if test $RC != 0 ; then
146         echo "ldapsearch failed ($RC)!"
147         kill -HUP $PID $CACHEPID
148         exit $RC
149 fi
150 sleep 3
151
152 echo "Query 7: filter:(mail=*) cn sn title"  
153 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
154         'mail=*' cn sn title >> $SLAVEOUT 2>&1
155 RC=$?
156 if test $RC != 0 ; then
157         echo "ldapsearch failed ($RC)!"
158         kill -HUP $PID $CACHEPID
159         exit $RC
160 fi
161 sleep 3
162 # queries 2-6 are cacheable
163 CACHEABILITY=0111110
164 grep CACHEABLE $SLAVELOG | awk '{ 
165                                   if ($2 == "NOT") 
166                                     printf "Query %d not cacheable\n",NR
167                                   else 
168                                     printf "Query %d cacheable\n",NR
169                                 }' 
170 CACHED=`grep CACHEABLE $SLAVELOG | awk '{ 
171                                           if ($2 == "NOT") 
172                                             printf "0" 
173                                           else 
174                                             printf "1" 
175                                         }'`
176
177 if test $CACHEABILITY = $CACHED
178 then
179         echo "successfully verified cacheability"
180 else 
181         echo "error in verifying cacheability"
182         kill -HUP $PID $CACHEPID
183         exit 1
184 fi
185
186 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title"  
187 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
188         '(|(cn=*Jones)(sn=Jones))' cn sn title >> $SLAVEOUT 2>&1
189 RC=$?
190 if test $RC != 0 ; then
191         echo "ldapsearch failed ($RC)!"
192         kill -HUP $PID $CACHEPID
193         exit $RC
194 fi
195 sleep 3
196
197 echo "Query 9: filter:(sn=Smith) attrs:cn sn title"  
198 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
199         'sn=Smith' cn sn title >> $SLAVEOUT 2>&1
200 RC=$?
201 if test $RC != 0 ; then
202         echo "ldapsearch failed ($RC)!"
203         kill -HUP $PID $CACHEPID
204         exit $RC
205 fi
206 sleep 3
207
208 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber"  
209 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
210         'uid=bjorn' mail postaladdress telephonenumber >> $SLAVEOUT 2>&1
211 RC=$?
212 if test $RC != 0 ; then
213         echo "ldapsearch failed ($RC)!"
214         kill -HUP $PID $CACHEPID
215         exit $RC
216 fi
217 sleep 3
218
219 echo "Query 11: filter:(mail=*@example.com) cn sn title"  
220 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
221         'mail=jaj@mail.alumni.example.com' cn sn title >> $SLAVEOUT 2>&1
222 RC=$?
223 if test $RC != 0 ; then
224         echo "ldapsearch failed ($RC)!"
225         kill -HUP $PID $CACHEPID
226         exit $RC
227 fi
228 sleep 3
229 #queries 8-11 are answerable
230 ANSWERABILITY=1111
231 grep ANSWERABLE $SLAVELOG | awk '{ 
232                                     if (NR > 7) { 
233                                       if ($2 == "NOT") 
234                                         printf "Query %d not answerable\n",NR
235                                       else 
236                                         printf "Query %d answerable\n",NR 
237                                      }
238                                   }' 
239 ANSWERED=`grep ANSWERABLE $SLAVELOG | awk '{ 
240                                              if (NR > 7) { 
241                                                if ($2 == "NOT") 
242                                                  printf "0" 
243                                                else 
244                                                  printf "1"
245                                              } 
246                                            }'`
247 if test $ANSWERABILITY = $ANSWERED
248 then
249         echo "successfully verified answerability"
250 else 
251         echo "error in verifying answerability"
252         kill -HUP $PID $CACHEPID
253         exit 1
254 fi
255
256 echo "Proxy cache successfully tested" 
257 kill -HUP $PID $CACHEPID