]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test000-read
Sync with HEAD
[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-2005 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 echo -n "Testing compare (should be TRUE)... "
416 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
417          "sn:kovalev" >> $TESTOUT 2>&1
418
419 RC=$?
420 case $RC in
421 6)
422         echo "TRUE"
423         ;;
424 5)      echo "FALSE!"
425         test $KILLSERVERS != no && kill -HUP $KILLPIDS
426         exit $RC
427         ;;
428 *)      echo "failed ($RC)!"
429         test $KILLSERVERS != no && kill -HUP $KILLPIDS
430         exit 1
431         ;;
432 esac
433
434 echo -n "Testing compare (should be FALSE)... "
435 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
436          "cn:foobar" >> $TESTOUT 2>&1
437
438 RC=$?
439 case $RC in
440 6)
441         echo "TRUE!"
442         test $KILLSERVERS != no && kill -HUP $KILLPIDS
443         exit $RC
444         ;;
445 5)      echo "FALSE"
446         ;;
447 *)      echo "failed ($RC)!"
448         test $KILLSERVERS != no && kill -HUP $KILLPIDS
449         exit 1
450         ;;
451 esac
452
453 echo -n "Testing compare (should be UNDEFINED)... "
454 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
455          "o:example" >> $TESTOUT 2>&1
456
457 RC=$?
458 case $RC in
459 6)
460         echo "TRUE!"
461         test $KILLSERVERS != no && kill -HUP $KILLPIDS
462         exit $RC
463         ;;
464 5)      echo "FALSE!"
465         test $KILLSERVERS != no && kill -HUP $KILLPIDS
466         exit $RC
467         ;;
468 *)      echo "failed ($RC)"
469         ;;
470 esac
471
472 echo -n "Testing compare on hasSubordinates (should be TRUE)... "
473 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BASEDN" \
474          "hasSubordinates:TRUE" >> $TESTOUT 2>&1
475
476 RC=$?
477 case $RC in
478 6)
479         echo "TRUE"
480         ;;
481 5)      echo "FALSE!"
482         test $KILLSERVERS != no && kill -HUP $KILLPIDS
483         exit $RC
484         ;;
485 *)      echo "failed ($RC)!"
486         test $KILLSERVERS != no && kill -HUP $KILLPIDS
487         exit 1
488         ;;
489 esac
490
491 echo "Filtering ldapsearch results..."
492 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
493 echo "Filtering original ldif..."
494 . $LDIFFILTER < $SQLREAD > $LDIFFLT
495 echo "Comparing filter output..."
496 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
497
498 if test $? != 0 ; then
499         echo "comparison failed - SQL search didn't succeed"
500         test $KILLSERVERS != no && kill -HUP $KILLPIDS
501         exit 1
502 fi
503
504 test $KILLSERVERS != no && kill -HUP $KILLPIDS
505
506 echo ">>>>> Test succeeded"
507 exit 0