]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test000-read
fix args order to client tools; use -M instead of -e manageDSAit
[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-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 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 $RC
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 invalid filter..."
114 echo "# Testing invalid filter..." >> $SEARCHOUT
115 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
116          "(foo=)" >> $SEARCHOUT 2>&1
117
118 RC=$?
119 if test $RC != 0 ; then
120         echo "ldapsearch failed ($RC)!"
121         test $KILLSERVERS != no && kill -HUP $KILLPIDS
122         exit $RC
123 fi
124
125 echo "Testing exact search..."
126 echo "# Testing exact search..." >> $SEARCHOUT
127 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
128          "(sn=Kovalev)" >> $SEARCHOUT 2>&1
129
130 RC=$?
131 if test $RC != 0 ; then
132         echo "ldapsearch failed ($RC)!"
133         test $KILLSERVERS != no && kill -HUP $KILLPIDS
134         exit $RC
135 fi
136
137 echo "Testing substrings initial search..."
138 echo "# Testing substrings initial search..." >> $SEARCHOUT
139 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
140          "(cn=m*)" >> $SEARCHOUT 2>&1
141
142 RC=$?
143 if test $RC != 0 ; then
144         echo "ldapsearch failed ($RC)!"
145         test $KILLSERVERS != no && kill -HUP $KILLPIDS
146         exit $RC
147 fi
148
149 echo "Testing substrings any search..."
150 echo "# Testing substrings any search..." >> $SEARCHOUT
151 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
152          "(cn=*m*)" >> $SEARCHOUT 2>&1
153
154 RC=$?
155 if test $RC != 0 ; then
156         echo "ldapsearch failed ($RC)!"
157         test $KILLSERVERS != no && kill -HUP $KILLPIDS
158         exit $RC
159 fi
160
161 echo "Testing substrings final search..."
162 echo "# Testing substrings final search..." >> $SEARCHOUT
163 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
164          "(cn=*v)" >> $SEARCHOUT 2>&1
165
166 RC=$?
167 if test $RC != 0 ; then
168         echo "ldapsearch failed ($RC)!"
169         test $KILLSERVERS != no && kill -HUP $KILLPIDS
170         exit $RC
171 fi
172
173 echo "Testing approx search..."
174 echo "# Testing approx search..." >> $SEARCHOUT
175 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
176          "(sn~=kovalev)" >> $SEARCHOUT 2>&1
177
178 RC=$?
179 if test $RC != 0 ; then
180         echo "ldapsearch failed ($RC)!"
181         test $KILLSERVERS != no && kill -HUP $KILLPIDS
182         exit $RC
183 fi
184
185 echo "Testing extensible filter search..."
186 echo "# Testing extensible filter search..." >> $SEARCHOUT
187 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
188          "(sn:caseExactMatch:=Kovalev)" >> $SEARCHOUT 2>&1
189
190 RC=$?
191 if test $RC != 0 ; then
192         echo "ldapsearch failed ($RC)!"
193         test $KILLSERVERS != no && kill -HUP $KILLPIDS
194         exit $RC
195 fi
196
197 echo "Testing search for telephoneNumber..."
198 echo "# Testing search for telephoneNumber..." >> $SEARCHOUT
199 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
200          "(telephoneNumber=3322334)" >> $SEARCHOUT 2>&1
201
202 RC=$?
203 if test $RC != 0 ; then
204         echo "ldapsearch failed ($RC)!"
205         test $KILLSERVERS != no && kill -HUP $KILLPIDS
206         exit $RC
207 fi
208
209 echo "Testing AND search..."
210 echo "# Testing AND search..." >> $SEARCHOUT
211 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
212          "(&(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
213
214 RC=$?
215 if test $RC != 0 ; then
216         echo "ldapsearch failed ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219 fi
220
221 echo "Testing AND search on objectClass..."
222 echo "# Testing AND search on objectClass..." >> $SEARCHOUT
223 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
224          "(&(objectClass=organization)(objectClass=dcObject))" >> $SEARCHOUT 2>&1
225
226 RC=$?
227 if test $RC != 0 ; then
228         echo "ldapsearch failed ($RC)!"
229         test $KILLSERVERS != no && kill -HUP $KILLPIDS
230         exit $RC
231 fi
232
233 echo "Testing OR search..."
234 echo "# Testing OR search..." >> $SEARCHOUT
235 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
236          "(|(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
237
238 RC=$?
239 if test $RC != 0 ; then
240         echo "ldapsearch failed ($RC)!"
241         test $KILLSERVERS != no && kill -HUP $KILLPIDS
242         exit $RC
243 fi
244
245 echo "Testing OR search on objectClass..."
246 echo "# Testing OR search on objectClass..." >> $SEARCHOUT
247 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
248          "(|(objectClass=document)(objectClass=organization))" >> $SEARCHOUT 2>&1
249
250 RC=$?
251 if test $RC != 0 ; then
252         echo "ldapsearch failed ($RC)!"
253         test $KILLSERVERS != no && kill -HUP $KILLPIDS
254         exit $RC
255 fi
256
257 echo "Testing NOT search..."
258 echo "# Testing NOT search..." >> $SEARCHOUT
259 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
260          '(!(sn=kovalev))' >> $SEARCHOUT 2>&1
261
262 RC=$?
263 if test $RC != 0 ; then
264         echo "ldapsearch failed ($RC)!"
265         test $KILLSERVERS != no && kill -HUP $KILLPIDS
266         exit $RC
267 fi
268
269 echo "Testing NOT search on objectClass..."
270 echo "# Testing NOT search on objectClass..." >> $SEARCHOUT
271 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
272          '(!(objectClass=inetOrgPerson))' >> $SEARCHOUT 2>&1
273
274 RC=$?
275 if test $RC != 0 ; then
276         echo "ldapsearch failed ($RC)!"
277         test $KILLSERVERS != no && kill -HUP $KILLPIDS
278         exit $RC
279 fi
280
281 echo "Testing NOT search on \"auxiliary\" objectClass..."
282 echo "# Testing NOT search on \"auxiliary\" objectClass..." >> $SEARCHOUT
283 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
284          '(!(objectClass=dcObject))' >> $SEARCHOUT 2>&1
285
286 RC=$?
287 if test $RC != 0 ; then
288         echo "ldapsearch failed ($RC)!"
289         test $KILLSERVERS != no && kill -HUP $KILLPIDS
290         exit $RC
291 fi
292
293 #### Needs work...
294 echo "Testing NOT presence search... (disabled)"
295 ###echo "# Testing NOT presence search..." >> $SEARCHOUT
296 ###$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
297 ###      '(!(sn=*))' >> $SEARCHOUT 2>&1
298 ###
299 ###RC=$?
300 ###if test $RC != 0 ; then
301 ###     echo "ldapsearch failed ($RC)!"
302 ###     test $KILLSERVERS != no && kill -HUP $KILLPIDS
303 ###     exit $RC
304 ###fi
305
306 echo "Testing attribute inheritance in filter..."
307 echo "# Testing attribute inheritance in filter..." >> $SEARCHOUT
308 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
309          "(name=example)" >> $SEARCHOUT 2>&1
310
311 RC=$?
312 if test $RC != 0 ; then
313         echo "ldapsearch failed ($RC)!"
314         test $KILLSERVERS != no && kill -HUP $KILLPIDS
315         exit $RC
316 fi
317
318 echo "Testing objectClass inheritance in filter..."
319 echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT
320 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
321          "(objectClass=person)" >> $SEARCHOUT 2>&1
322
323 RC=$?
324 if test $RC != 0 ; then
325         echo "ldapsearch failed ($RC)!"
326         test $KILLSERVERS != no && kill -HUP $KILLPIDS
327         exit $RC
328 fi
329
330 echo "Testing \"auxiliary\" objectClass in filter..."
331 echo "# Testing \"auxiliary\" objectClass in filter..." >> $SEARCHOUT
332 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
333          "(objectClass=dcObject)" >> $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 hasSubordinates in filter..."
343 echo "# Testing hasSubordinates in filter..." >> $SEARCHOUT
344 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
345          "(hasSubordinates=TRUE)" >> $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 entryUUID in filter..."
355 echo "# Testing entryUUID in filter..." >> $SEARCHOUT
356 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
357          "(entryUUID=00000001-0000-0001-0000-000000000000)" >> $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 attribute inheritance in requested attributes..."
367 echo "# Testing attribute inheritance in requested attributes..." >> $SEARCHOUT
368 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
369          "(sn=kovalev)" name >> $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 objectClass in requested attributes..."
379 echo "# Testing objectClass in requested attributes..." >> $SEARCHOUT
380 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
381          objectClass >> $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 operational attributes in request..."
391 echo "# Testing operational attributes in request..." >> $SEARCHOUT
392 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
393          '+' 2>&1 | grep -v '^entryCSN:' >> $SEARCHOUT 
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 -n "Testing compare (should be TRUE)... "
403 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
404          "sn:kovalev" >> $TESTOUT 2>&1
405
406 RC=$?
407 case $RC in
408 6)
409         echo "TRUE"
410         ;;
411 5)      echo "FALSE!"
412         test $KILLSERVERS != no && kill -HUP $KILLPIDS
413         exit $RC
414         ;;
415 *)      echo "failed ($RC)!"
416         test $KILLSERVERS != no && kill -HUP $KILLPIDS
417         exit $RC
418         ;;
419 esac
420
421 echo -n "Testing compare (should be FALSE)... "
422 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
423          "cn:foobar" >> $TESTOUT 2>&1
424
425 RC=$?
426 case $RC in
427 6)
428         echo "TRUE!"
429         test $KILLSERVERS != no && kill -HUP $KILLPIDS
430         exit $RC
431         ;;
432 5)      echo "FALSE"
433         ;;
434 *)      echo "failed ($RC)!"
435         test $KILLSERVERS != no && kill -HUP $KILLPIDS
436         exit $RC
437         ;;
438 esac
439
440 echo -n "Testing compare (should be UNDEFINED)... "
441 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
442          "o:example" >> $TESTOUT 2>&1
443
444 RC=$?
445 case $RC in
446 6)
447         echo "TRUE!"
448         test $KILLSERVERS != no && kill -HUP $KILLPIDS
449         exit $RC
450         ;;
451 5)      echo "FALSE!"
452         test $KILLSERVERS != no && kill -HUP $KILLPIDS
453         exit $RC
454         ;;
455 *)      echo "failed ($RC)"
456         ;;
457 esac
458
459 echo "Filtering ldapsearch results..."
460 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
461 echo "Filtering original ldif..."
462 . $LDIFFILTER < $SQLREAD > $LDIFFLT
463 echo "Comparing filter output..."
464 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
465         
466 if test $? != 0 ; then
467         echo "comparison failed - SQL search didn't succeed"
468         test $KILLSERVERS != no && kill -HUP $KILLPIDS
469         exit 1
470 fi
471
472 test $KILLSERVERS != no && kill -HUP $KILLPIDS
473
474 echo ">>>>> Test succeeded"
475 exit 0