]> git.sur5r.net Git - openldap/blob - tests/scripts/test019-proxycaching
fix ITS#2733
[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 $PROXYCACHE = no; then 
15         echo "Proxy caching requires back-meta AND (back-ldbm OR back-bdb)" 
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 10
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 if test $WAIT != 0 ; then
79         echo CACHEPID $CACHEPID
80         read foo
81 fi
82
83 sleep 8
84 echo "Making queries on the proxy cache..." 
85 echo "Query 1: filter:(sn=Jon) attrs: all" 
86 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
87         'sn=Jon' > $SLAVEOUT 2>&1
88 RC=$?
89 if test $RC != 0 ; then
90         echo "ldapsearch failed ($RC)!"
91         kill -HUP $PID $CACHEPID
92         exit $RC
93 fi
94 sleep 3
95
96 echo "Query 2: filter:(|(cn=*Jon*)(sn=Jon*)) attrs:cn sn title uid"  
97 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
98         '(|(cn=*Jon*)(sn=Jon*))' cn sn title uid >> $SLAVEOUT 2>&1
99 RC=$?
100 if test $RC != 0 ; then
101         echo "ldapsearch failed ($RC)!"
102         kill -HUP $PID $CACHEPID
103         exit $RC
104 fi
105 sleep 3
106
107 echo "Query 3: filter:(sn=Smith*) attrs:cn sn title uid"  
108 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
109         'sn=Smith*' cn sn title uid >> $SLAVEOUT 2>&1
110 RC=$?
111 if test $RC != 0 ; then
112         echo "ldapsearch failed ($RC)!"
113         kill -HUP $PID $CACHEPID
114         exit $RC
115 fi
116 sleep 3
117
118 echo "Query 4: filter:(sn=Doe*) attrs:cn sn title uid"  
119 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
120         'sn=Doe' cn sn title uid >> $SLAVEOUT 2>&1
121 RC=$?
122 if test $RC != 0 ; then
123         echo "ldapsearch failed ($RC)!"
124         kill -HUP $PID $CACHEPID
125         exit $RC
126 fi
127 sleep 3
128  
129 echo "Query 5: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
130 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
131         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
132 RC=$?
133 if test $RC != 0 ; then
134         echo "ldapsearch failed ($RC)!"
135         kill -HUP $PID $CACHEPID
136         exit $RC
137 fi
138 sleep 3
139
140 echo "Query 6: filter:(mail=*@example.com) cn sn title uid"  
141 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
142         'mail=*@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
143 RC=$?
144 if test $RC != 0 ; then
145         echo "ldapsearch failed ($RC)!"
146         kill -HUP $PID $CACHEPID
147         exit $RC
148 fi
149 sleep 3
150
151 echo "Query 7: filter:(mail=*) cn sn title uid"  
152 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
153         'mail=*' cn sn title uid >> $SLAVEOUT 2>&1
154 RC=$?
155 if test $RC != 0 ; then
156         echo "ldapsearch failed ($RC)!"
157         kill -HUP $PID $CACHEPID
158         exit $RC
159 fi
160 sleep 3
161 # queries 2-6 are cacheable
162 CACHEABILITY=0111110
163 grep CACHEABLE $SLAVELOG | awk '{ 
164                                   if ($2 == "NOT") 
165                                     printf "Query %d not cacheable\n",NR
166                                   else 
167                                     printf "Query %d cacheable\n",NR
168                                 }' 
169 CACHED=`grep CACHEABLE $SLAVELOG | awk '{ 
170                                           if ($2 == "NOT") 
171                                             printf "0" 
172                                           else 
173                                             printf "1" 
174                                         }'`
175
176 if test $CACHEABILITY = $CACHED
177 then
178         echo "successfully verified cacheability"
179 else 
180         echo "error in verifying cacheability"
181         kill -HUP $PID $CACHEPID
182         exit 1
183 fi
184
185 echo "Query 8: filter:(|(cn=*Jones)(sn=Jones)) attrs:cn sn title uid"  
186 $LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
187         '(|(cn=*Jones)(sn=Jones))' cn sn title uid >> $SLAVEOUT 2>&1
188 RC=$?
189 if test $RC != 0 ; then
190         echo "ldapsearch failed ($RC)!"
191         kill -HUP $PID $CACHEPID
192         exit $RC
193 fi
194 sleep 3
195
196 echo "Query 9: filter:(sn=Smith) attrs:cn sn title uid"  
197 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
198         'sn=Smith' cn sn title uid >> $SLAVEOUT 2>&1
199 RC=$?
200 if test $RC != 0 ; then
201         echo "ldapsearch failed ($RC)!"
202         kill -HUP $PID $CACHEPID
203         exit $RC
204 fi
205 sleep 3
206
207 echo "Query 10: filter:(uid=bjorn) attrs:mail postaladdress telephonenumber cn uid"  
208 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
209         'uid=bjorn' mail postaladdress telephonenumber cn uid >> $SLAVEOUT 2>&1
210 RC=$?
211 if test $RC != 0 ; then
212         echo "ldapsearch failed ($RC)!"
213         kill -HUP $PID $CACHEPID
214         exit $RC
215 fi
216 sleep 3
217
218 echo "Query 11: filter:(mail=*@example.com) cn sn title uid"  
219 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $SLAVEPORT \
220         'mail=jaj@mail.alumni.example.com' cn sn title uid >> $SLAVEOUT 2>&1
221 RC=$?
222 if test $RC != 0 ; then
223         echo "ldapsearch failed ($RC)!"
224         kill -HUP $PID $CACHEPID
225         exit $RC
226 fi
227 sleep 3
228 #queries 8-11 are answerable
229 ANSWERABILITY=1111
230 grep ANSWERABLE $SLAVELOG | awk '{ 
231                                     if (NR > 7) { 
232                                       if ($2 == "NOT") 
233                                         printf "Query %d not answerable\n",NR
234                                       else 
235                                         printf "Query %d answerable\n",NR 
236                                      }
237                                   }' 
238 ANSWERED=`grep ANSWERABLE $SLAVELOG | awk '{ 
239                                              if (NR > 7) { 
240                                                if ($2 == "NOT") 
241                                                  printf "0" 
242                                                else 
243                                                  printf "1"
244                                              } 
245                                            }'`
246 if test $ANSWERABILITY = $ANSWERED
247 then
248         echo "successfully verified answerability"
249 else 
250         echo "error in verifying answerability"
251         kill -HUP $PID $CACHEPID
252         exit 1
253 fi
254
255 echo "Proxy cache successfully tested" 
256 kill -HUP $PID $CACHEPID