]> git.sur5r.net Git - openldap/blob - tests/scripts/test025-limits
d098b97955ef8f4e60918ddb8f59685880386ee5
[openldap] / tests / scripts / test025-limits
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 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $LIMITSCONF > $ADDCONF
23 $SLAPADD -f $ADDCONF -l $LDIFLIMITS
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Running slapindex to index slapd database..."
31 . $CONFFILTER $BACKEND $MONITORDB < $LIMITSCONF > $CONF1
32 $SLAPINDEX -f $CONF1
33 RC=$?
34 if test $RC != 0 ; then
35         echo "warning: slapindex failed ($RC)"
36         echo "  assuming no indexing support"
37 fi
38
39 echo "Starting slapd on TCP/IP port $PORT1..."
40 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43     echo PID $PID
44     read foo
45 fi
46 KILLPIDS="$PID"
47
48 echo "Testing slapd searching..."
49 for i in 0 1 2 3 4 5; do
50         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
51                 '(objectclass=*)' > /dev/null 2>&1
52         RC=$?
53         if test $RC = 0 ; then
54                 break
55         fi
56         echo "Waiting 5 seconds for slapd to start..."
57         sleep 5
58 done
59
60 if test $RC != 0 ; then
61         echo "ldapsearch failed ($RC)!"
62         test $KILLSERVERS != no && kill -HUP $KILLPIDS
63         exit $RC
64 fi
65
66 cat /dev/null > $SEARCHOUT
67
68 echo "Testing no limits requested for unlimited ID..."
69 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
70         -D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
71         '(objectClass=*)' >$SEARCHOUT 2>&1
72 RC=$?
73 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
74 case $RC in
75         0)
76                 echo "...success (got $COUNT entries)"
77         ;;
78         *)
79                 echo "ldapsearch failed ($RC)!"
80                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
81                 exit $RC
82         ;;
83 esac
84
85 SIZELIMIT=2
86 echo "Testing size limit request ($SIZELIMIT) for unlimited ID..."
87 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
88         -D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
89         '(objectClass=*)' > $SEARCHOUT 2>&1
90 RC=$?
91 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
92 case $RC in
93         0)
94                 echo "...success (got $COUNT entries)"
95         ;;
96         4)
97                 echo "...bumped into requested size limit ($SIZELIMIT)"
98         ;;
99         *)
100                 echo "ldapsearch failed ($RC)!"
101                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
102                 exit $RC
103         ;;
104 esac
105
106 TIMELIMIT=10
107 echo "Testing time limit request ($TIMELIMIT s) for unlimited ID..."
108 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -l $TIMELIMIT \
109         -D 'cn=Unlimited User,ou=People,o=University of Michigan,c=US' \
110         '(objectClass=*)' > $SEARCHOUT 2>&1
111 RC=$?
112 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
113 case $RC in
114         0)
115                 echo "...success (got $COUNT entries)"
116         ;;
117         3)
118                 echo "...bumped into requested time limit ($TIMELIMIT s; $COUNT entries)"
119         ;;
120         *)
121                 echo "ldapsearch failed ($RC)!"
122                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
123                 exit $RC
124         ;;
125 esac
126
127 echo "Testing no limits requested for soft limited ID..."
128 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
129         -D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
130         '(objectClass=*)' > $SEARCHOUT 2>&1
131 RC=$?
132 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
133 case $RC in
134         0)
135                 echo "...success; didn't bump into server-side size limit (got $COUNT entries)"
136         ;;
137         4)
138                 echo "...bumped into server-side size limit ($COUNT)"
139         ;;
140         *)
141                 echo "ldapsearch failed ($RC)!"
142                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
143                 exit $RC
144         ;;
145 esac
146
147 SIZELIMIT=2
148 echo "Testing lower than soft limit request ($SIZELIMIT) for soft limited ID..."
149 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
150         -D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
151         '(objectClass=*)' > $SEARCHOUT 2>&1
152 RC=$?
153 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
154 case $RC in
155         0)
156                 echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
157         ;;
158         4)
159                 if test "x$COUNT" != "x" ; then
160                         if test $SIZELIMIT = $COUNT ; then
161                                 echo "...bumped into requested ($SIZELIMIT) size limit"
162                         else
163                                 echo "...bumped into server-side size limit ($COUNT)"
164                         fi
165                 else
166                         echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
167                 fi
168         ;;
169         *)
170                 echo "ldapsearch failed ($RC)!"
171                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
172                 exit $RC
173         ;;
174 esac
175
176 SIZELIMIT=100
177 echo "Testing higher than soft limit request ($SIZELIMIT) for soft limited ID..."
178 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
179         -D 'cn=Soft Limited User,ou=People,o=University of Michigan,c=US' \
180         '(objectClass=*)' > $SEARCHOUT 2>&1
181 RC=$?
182 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
183 case $RC in
184         0)
185                 echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
186         ;;
187         4)
188                 if test "x$COUNT" != "x" ; then
189                         if test $SIZELIMIT = $COUNT ; then
190                                 echo "...bumped into requested ($SIZELIMIT) size limit"
191                         else
192                                 echo "...bumped into server-side size limit ($COUNT)"
193                         fi
194                 else
195                         echo "...bumped into either requested ($SIZELIMIT) or server-side size limit"
196                 fi
197         ;;
198         *)
199                 echo "ldapsearch failed ($RC)!"
200                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
201                 exit $RC
202         ;;
203 esac
204
205 SIZELIMIT=2
206 echo "Testing lower than hard limit request ($SIZELIMIT) for hard limited ID..."
207 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
208         -D 'cn=Hard Limited User,ou=People,o=University of Michigan,c=US' \
209         '(objectClass=*)' > $SEARCHOUT 2>&1
210 RC=$?
211 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
212 case $RC in
213         0)
214                 echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
215         ;;
216         4)
217                 echo "...bumped into requested ($SIZELIMIT) size limit"
218         ;;
219         *)
220                 echo "ldapsearch failed ($RC)!"
221                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
222                 exit $RC
223         ;;
224 esac
225
226 SIZELIMIT=100
227 echo "Testing higher than hard limit request ($SIZELIMIT) for hard limited ID..."
228 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret -z $SIZELIMIT \
229         -D 'cn=Hard Limited User,ou=People,o=University of Michigan,c=US' \
230         '(objectClass=*)' > $SEARCHOUT 2>&1
231 RC=$?
232 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
233 case $RC in
234         0)
235                 echo "...success; didn't bump into either requested ($SIZELIMIT) or server-side size limit (got $COUNT entries)"
236         ;;
237         4)
238                 echo "...bumped into requested ($SIZELIMIT) size limit"
239         ;;
240         11)
241                 echo "...bumped into server-side size limit"
242         ;;
243         *)
244                 echo "ldapsearch failed ($RC)!"
245                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
246                 exit $RC
247         ;;
248 esac
249
250 echo "Testing lower than unchecked limit request for unchecked limited ID..."
251 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
252         -D 'cn=Unchecked Limited User,ou=People,o=University of Michigan,c=US' \
253         '(uid=uncheckedlimited)' > $SEARCHOUT 2>&1
254 RC=$?
255 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
256 case $RC in
257         0)
258                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
259         ;;
260         11)
261                 echo "...bumped into server-side unchecked limit"
262         ;;
263         *)
264                 echo "ldapsearch failed ($RC)!"
265                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
266                 exit $RC
267         ;;
268 esac
269
270 echo "Testing higher than unchecked limit requested for unchecked limited ID..."
271 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
272         -D 'cn=Unchecked Limited User,ou=People,o=University of Michigan,c=US' \
273         '(objectClass=*)' > $SEARCHOUT 2>&1
274 RC=$?
275 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
276 case $RC in
277         0)
278                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
279         ;;
280         11)
281                 echo "...bumped into server-side unchecked limit"
282         ;;
283         *)
284                 echo "ldapsearch failed ($RC)!"
285                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
286                 exit $RC
287         ;;
288 esac
289
290 echo "Testing higher than unchecked limit requested for unchecked limited group..."
291 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
292         -D 'cn=Unchecked Limited User 2,ou=People,o=University of Michigan,c=US' \
293         '(objectClass=*)' > $SEARCHOUT 2>&1
294 RC=$?
295 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
296 case $RC in
297         0)
298                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
299         ;;
300         11)
301                 echo "...bumped into server-side unchecked limit"
302         ;;
303         *)
304                 echo "ldapsearch failed ($RC)!"
305                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
306                 exit $RC
307         ;;
308 esac
309
310 echo "Testing higher than unchecked limit requested for unchecked limited regex..."
311 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
312         -D 'cn=Foo User,ou=People,o=University of Michigan,c=US' \
313         '(objectClass=*)' > $SEARCHOUT 2>&1
314 RC=$?
315 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
316 case $RC in
317         0)
318                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
319         ;;
320         11)
321                 echo "...bumped into server-side unchecked limit"
322         ;;
323         *)
324                 echo "ldapsearch failed ($RC)!"
325                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
326                 exit $RC
327         ;;
328 esac
329
330 echo "Testing higher than unchecked limit requested for unchecked limited onelevel..."
331 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
332         -D 'cn=Bar User,ou=People,o=University of Michigan,c=US' \
333         '(objectClass=*)' > $SEARCHOUT 2>&1
334 RC=$?
335 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
336 case $RC in
337         0)
338                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
339         ;;
340         11)
341                 echo "...bumped into server-side unchecked limit"
342         ;;
343         *)
344                 echo "ldapsearch failed ($RC)!"
345                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
346                 exit $RC
347         ;;
348 esac
349
350 echo "Testing higher than unchecked limit requested for unchecked limited children..."
351 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
352         -D 'cn=Unchecked Limited Users,ou=Groups,o=University of Michigan,c=US' \
353         '(objectClass=*)' > $SEARCHOUT 2>&1
354 RC=$?
355 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
356 case $RC in
357         0)
358                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
359         ;;
360         11)
361                 echo "...bumped into server-side unchecked limit"
362         ;;
363         *)
364                 echo "ldapsearch failed ($RC)!"
365                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
366                 exit $RC
367         ;;
368 esac
369
370 echo "Testing higher than unchecked limit requested for unchecked limited subtree..."
371 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
372         -D 'cn=Unchecked Limited User 3,ou=Admin,o=University of Michigan,c=US' \
373         '(objectClass=*)' > $SEARCHOUT 2>&1
374 RC=$?
375 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
376 case $RC in
377         0)
378                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
379         ;;
380         11)
381                 echo "...bumped into server-side unchecked limit"
382         ;;
383         *)
384                 echo "ldapsearch failed ($RC)!"
385                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
386                 exit $RC
387         ;;
388 esac
389
390 echo "Testing higher than unchecked limit requested for unchecked limited users..."
391 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 -w secret \
392         -D 'cn=Special User,o=University of Michigan,c=US' \
393         '(objectClass=*)' > $SEARCHOUT 2>&1
394 RC=$?
395 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
396 case $RC in
397         0)
398                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
399         ;;
400         11)
401                 echo "...bumped into server-side unchecked limit"
402         ;;
403         *)
404                 echo "ldapsearch failed ($RC)!"
405                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
406                 exit $RC
407         ;;
408 esac
409
410 echo "Testing higher than unchecked limit requested for unchecked limited anonymous..."
411 $LDAPRSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
412         '(objectClass=*)' > $SEARCHOUT 2>&1
413 RC=$?
414 COUNT=`cat $SEARCHOUT | grep '^# numEntries:' | sed 's;.*\([0-9]\+\)$;\1;'`
415 case $RC in
416         0)
417                 echo "...success; didn't bump into server-side unchecked limit (got $COUNT entries)"
418         ;;
419         11)
420                 echo "...bumped into server-side unchecked limit"
421         ;;
422         *)
423                 echo "ldapsearch failed ($RC)!"
424                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
425                 exit $RC
426         ;;
427 esac
428
429 test $KILLSERVERS != no && kill -HUP $KILLPIDS
430
431 echo ">>>>> Test succeeded"
432 exit 0