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