]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test000-read
Happy new year!
[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-2006 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 echo "Testing objectClass inheritance in filter..."
330 echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT
331 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
332          "(objectClass=person)" >> $SEARCHOUT 2>&1
333
334 RC=$?
335 if test $RC != 0 ; then
336         echo "ldapsearch failed ($RC)!"
337         test $KILLSERVERS != no && kill -HUP $KILLPIDS
338         exit $RC
339 fi
340
341 echo "Testing \"auxiliary\" objectClass in filter..."
342 echo "# Testing \"auxiliary\" objectClass in filter..." >> $SEARCHOUT
343 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
344          "(objectClass=dcObject)" >> $SEARCHOUT 2>&1
345
346 RC=$?
347 if test $RC != 0 ; then
348         echo "ldapsearch failed ($RC)!"
349         test $KILLSERVERS != no && kill -HUP $KILLPIDS
350         exit $RC
351 fi
352
353 echo "Testing hasSubordinates in filter..."
354 echo "# Testing hasSubordinates in filter..." >> $SEARCHOUT
355 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
356          "(hasSubordinates=TRUE)" >> $SEARCHOUT 2>&1
357
358 RC=$?
359 if test $RC != 0 ; then
360         echo "ldapsearch failed ($RC)!"
361         test $KILLSERVERS != no && kill -HUP $KILLPIDS
362         exit $RC
363 fi
364
365 echo "Testing entryUUID in filter..."
366 echo "# Testing entryUUID in filter..." >> $SEARCHOUT
367 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
368          "(entryUUID=00000001-0000-0001-0000-000000000000)" >> $SEARCHOUT 2>&1
369
370 RC=$?
371 if test $RC != 0 ; then
372         echo "ldapsearch failed ($RC)!"
373         test $KILLSERVERS != no && kill -HUP $KILLPIDS
374         exit $RC
375 fi
376
377 echo "Testing attribute inheritance in requested attributes..."
378 echo "# Testing attribute inheritance in requested attributes..." >> $SEARCHOUT
379 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
380          "(sn=kovalev)" name >> $SEARCHOUT 2>&1
381
382 RC=$?
383 if test $RC != 0 ; then
384         echo "ldapsearch failed ($RC)!"
385         test $KILLSERVERS != no && kill -HUP $KILLPIDS
386         exit $RC
387 fi
388
389 echo "Testing objectClass in requested attributes..."
390 echo "# Testing objectClass in requested attributes..." >> $SEARCHOUT
391 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
392          objectClass >> $SEARCHOUT 2>&1
393
394 RC=$?
395 if test $RC != 0 ; then
396         echo "ldapsearch failed ($RC)!"
397         test $KILLSERVERS != no && kill -HUP $KILLPIDS
398         exit $RC
399 fi
400
401 echo "Testing operational attributes in request..."
402 echo "# Testing operational attributes in request..." >> $SEARCHOUT
403 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
404          '+' 2>&1 > $SEARCHFLT
405
406 RC=$?
407 if test $RC != 0 ; then
408         echo "ldapsearch failed ($RC)!"
409         test $KILLSERVERS != no && kill -HUP $KILLPIDS
410         exit $RC
411 fi
412
413 grep -v '^entryCSN:' $SEARCHFLT >> $SEARCHOUT 
414
415 SIZELIMIT=4
416 echo "Testing size limit..."
417 $LDAPRSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
418         -z $SIZELIMIT -S "" '(objectClass=*)' >$SEARCHFLT 2>&1
419 RC=$?
420 COUNT=`awk '/^# numEntries:/ {print $3}' $SEARCHFLT`
421 case $RC in
422         0)
423                 if test x"$COUNT" != x ; then
424                         if test "$COUNT" -gt "$SIZELIMIT" ; then
425                                 echo "...error: got $COUNT entries instead of the requested $SIZELIMIT"
426                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
427                                 exit 1
428                         fi
429                         echo "...didn't bump into the requested size limit ($SIZELIMIT; got $COUNT entries)"
430                 else
431                         echo "...error: did not expect ldapsearch success ($RC)!"
432                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
433                         exit 1
434                 fi
435         ;;
436         4)
437                 if test x"$COUNT" != x ; then
438                         if test "$COUNT" = "$SIZELIMIT" ; then
439                                 echo "...bumped into requested size limit ($SIZELIMIT)"
440                         else
441                                 echo "...error: got $COUNT entries with a requested sizelimit of $SIZELIMIT"
442                                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
443                                 exit $RC
444                         fi
445                 else
446                         echo "...error: bumped into server-side size limit, but got no entries!"
447                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
448                         exit $RC
449                 fi
450         ;;
451         *)
452                 echo "ldapsearch failed ($RC)!"
453                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
454                 exit $RC
455         ;;
456 esac
457
458 echo -n "Testing compare (should be TRUE)... "
459 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
460          "sn:kovalev" >> $TESTOUT 2>&1
461
462 RC=$?
463 case $RC in
464 6)
465         echo "TRUE"
466         ;;
467 5)      echo "FALSE!"
468         test $KILLSERVERS != no && kill -HUP $KILLPIDS
469         exit $RC
470         ;;
471 *)      echo "failed ($RC)!"
472         test $KILLSERVERS != no && kill -HUP $KILLPIDS
473         exit 1
474         ;;
475 esac
476
477 echo -n "Testing compare (should be FALSE)... "
478 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
479          "cn:foobar" >> $TESTOUT 2>&1
480
481 RC=$?
482 case $RC in
483 6)
484         echo "TRUE!"
485         test $KILLSERVERS != no && kill -HUP $KILLPIDS
486         exit $RC
487         ;;
488 5)      echo "FALSE"
489         ;;
490 *)      echo "failed ($RC)!"
491         test $KILLSERVERS != no && kill -HUP $KILLPIDS
492         exit 1
493         ;;
494 esac
495
496 echo -n "Testing compare (should be UNDEFINED)... "
497 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
498          "o:example" >> $TESTOUT 2>&1
499
500 RC=$?
501 case $RC in
502 6)
503         echo "TRUE!"
504         test $KILLSERVERS != no && kill -HUP $KILLPIDS
505         exit $RC
506         ;;
507 5)      echo "FALSE!"
508         test $KILLSERVERS != no && kill -HUP $KILLPIDS
509         exit $RC
510         ;;
511 *)      echo "failed ($RC)"
512         ;;
513 esac
514
515 echo -n "Testing compare on hasSubordinates (should be TRUE)... "
516 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BASEDN" \
517          "hasSubordinates:TRUE" >> $TESTOUT 2>&1
518
519 RC=$?
520 case $RC in
521 6)
522         echo "TRUE"
523         ;;
524 5)      echo "FALSE!"
525         test $KILLSERVERS != no && kill -HUP $KILLPIDS
526         exit $RC
527         ;;
528 *)      echo "failed ($RC)!"
529         test $KILLSERVERS != no && kill -HUP $KILLPIDS
530         exit 1
531         ;;
532 esac
533
534 echo "Filtering ldapsearch results..."
535 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
536 echo "Filtering original ldif..."
537 . $LDIFFILTER < $SQLREAD > $LDIFFLT
538 echo "Comparing filter output..."
539 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
540
541 if test $? != 0 ; then
542         echo "comparison failed - SQL search didn't succeed"
543         test $KILLSERVERS != no && kill -HUP $KILLPIDS
544         exit 1
545 fi
546
547 test $KILLSERVERS != no && kill -HUP $KILLPIDS
548
549 echo ">>>>> Test succeeded"
550 exit 0