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