]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test000-read
more definitive improvements; now write operations are consistent; plugged some more...
[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 search..."
81 echo "# Testing search..." > $SEARCHOUT
82 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $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 invalid filter..."
92 echo "# Testing invalid filter..." >> $SEARCHOUT
93 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
94          "(foo=)" >> $SEARCHOUT 2>&1
95
96 RC=$?
97 if test $RC != 0 ; then
98         echo "ldapsearch failed ($RC)!"
99         test $KILLSERVERS != no && kill -HUP $KILLPIDS
100         exit $RC
101 fi
102
103 echo "Testing exact search..."
104 echo "# Testing exact search..." >> $SEARCHOUT
105 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
106          "(sn=Kovalev)" >> $SEARCHOUT 2>&1
107
108 RC=$?
109 if test $RC != 0 ; then
110         echo "ldapsearch failed ($RC)!"
111         test $KILLSERVERS != no && kill -HUP $KILLPIDS
112         exit $RC
113 fi
114
115 echo "Testing substrings initial search..."
116 echo "# Testing substrings initial search..." >> $SEARCHOUT
117 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
118          "(cn=m*)" >> $SEARCHOUT 2>&1
119
120 RC=$?
121 if test $RC != 0 ; then
122         echo "ldapsearch failed ($RC)!"
123         test $KILLSERVERS != no && kill -HUP $KILLPIDS
124         exit $RC
125 fi
126
127 echo "Testing substrings any search..."
128 echo "# Testing substrings any search..." >> $SEARCHOUT
129 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
130          "(cn=*m*)" >> $SEARCHOUT 2>&1
131
132 RC=$?
133 if test $RC != 0 ; then
134         echo "ldapsearch failed ($RC)!"
135         test $KILLSERVERS != no && kill -HUP $KILLPIDS
136         exit $RC
137 fi
138
139 echo "Testing substrings final search..."
140 echo "# Testing substrings final search..." >> $SEARCHOUT
141 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
142          "(cn=*v)" >> $SEARCHOUT 2>&1
143
144 RC=$?
145 if test $RC != 0 ; then
146         echo "ldapsearch failed ($RC)!"
147         test $KILLSERVERS != no && kill -HUP $KILLPIDS
148         exit $RC
149 fi
150
151 echo "Testing approx search..."
152 echo "# Testing approx search..." >> $SEARCHOUT
153 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
154          "(sn~=kovalev)" >> $SEARCHOUT 2>&1
155
156 RC=$?
157 if test $RC != 0 ; then
158         echo "ldapsearch failed ($RC)!"
159         test $KILLSERVERS != no && kill -HUP $KILLPIDS
160         exit $RC
161 fi
162
163 echo "Testing extensible filter search..."
164 echo "# Testing extensible filter search..." >> $SEARCHOUT
165 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
166          "(sn:caseExactMatch:=Kovalev)" >> $SEARCHOUT 2>&1
167
168 RC=$?
169 if test $RC != 0 ; then
170         echo "ldapsearch failed ($RC)!"
171         test $KILLSERVERS != no && kill -HUP $KILLPIDS
172         exit $RC
173 fi
174
175 echo "Testing search for telephoneNumber..."
176 echo "# Testing search for telephoneNumber..." >> $SEARCHOUT
177 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
178          "(telephoneNumber=3322334)" >> $SEARCHOUT 2>&1
179
180 RC=$?
181 if test $RC != 0 ; then
182         echo "ldapsearch failed ($RC)!"
183         test $KILLSERVERS != no && kill -HUP $KILLPIDS
184         exit $RC
185 fi
186
187 echo "Testing AND search..."
188 echo "# Testing AND search..." >> $SEARCHOUT
189 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
190          "(&(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
191
192 RC=$?
193 if test $RC != 0 ; then
194         echo "ldapsearch failed ($RC)!"
195         test $KILLSERVERS != no && kill -HUP $KILLPIDS
196         exit $RC
197 fi
198
199 echo "Testing AND search on objectClass..."
200 echo "# Testing AND search on objectClass..." >> $SEARCHOUT
201 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
202          "(&(objectClass=organization)(objectClass=dcObject))" >> $SEARCHOUT 2>&1
203
204 RC=$?
205 if test $RC != 0 ; then
206         echo "ldapsearch failed ($RC)!"
207         test $KILLSERVERS != no && kill -HUP $KILLPIDS
208         exit $RC
209 fi
210
211 echo "Testing OR search..."
212 echo "# Testing OR search..." >> $SEARCHOUT
213 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
214          "(|(sn=kovalev)(givenName=mitya))" >> $SEARCHOUT 2>&1
215
216 RC=$?
217 if test $RC != 0 ; then
218         echo "ldapsearch failed ($RC)!"
219         test $KILLSERVERS != no && kill -HUP $KILLPIDS
220         exit $RC
221 fi
222
223 echo "Testing OR search on objectClass..."
224 echo "# Testing OR search on objectClass..." >> $SEARCHOUT
225 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
226          "(|(objectClass=document)(objectClass=organization))" >> $SEARCHOUT 2>&1
227
228 RC=$?
229 if test $RC != 0 ; then
230         echo "ldapsearch failed ($RC)!"
231         test $KILLSERVERS != no && kill -HUP $KILLPIDS
232         exit $RC
233 fi
234
235 echo "Testing NOT search..."
236 echo "# Testing NOT search..." >> $SEARCHOUT
237 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
238          '(!(sn=kovalev))' >> $SEARCHOUT 2>&1
239
240 RC=$?
241 if test $RC != 0 ; then
242         echo "ldapsearch failed ($RC)!"
243         test $KILLSERVERS != no && kill -HUP $KILLPIDS
244         exit $RC
245 fi
246
247 echo "Testing NOT search on objectClass..."
248 echo "# Testing NOT search on objectClass..." >> $SEARCHOUT
249 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
250          '(!(objectClass=inetOrgPerson))' >> $SEARCHOUT 2>&1
251
252 RC=$?
253 if test $RC != 0 ; then
254         echo "ldapsearch failed ($RC)!"
255         test $KILLSERVERS != no && kill -HUP $KILLPIDS
256         exit $RC
257 fi
258
259 echo "Testing NOT search on \"auxiliary\" objectClass..."
260 echo "# Testing NOT search on \"auxiliary\" objectClass..." >> $SEARCHOUT
261 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
262          '(!(objectClass=dcObject))' >> $SEARCHOUT 2>&1
263
264 RC=$?
265 if test $RC != 0 ; then
266         echo "ldapsearch failed ($RC)!"
267         test $KILLSERVERS != no && kill -HUP $KILLPIDS
268         exit $RC
269 fi
270
271 #### Needs work...
272 echo "Testing NOT presence search... (disabled)"
273 ###echo "# Testing NOT presence search..." >> $SEARCHOUT
274 ###$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
275 ###      '(!(sn=*))' >> $SEARCHOUT 2>&1
276 ###
277 ###RC=$?
278 ###if test $RC != 0 ; then
279 ###     echo "ldapsearch failed ($RC)!"
280 ###     test $KILLSERVERS != no && kill -HUP $KILLPIDS
281 ###     exit $RC
282 ###fi
283
284 echo "Testing attribute inheritance in filter..."
285 echo "# Testing attribute inheritance in filter..." >> $SEARCHOUT
286 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
287          "(name=example)" >> $SEARCHOUT 2>&1
288
289 RC=$?
290 if test $RC != 0 ; then
291         echo "ldapsearch failed ($RC)!"
292         test $KILLSERVERS != no && kill -HUP $KILLPIDS
293         exit $RC
294 fi
295
296 echo "Testing objectClass inheritance in filter..."
297 echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT
298 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
299          "(objectClass=person)" >> $SEARCHOUT 2>&1
300
301 RC=$?
302 if test $RC != 0 ; then
303         echo "ldapsearch failed ($RC)!"
304         test $KILLSERVERS != no && kill -HUP $KILLPIDS
305         exit $RC
306 fi
307
308 echo "Testing \"auxiliary\" objectClass in filter..."
309 echo "# Testing \"auxiliary\" objectClass in filter..." >> $SEARCHOUT
310 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
311          "(objectClass=dcObject)" >> $SEARCHOUT 2>&1
312
313 RC=$?
314 if test $RC != 0 ; then
315         echo "ldapsearch failed ($RC)!"
316         test $KILLSERVERS != no && kill -HUP $KILLPIDS
317         exit $RC
318 fi
319
320 echo "Testing hasSubordinates in filter..."
321 echo "# Testing hasSubordinates in filter..." >> $SEARCHOUT
322 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
323          "(hasSubordinates=TRUE)" >> $SEARCHOUT 2>&1
324
325 RC=$?
326 if test $RC != 0 ; then
327         echo "ldapsearch failed ($RC)!"
328         test $KILLSERVERS != no && kill -HUP $KILLPIDS
329         exit $RC
330 fi
331
332 echo "Testing attribute inheritance in requested attributes..."
333 echo "# Testing attribute inheritance in requested attributes..." >> $SEARCHOUT
334 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
335          "(sn=kovalev)" name >> $SEARCHOUT 2>&1
336
337 RC=$?
338 if test $RC != 0 ; then
339         echo "ldapsearch failed ($RC)!"
340         test $KILLSERVERS != no && kill -HUP $KILLPIDS
341         exit $RC
342 fi
343
344 echo "Testing objectClass in requested attributes..."
345 echo "# Testing objectClass in requested attributes..." >> $SEARCHOUT
346 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
347          objectClass >> $SEARCHOUT 2>&1
348
349 RC=$?
350 if test $RC != 0 ; then
351         echo "ldapsearch failed ($RC)!"
352         test $KILLSERVERS != no && kill -HUP $KILLPIDS
353         exit $RC
354 fi
355
356 echo "Testing operational attributes in request..."
357 echo "# Testing operational attributes in request..." >> $SEARCHOUT
358 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
359          '+' >> $SEARCHOUT 2>&1
360
361 RC=$?
362 if test $RC != 0 ; then
363         echo "ldapsearch failed ($RC)!"
364         test $KILLSERVERS != no && kill -HUP $KILLPIDS
365         exit $RC
366 fi
367
368 echo -n "Testing compare (should be TRUE)... "
369 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
370          "sn:kovalev" >> $TESTOUT 2>&1
371
372 RC=$?
373 case $RC in
374 6)
375         echo "TRUE"
376         ;;
377 5)      echo "FALSE!"
378         test $KILLSERVERS != no && kill -HUP $KILLPIDS
379         exit $RC
380         ;;
381 *)      echo "failed ($RC)!"
382         test $KILLSERVERS != no && kill -HUP $KILLPIDS
383         exit $RC
384         ;;
385 esac
386
387 echo -n "Testing compare (should be FALSE)... "
388 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
389          "cn:foobar" >> $TESTOUT 2>&1
390
391 RC=$?
392 case $RC in
393 6)
394         echo "TRUE!"
395         test $KILLSERVERS != no && kill -HUP $KILLPIDS
396         exit $RC
397         ;;
398 5)      echo "FALSE"
399         ;;
400 *)      echo "failed ($RC)!"
401         test $KILLSERVERS != no && kill -HUP $KILLPIDS
402         exit $RC
403         ;;
404 esac
405
406 echo -n "Testing compare (should be UNDEFINED)... "
407 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
408          "o:example" >> $TESTOUT 2>&1
409
410 RC=$?
411 case $RC in
412 6)
413         echo "TRUE!"
414         test $KILLSERVERS != no && kill -HUP $KILLPIDS
415         exit $RC
416         ;;
417 5)      echo "FALSE!"
418         test $KILLSERVERS != no && kill -HUP $KILLPIDS
419         exit $RC
420         ;;
421 *)      echo "failed ($RC)"
422         ;;
423 esac
424
425 echo "Filtering ldapsearch results..."
426 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
427 echo "Filtering original ldif..."
428 . $LDIFFILTER < $SQLREAD > $LDIFFLT
429 echo "Comparing filter output..."
430 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
431         
432 if test $? != 0 ; then
433         echo "comparison failed - SQL search didn't succeed"
434         test $KILLSERVERS != no && kill -HUP $KILLPIDS
435         exit 1
436 fi
437
438 test $KILLSERVERS != no && kill -HUP $KILLPIDS
439
440 echo ">>>>> Test succeeded"
441 exit 0