]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test000-read
Happy new year! (belated)
[openldap] / tests / scripts / sql-test000-read
1 #! /bin/sh
2 # $OpenLDAP$
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.
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 if test $BACKSQL = "sqlno" ; then 
20         echo "SQL backend not available, test skipped"
21         exit 0
22 fi 
23
24 if test $RDBMS = "rdbmsno" ; then
25         echo "SQL test not requested, test skipped"
26         exit 0
27 fi
28
29 mkdir -p $TESTDIR
30
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
38 fi
39 KILLPIDS="$PID"
40
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
48         fi
49         echo "Waiting 5 seconds for slapd to start..."
50         sleep 5
51 done
52
53 if test $RC != 0 ; then
54         echo "ldapsearch failed ($RC)!"
55         test $KILLSERVERS != no && kill -HUP $KILLPIDS
56         exit $RC
57 fi
58
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
69 fi
70
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
78 fi
79
80 echo "Testing baseobject search..."
81 echo "# Testing baseobject search..." >> $SEARCHOUT
82 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -s base >> $SEARCHOUT 2>&1
83
84 RC=$?
85 if test $RC != 0 ; then
86         echo "ldapsearch failed ($RC)!"
87         test $KILLSERVERS != no && kill -HUP $KILLPIDS
88         exit $RC
89 fi
90
91 echo "Testing onelevel search..."
92 echo "# Testing onelevel search..." >> $SEARCHOUT
93 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -s one >> $SEARCHOUT 2>&1
94
95 RC=$?
96 if test $RC != 0 ; then
97         echo "ldapsearch failed ($RC)!"
98         test $KILLSERVERS != no && kill -HUP $KILLPIDS
99         exit $RC
100 fi
101
102 echo "Testing subtree search..."
103 echo "# Testing subtree search..." >> $SEARCHOUT
104 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
105
106 RC=$?
107 if test $RC != 0 ; then
108         echo "ldapsearch failed ($RC)!"
109         test $KILLSERVERS != no && kill -HUP $KILLPIDS
110         exit $RC
111 fi
112
113 echo "Testing subtree search with manageDSAit..."
114 echo "# Testing subtree search with manageDSAit..." >> $SEARCHOUT
115 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M '*' ref >> $SEARCHOUT 2>&1
116
117 RC=$?
118 if test $RC != 0 ; then
119         echo "ldapsearch failed ($RC)!"
120         test $KILLSERVERS != no && kill -HUP $KILLPIDS
121         exit $RC
122 fi
123
124 echo "Testing invalid filter..."
125 echo "# Testing invalid filter..." >> $SEARCHOUT
126 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
127          "(foo=)" >> $SEARCHOUT 2>&1
128
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 "Testing exact search..."
137 echo "# Testing exact search..." >> $SEARCHOUT
138 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
139          "(sn=Kovalev)" >> $SEARCHOUT 2>&1
140
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 "Testing substrings initial search..."
149 echo "# Testing substrings initial search..." >> $SEARCHOUT
150 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
151          "(cn=m*)" >> $SEARCHOUT 2>&1
152
153 RC=$?
154 if test $RC != 0 ; then
155         echo "ldapsearch failed ($RC)!"
156         test $KILLSERVERS != no && kill -HUP $KILLPIDS
157         exit $RC
158 fi
159
160 echo "Testing substrings any search..."
161 echo "# Testing substrings any search..." >> $SEARCHOUT
162 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
163          "(cn=*m*)" >> $SEARCHOUT 2>&1
164
165 RC=$?
166 if test $RC != 0 ; then
167         echo "ldapsearch failed ($RC)!"
168         test $KILLSERVERS != no && kill -HUP $KILLPIDS
169         exit $RC
170 fi
171
172 echo "Testing substrings final search..."
173 echo "# Testing substrings final search..." >> $SEARCHOUT
174 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
175          "(cn=*v)" >> $SEARCHOUT 2>&1
176
177 RC=$?
178 if test $RC != 0 ; then
179         echo "ldapsearch failed ($RC)!"
180         test $KILLSERVERS != no && kill -HUP $KILLPIDS
181         exit $RC
182 fi
183
184 echo "Testing approx search..."
185 echo "# Testing approx search..." >> $SEARCHOUT
186 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
187          "(sn~=kovalev)" >> $SEARCHOUT 2>&1
188
189 RC=$?
190 if test $RC != 0 ; then
191         echo "ldapsearch failed ($RC)!"
192         test $KILLSERVERS != no && kill -HUP $KILLPIDS
193         exit $RC
194 fi
195
196 echo "Testing extensible filter search..."
197 echo "# Testing extensible filter search..." >> $SEARCHOUT
198 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
199          "(sn:caseExactMatch:=Kovalev)" >> $SEARCHOUT 2>&1
200
201 RC=$?
202 if test $RC != 0 ; then
203         echo "ldapsearch failed ($RC)!"
204         test $KILLSERVERS != no && kill -HUP $KILLPIDS
205         exit $RC
206 fi
207
208 echo "Testing search for telephoneNumber..."
209 echo "# Testing search for telephoneNumber..." >> $SEARCHOUT
210 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
211          "(telephoneNumber=3322334)" >> $SEARCHOUT 2>&1
212
213 RC=$?
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 echo "Testing AND search..."
221 echo "# Testing AND search..." >> $SEARCHOUT
222 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
223          "(&(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
224
225 RC=$?
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 echo "Testing AND search on objectClass..."
233 echo "# Testing AND search on objectClass..." >> $SEARCHOUT
234 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
235          "(&(objectClass=organization)(objectClass=dcObject))" >> $SEARCHOUT 2>&1
236
237 RC=$?
238 if test $RC != 0 ; then
239         echo "ldapsearch failed ($RC)!"
240         test $KILLSERVERS != no && kill -HUP $KILLPIDS
241         exit $RC
242 fi
243
244 echo "Testing OR search..."
245 echo "# Testing OR search..." >> $SEARCHOUT
246 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
247          "(|(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
248
249 RC=$?
250 if test $RC != 0 ; then
251         echo "ldapsearch failed ($RC)!"
252         test $KILLSERVERS != no && kill -HUP $KILLPIDS
253         exit $RC
254 fi
255
256 echo "Testing OR search on objectClass..."
257 echo "# Testing OR search on objectClass..." >> $SEARCHOUT
258 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
259          "(|(objectClass=document)(objectClass=organization))" >> $SEARCHOUT 2>&1
260
261 RC=$?
262 if test $RC != 0 ; then
263         echo "ldapsearch failed ($RC)!"
264         test $KILLSERVERS != no && kill -HUP $KILLPIDS
265         exit $RC
266 fi
267
268 echo "Testing NOT search..."
269 echo "# Testing NOT search..." >> $SEARCHOUT
270 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
271          '(!(sn=kovalev))' >> $SEARCHOUT 2>&1
272
273 RC=$?
274 if test $RC != 0 ; then
275         echo "ldapsearch failed ($RC)!"
276         test $KILLSERVERS != no && kill -HUP $KILLPIDS
277         exit $RC
278 fi
279
280 echo "Testing NOT search on objectClass..."
281 echo "# Testing NOT search on objectClass..." >> $SEARCHOUT
282 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
283          '(!(objectClass=inetOrgPerson))' >> $SEARCHOUT 2>&1
284
285 RC=$?
286 if test $RC != 0 ; then
287         echo "ldapsearch failed ($RC)!"
288         test $KILLSERVERS != no && kill -HUP $KILLPIDS
289         exit $RC
290 fi
291
292 echo "Testing NOT search on \"auxiliary\" objectClass..."
293 echo "# Testing NOT search on \"auxiliary\" objectClass..." >> $SEARCHOUT
294 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
295          '(!(objectClass=dcObject))' >> $SEARCHOUT 2>&1
296
297 RC=$?
298 if test $RC != 0 ; then
299         echo "ldapsearch failed ($RC)!"
300         test $KILLSERVERS != no && kill -HUP $KILLPIDS
301         exit $RC
302 fi
303
304 #### Needs work...
305 echo "Testing NOT presence search... (disabled)"
306 ###echo "# Testing NOT presence search..." >> $SEARCHOUT
307 ###$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
308 ###      '(!(sn=*))' >> $SEARCHOUT 2>&1
309 ###
310 ###RC=$?
311 ###if test $RC != 0 ; then
312 ###     echo "ldapsearch failed ($RC)!"
313 ###     test $KILLSERVERS != no && kill -HUP $KILLPIDS
314 ###     exit $RC
315 ###fi
316
317 echo "Testing attribute inheritance in filter..."
318 echo "# Testing attribute inheritance in filter..." >> $SEARCHOUT
319 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
320          "(name=example)" >> $SEARCHOUT 2>&1
321
322 RC=$?
323 if test $RC != 0 ; then
324         echo "ldapsearch failed ($RC)!"
325         test $KILLSERVERS != no && kill -HUP $KILLPIDS
326         exit $RC
327 fi
328
329 # ITS#4604
330 echo "Testing undefined attribute in filter..."
331 echo "# Testing undefined attribute in filter..." >> $SEARCHOUT
332 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
333          "(|(o=example)(foobar=x))" >> $SEARCHOUT 2>&1
334
335 RC=$?
336 if test $RC != 0 ; then
337         echo "ldapsearch failed ($RC)!"
338         test $KILLSERVERS != no && kill -HUP $KILLPIDS
339         exit $RC
340 fi
341
342 echo "Testing objectClass inheritance in filter..."
343 echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT
344 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
345          "(objectClass=person)" >> $SEARCHOUT 2>&1
346
347 RC=$?
348 if test $RC != 0 ; then
349         echo "ldapsearch failed ($RC)!"
350         test $KILLSERVERS != no && kill -HUP $KILLPIDS
351         exit $RC
352 fi
353
354 echo "Testing \"auxiliary\" objectClass in filter..."
355 echo "# Testing \"auxiliary\" objectClass in filter..." >> $SEARCHOUT
356 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
357          "(objectClass=dcObject)" >> $SEARCHOUT 2>&1
358
359 RC=$?
360 if test $RC != 0 ; then
361         echo "ldapsearch failed ($RC)!"
362         test $KILLSERVERS != no && kill -HUP $KILLPIDS
363         exit $RC
364 fi
365
366 echo "Testing hasSubordinates in filter..."
367 echo "# Testing hasSubordinates in filter..." >> $SEARCHOUT
368 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
369          "(hasSubordinates=TRUE)" >> $SEARCHOUT 2>&1
370
371 RC=$?
372 if test $RC != 0 ; then
373         echo "ldapsearch failed ($RC)!"
374         test $KILLSERVERS != no && kill -HUP $KILLPIDS
375         exit $RC
376 fi
377
378 echo "Testing entryUUID in filter..."
379 echo "# Testing entryUUID in filter..." >> $SEARCHOUT
380 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
381          "(entryUUID=00000001-0000-0001-0000-000000000000)" >> $SEARCHOUT 2>&1
382
383 RC=$?
384 if test $RC != 0 ; then
385         echo "ldapsearch failed ($RC)!"
386         test $KILLSERVERS != no && kill -HUP $KILLPIDS
387         exit $RC
388 fi
389
390 echo "Testing attribute inheritance in requested attributes..."
391 echo "# Testing attribute inheritance in requested attributes..." >> $SEARCHOUT
392 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
393          "(sn=kovalev)" name >> $SEARCHOUT 2>&1
394
395 RC=$?
396 if test $RC != 0 ; then
397         echo "ldapsearch failed ($RC)!"
398         test $KILLSERVERS != no && kill -HUP $KILLPIDS
399         exit $RC
400 fi
401
402 echo "Testing objectClass in requested attributes..."
403 echo "# Testing objectClass in requested attributes..." >> $SEARCHOUT
404 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
405          objectClass >> $SEARCHOUT 2>&1
406
407 RC=$?
408 if test $RC != 0 ; then
409         echo "ldapsearch failed ($RC)!"
410         test $KILLSERVERS != no && kill -HUP $KILLPIDS
411         exit $RC
412 fi
413
414 echo "Testing operational attributes in request..."
415 echo "# Testing operational attributes in request..." >> $SEARCHOUT
416 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
417          '+' 2>&1 > $SEARCHFLT
418
419 RC=$?
420 if test $RC != 0 ; then
421         echo "ldapsearch failed ($RC)!"
422         test $KILLSERVERS != no && kill -HUP $KILLPIDS
423         exit $RC
424 fi
425
426 grep -v '^entryCSN:' $SEARCHFLT >> $SEARCHOUT 
427
428 SIZELIMIT=4
429 echo "Testing size limit..."
430 $LDAPRSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
431         -z $SIZELIMIT -S "" '(objectClass=*)' >$SEARCHFLT 2>&1
432 RC=$?
433 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHFLT`
434 case $RC in
435         0)
436                 if test x"$COUNT" != x ; then
437                         if test "$COUNT" -gt "$SIZELIMIT" ; then
438                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
439                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
440                                 exit 1
441                         fi
442                         echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)"
443                 else
444                         echo "...error: did not expect ldapsearch success ($RC)!"
445                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
446                         exit 1
447                 fi
448         ;;
449         4)
450                 if test x"$COUNT" != x ; then
451                         if test "$COUNT" = "$SIZELIMIT" ; then
452                                 echo "...bumped into requested size limit ($SIZELIMIT)"
453                         else
454                                 echo "...error: got $COUNT entries with a requested sizelimit of $SIZELIMIT"
455                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
456                                 exit $RC
457                         fi
458                 else
459                         echo "...error: bumped into server-side size limit, but got no entries!"
460                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
461                         exit $RC
462                 fi
463         ;;
464         *)
465                 echo "ldapsearch failed ($RC)!"
466                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
467                 exit $RC
468         ;;
469 esac
470
471 echo -n "Testing compare (should be TRUE)... "
472 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
473          "sn:kovalev" >> $TESTOUT 2>&1
474
475 RC=$?
476 case $RC in
477 6)
478         echo "TRUE"
479         ;;
480 5)      echo "FALSE!"
481         test $KILLSERVERS != no && kill -HUP $KILLPIDS
482         exit $RC
483         ;;
484 *)      echo "failed ($RC)!"
485         test $KILLSERVERS != no && kill -HUP $KILLPIDS
486         exit 1
487         ;;
488 esac
489
490 echo -n "Testing compare (should be FALSE)... "
491 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
492          "cn:foobar" >> $TESTOUT 2>&1
493
494 RC=$?
495 case $RC in
496 6)
497         echo "TRUE!"
498         test $KILLSERVERS != no && kill -HUP $KILLPIDS
499         exit $RC
500         ;;
501 5)      echo "FALSE"
502         ;;
503 *)      echo "failed ($RC)!"
504         test $KILLSERVERS != no && kill -HUP $KILLPIDS
505         exit 1
506         ;;
507 esac
508
509 echo -n "Testing compare (should be UNDEFINED)... "
510 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
511          "o:example" >> $TESTOUT 2>&1
512
513 RC=$?
514 case $RC in
515 6)
516         echo "TRUE!"
517         test $KILLSERVERS != no && kill -HUP $KILLPIDS
518         exit $RC
519         ;;
520 5)      echo "FALSE!"
521         test $KILLSERVERS != no && kill -HUP $KILLPIDS
522         exit $RC
523         ;;
524 *)      echo "failed ($RC)"
525         ;;
526 esac
527
528 echo -n "Testing compare on hasSubordinates (should be TRUE)... "
529 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BASEDN" \
530          "hasSubordinates:TRUE" >> $TESTOUT 2>&1
531
532 RC=$?
533 case $RC in
534 6)
535         echo "TRUE"
536         ;;
537 5)      echo "FALSE!"
538         test $KILLSERVERS != no && kill -HUP $KILLPIDS
539         exit $RC
540         ;;
541 *)      echo "failed ($RC)!"
542         test $KILLSERVERS != no && kill -HUP $KILLPIDS
543         exit 1
544         ;;
545 esac
546
547 echo "Filtering ldapsearch results..."
548 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
549 echo "Filtering original ldif..."
550 . $LDIFFILTER < $SQLREAD > $LDIFFLT
551 echo "Comparing filter output..."
552 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
553
554 if test $? != 0 ; then
555         echo "comparison failed - SQL search didn't succeed"
556         test $KILLSERVERS != no && kill -HUP $KILLPIDS
557         exit 1
558 fi
559
560 test $KILLSERVERS != no && kill -HUP $KILLPIDS
561
562 echo ">>>>> Test succeeded"
563 exit 0