Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / sql-test000-read
blobd0ef275bf2d8a5ec55e6807049b345a15ced0d7f
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/sql-test000-read,v 1.11.2.4 2008/02/11 23:26:50 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 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.
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>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $BACKSQL = "sqlno" ; then
20 echo "SQL backend not available, test skipped"
21 exit 0
22 fi
24 if test $RDBMS = "rdbmsno" ; then
25 echo "SQL test not requested, test skipped"
26 exit 0
29 mkdir -p $TESTDIR
31 echo "Starting slapd on TCP/IP port $PORT1..."
32 . $CONFFILTER $BACKEND $MONITORDB < $SQLCONF > $CONF1
33 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
34 PID=$!
35 if test $WAIT != 0 ; then
36 echo PID $PID
37 read foo
39 KILLPIDS="$PID"
41 echo "Testing SQL backend read operations..."
42 for i in 0 1 2 3 4 5; do
43 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
44 'objectclass=*' > /dev/null 2>&1
45 RC=$?
46 if test $RC = 0 ; then
47 break
49 echo "Waiting 5 seconds for slapd to start..."
50 sleep 5
51 done
53 if test $RC != 0 ; then
54 echo "ldapsearch failed ($RC)!"
55 test $KILLSERVERS != no && kill -HUP $KILLPIDS
56 exit $RC
59 BASEDN="dc=example,dc=com"
60 BINDDN="cn=Mitya Kovalev,${BASEDN}"
61 BINDPW="mit"
62 echo -n "Testing correct bind... "
63 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
64 RC=$?
65 if test $RC != 0 ; then
66 echo "ldapwhoami failed ($RC)!"
67 test $KILLSERVERS != no && kill -HUP $KILLPIDS
68 exit $RC
71 echo -n "Testing incorrect bind (should fail)... "
72 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w "XXX"
73 RC=$?
74 if test $RC = 0 ; then
75 echo "ldapwhoami should have failed ($RC)!"
76 test $KILLSERVERS != no && kill -HUP $KILLPIDS
77 exit 1
80 echo "Testing baseobject search..."
81 echo "# Testing baseobject search..." >> $SEARCHOUT
82 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -s base -S "" \
83 >> $SEARCHOUT 2>&1
85 RC=$?
86 if test $RC != 0 ; then
87 echo "ldapsearch failed ($RC)!"
88 test $KILLSERVERS != no && kill -HUP $KILLPIDS
89 exit $RC
92 echo "Testing onelevel search..."
93 echo "# Testing onelevel search..." >> $SEARCHOUT
94 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -s one -S "" \
95 >> $SEARCHOUT 2>&1
97 RC=$?
98 if test $RC != 0 ; then
99 echo "ldapsearch failed ($RC)!"
100 test $KILLSERVERS != no && kill -HUP $KILLPIDS
101 exit $RC
104 echo "Testing subtree search..."
105 echo "# Testing subtree search..." >> $SEARCHOUT
106 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
107 >> $SEARCHOUT 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
116 echo "Testing subtree search with manageDSAit..."
117 echo "# Testing subtree search with manageDSAit..." >> $SEARCHOUT
118 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M -S "" '*' ref \
119 >> $SEARCHOUT 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
128 echo "Testing invalid filter..."
129 echo "# Testing invalid filter..." >> $SEARCHOUT
130 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(foo=)" \
131 >> $SEARCHOUT 2>&1
133 RC=$?
134 if test $RC != 0 ; then
135 echo "ldapsearch failed ($RC)!"
136 test $KILLSERVERS != no && kill -HUP $KILLPIDS
137 exit $RC
140 echo "Testing exact search..."
141 echo "# Testing exact search..." >> $SEARCHOUT
142 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(sn=Kovalev)" \
143 >> $SEARCHOUT 2>&1
145 RC=$?
146 if test $RC != 0 ; then
147 echo "ldapsearch failed ($RC)!"
148 test $KILLSERVERS != no && kill -HUP $KILLPIDS
149 exit $RC
152 echo "Testing substrings initial search..."
153 echo "# Testing substrings initial search..." >> $SEARCHOUT
154 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=m*)" \
155 >> $SEARCHOUT 2>&1
157 RC=$?
158 if test $RC != 0 ; then
159 echo "ldapsearch failed ($RC)!"
160 test $KILLSERVERS != no && kill -HUP $KILLPIDS
161 exit $RC
164 echo "Testing substrings any search..."
165 echo "# Testing substrings any search..." >> $SEARCHOUT
166 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=*m*)" \
167 >> $SEARCHOUT 2>&1
169 RC=$?
170 if test $RC != 0 ; then
171 echo "ldapsearch failed ($RC)!"
172 test $KILLSERVERS != no && kill -HUP $KILLPIDS
173 exit $RC
176 echo "Testing substrings final search..."
177 echo "# Testing substrings final search..." >> $SEARCHOUT
178 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=*v)" \
179 >> $SEARCHOUT 2>&1
181 RC=$?
182 if test $RC != 0 ; then
183 echo "ldapsearch failed ($RC)!"
184 test $KILLSERVERS != no && kill -HUP $KILLPIDS
185 exit $RC
188 echo "Testing approx search..."
189 echo "# Testing approx search..." >> $SEARCHOUT
190 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(sn~=kovalev)" \
191 >> $SEARCHOUT 2>&1
193 RC=$?
194 if test $RC != 0 ; then
195 echo "ldapsearch failed ($RC)!"
196 test $KILLSERVERS != no && kill -HUP $KILLPIDS
197 exit $RC
200 echo "Testing extensible filter search..."
201 echo "# Testing extensible filter search..." >> $SEARCHOUT
202 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
203 "(sn:caseExactMatch:=Kovalev)" >> $SEARCHOUT 2>&1
205 RC=$?
206 if test $RC != 0 ; then
207 echo "ldapsearch failed ($RC)!"
208 test $KILLSERVERS != no && kill -HUP $KILLPIDS
209 exit $RC
212 echo "Testing search for telephoneNumber..."
213 echo "# Testing search for telephoneNumber..." >> $SEARCHOUT
214 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
215 "(telephoneNumber=3322334)" >> $SEARCHOUT 2>&1
217 RC=$?
218 if test $RC != 0 ; then
219 echo "ldapsearch failed ($RC)!"
220 test $KILLSERVERS != no && kill -HUP $KILLPIDS
221 exit $RC
224 echo "Testing AND search..."
225 echo "# Testing AND search..." >> $SEARCHOUT
226 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
227 "(&(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
229 RC=$?
230 if test $RC != 0 ; then
231 echo "ldapsearch failed ($RC)!"
232 test $KILLSERVERS != no && kill -HUP $KILLPIDS
233 exit $RC
236 echo "Testing AND search on objectClass..."
237 echo "# Testing AND search on objectClass..." >> $SEARCHOUT
238 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
239 "(&(objectClass=organization)(objectClass=dcObject))" >> $SEARCHOUT 2>&1
241 RC=$?
242 if test $RC != 0 ; then
243 echo "ldapsearch failed ($RC)!"
244 test $KILLSERVERS != no && kill -HUP $KILLPIDS
245 exit $RC
248 echo "Testing OR search..."
249 echo "# Testing OR search..." >> $SEARCHOUT
250 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
251 "(|(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
253 RC=$?
254 if test $RC != 0 ; then
255 echo "ldapsearch failed ($RC)!"
256 test $KILLSERVERS != no && kill -HUP $KILLPIDS
257 exit $RC
260 echo "Testing OR search on objectClass..."
261 echo "# Testing OR search on objectClass..." >> $SEARCHOUT
262 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
263 "(|(objectClass=document)(objectClass=organization))" \
264 >> $SEARCHOUT 2>&1
266 RC=$?
267 if test $RC != 0 ; then
268 echo "ldapsearch failed ($RC)!"
269 test $KILLSERVERS != no && kill -HUP $KILLPIDS
270 exit $RC
273 echo "Testing NOT search..."
274 echo "# Testing NOT search..." >> $SEARCHOUT
275 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
276 '(!(sn=kovalev))' >> $SEARCHOUT 2>&1
278 RC=$?
279 if test $RC != 0 ; then
280 echo "ldapsearch failed ($RC)!"
281 test $KILLSERVERS != no && kill -HUP $KILLPIDS
282 exit $RC
285 echo "Testing NOT search on objectClass..."
286 echo "# Testing NOT search on objectClass..." >> $SEARCHOUT
287 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
288 '(!(objectClass=inetOrgPerson))' >> $SEARCHOUT 2>&1
290 RC=$?
291 if test $RC != 0 ; then
292 echo "ldapsearch failed ($RC)!"
293 test $KILLSERVERS != no && kill -HUP $KILLPIDS
294 exit $RC
297 echo "Testing NOT search on \"auxiliary\" objectClass..."
298 echo "# Testing NOT search on \"auxiliary\" objectClass..." >> $SEARCHOUT
299 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
300 '(!(objectClass=dcObject))' >> $SEARCHOUT 2>&1
302 RC=$?
303 if test $RC != 0 ; then
304 echo "ldapsearch failed ($RC)!"
305 test $KILLSERVERS != no && kill -HUP $KILLPIDS
306 exit $RC
309 #### Needs work...
310 echo "Testing NOT presence search... (disabled)"
311 ###echo "# Testing NOT presence search..." >> $SEARCHOUT
312 ###$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
313 ### '(!(sn=*))' >> $SEARCHOUT 2>&1
315 ###RC=$?
316 ###if test $RC != 0 ; then
317 ### echo "ldapsearch failed ($RC)!"
318 ### test $KILLSERVERS != no && kill -HUP $KILLPIDS
319 ### exit $RC
320 ###fi
322 echo "Testing attribute inheritance in filter..."
323 echo "# Testing attribute inheritance in filter..." >> $SEARCHOUT
324 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
325 "(name=example)" >> $SEARCHOUT 2>&1
327 RC=$?
328 if test $RC != 0 ; then
329 echo "ldapsearch failed ($RC)!"
330 test $KILLSERVERS != no && kill -HUP $KILLPIDS
331 exit $RC
334 # ITS#4604
335 echo "Testing undefined attribute in filter..."
336 echo "# Testing undefined attribute in filter..." >> $SEARCHOUT
337 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
338 "(|(o=example)(foobar=x))" >> $SEARCHOUT 2>&1
340 RC=$?
341 if test $RC != 0 ; then
342 echo "ldapsearch failed ($RC)!"
343 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344 exit $RC
347 echo "Testing objectClass inheritance in filter..."
348 echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT
349 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
350 "(objectClass=person)" >> $SEARCHOUT 2>&1
352 RC=$?
353 if test $RC != 0 ; then
354 echo "ldapsearch failed ($RC)!"
355 test $KILLSERVERS != no && kill -HUP $KILLPIDS
356 exit $RC
359 echo "Testing \"auxiliary\" objectClass in filter..."
360 echo "# Testing \"auxiliary\" objectClass in filter..." >> $SEARCHOUT
361 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
362 "(objectClass=dcObject)" >> $SEARCHOUT 2>&1
364 RC=$?
365 if test $RC != 0 ; then
366 echo "ldapsearch failed ($RC)!"
367 test $KILLSERVERS != no && kill -HUP $KILLPIDS
368 exit $RC
371 echo "Testing hasSubordinates in filter..."
372 echo "# Testing hasSubordinates in filter..." >> $SEARCHOUT
373 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
374 "(hasSubordinates=TRUE)" >> $SEARCHOUT 2>&1
376 RC=$?
377 if test $RC != 0 ; then
378 echo "ldapsearch failed ($RC)!"
379 test $KILLSERVERS != no && kill -HUP $KILLPIDS
380 exit $RC
383 echo "Testing entryUUID in filter..."
384 echo "# Testing entryUUID in filter..." >> $SEARCHOUT
385 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
386 "(entryUUID=00000001-0000-0001-0000-000000000000)" >> $SEARCHOUT 2>&1
388 RC=$?
389 if test $RC != 0 ; then
390 echo "ldapsearch failed ($RC)!"
391 test $KILLSERVERS != no && kill -HUP $KILLPIDS
392 exit $RC
395 echo "Testing attribute inheritance in requested attributes..."
396 echo "# Testing attribute inheritance in requested attributes..." >> $SEARCHOUT
397 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
398 "(sn=kovalev)" name >> $SEARCHOUT 2>&1
400 RC=$?
401 if test $RC != 0 ; then
402 echo "ldapsearch failed ($RC)!"
403 test $KILLSERVERS != no && kill -HUP $KILLPIDS
404 exit $RC
407 echo "Testing objectClass in requested attributes..."
408 echo "# Testing objectClass in requested attributes..." >> $SEARCHOUT
409 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
410 objectClass >> $SEARCHOUT 2>&1
412 RC=$?
413 if test $RC != 0 ; then
414 echo "ldapsearch failed ($RC)!"
415 test $KILLSERVERS != no && kill -HUP $KILLPIDS
416 exit $RC
419 echo "Testing operational attributes in request..."
420 echo "# Testing operational attributes in request..." >> $SEARCHOUT
421 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" \
422 '+' 2>&1 > $SEARCHFLT
424 RC=$?
425 if test $RC != 0 ; then
426 echo "ldapsearch failed ($RC)!"
427 test $KILLSERVERS != no && kill -HUP $KILLPIDS
428 exit $RC
431 grep -v '^entryCSN:' $SEARCHFLT >> $SEARCHOUT
433 SIZELIMIT=4
434 echo "Testing size limit..."
435 $LDAPRSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
436 -z $SIZELIMIT -S "" '(objectClass=*)' >$SEARCHFLT 2>&1
437 RC=$?
438 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHFLT`
439 case $RC in
441 if test x"$COUNT" != x ; then
442 if test "$COUNT" -gt "$SIZELIMIT" ; then
443 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
444 test $KILLSERVERS != no && kill -HUP $KILLPIDS
445 exit 1
447 echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)"
448 else
449 echo "...error: did not expect ldapsearch success ($RC)!"
450 test $KILLSERVERS != no && kill -HUP $KILLPIDS
451 exit 1
455 if test x"$COUNT" != x ; then
456 if test "$COUNT" = "$SIZELIMIT" ; then
457 echo "...bumped into requested size limit ($SIZELIMIT)"
458 else
459 echo "...error: got $COUNT entries with a requested sizelimit of $SIZELIMIT"
460 test $KILLSERVERS != no && kill -HUP $KILLPIDS
461 exit $RC
463 else
464 echo "...error: bumped into server-side size limit, but got no entries!"
465 test $KILLSERVERS != no && kill -HUP $KILLPIDS
466 exit $RC
470 echo "ldapsearch failed ($RC)!"
471 test $KILLSERVERS != no && kill -HUP $KILLPIDS
472 exit $RC
474 esac
476 echo -n "Testing compare (should be TRUE)... "
477 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
478 "sn:kovalev" >> $TESTOUT 2>&1
480 RC=$?
481 case $RC in
483 echo "TRUE"
485 5) echo "FALSE!"
486 test $KILLSERVERS != no && kill -HUP $KILLPIDS
487 exit $RC
489 *) echo "failed ($RC)!"
490 test $KILLSERVERS != no && kill -HUP $KILLPIDS
491 exit 1
493 esac
495 echo -n "Testing compare (should be FALSE)... "
496 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
497 "cn:foobar" >> $TESTOUT 2>&1
499 RC=$?
500 case $RC in
502 echo "TRUE!"
503 test $KILLSERVERS != no && kill -HUP $KILLPIDS
504 exit $RC
506 5) echo "FALSE"
508 *) echo "failed ($RC)!"
509 test $KILLSERVERS != no && kill -HUP $KILLPIDS
510 exit 1
512 esac
514 echo -n "Testing compare (should be UNDEFINED)... "
515 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
516 "o:example" >> $TESTOUT 2>&1
518 RC=$?
519 case $RC in
521 echo "TRUE!"
522 test $KILLSERVERS != no && kill -HUP $KILLPIDS
523 exit $RC
525 5) echo "FALSE!"
526 test $KILLSERVERS != no && kill -HUP $KILLPIDS
527 exit $RC
529 *) echo "failed ($RC)"
531 esac
533 echo -n "Testing compare on hasSubordinates (should be TRUE)... "
534 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BASEDN" \
535 "hasSubordinates:TRUE" >> $TESTOUT 2>&1
537 RC=$?
538 case $RC in
540 echo "TRUE"
542 5) echo "FALSE!"
543 test $KILLSERVERS != no && kill -HUP $KILLPIDS
544 exit $RC
546 *) echo "failed ($RC)!"
547 test $KILLSERVERS != no && kill -HUP $KILLPIDS
548 exit 1
550 esac
552 echo "Filtering ldapsearch results..."
553 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
554 echo "Filtering original ldif..."
555 . $LDIFFILTER < $SQLREAD > $LDIFFLT
556 echo "Comparing filter output..."
557 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
559 if test $? != 0 ; then
560 echo "comparison failed - SQL search didn't succeed"
561 test $KILLSERVERS != no && kill -HUP $KILLPIDS
562 exit 1
565 test $KILLSERVERS != no && kill -HUP $KILLPIDS
567 echo ">>>>> Test succeeded"
568 exit 0