]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test000-read
rework SQL tests invocation; improve all tests
[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 exact search..."
92 echo "# Testing exact search..." >> $SEARCHOUT
93 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
94          "(sn=Kovalev)" >> $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 substrings initial search..."
104 echo "# Testing substrings initial search..." >> $SEARCHOUT
105 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
106          "(cn=m*)" >> $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 any search..."
116 echo "# Testing substrings any 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 final search..."
128 echo "# Testing substrings final search..." >> $SEARCHOUT
129 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
130          "(cn=*v)" >> $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 approx search..."
140 echo "# Testing approx search..." >> $SEARCHOUT
141 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
142          "(sn~=kovalev)" >> $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 extensible filter search..."
152 echo "# Testing extensible filter search..." >> $SEARCHOUT
153 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
154          "(sn:caseExactMatch:=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 search for telephoneNumber..."
164 echo "# Testing search for telephoneNumber..." >> $SEARCHOUT
165 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
166          "(telephoneNumber=3322334)" >> $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 AND search..."
176 echo "# Testing AND search..." >> $SEARCHOUT
177 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
178          "(&(sn=kovalev)(givenName=mitya))" >> $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 on objectClass..."
188 echo "# Testing AND search on objectClass..." >> $SEARCHOUT
189 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
190          "(&(objectClass=organization)(objectClass=dcObject))" >> $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 OR search..."
200 echo "# Testing OR search..." >> $SEARCHOUT
201 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
202          "(|(sn=kovalev)(givenName=mitya))" >> $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 on objectClass..."
212 echo "# Testing OR search on objectClass..." >> $SEARCHOUT
213 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
214          "(|(objectClass=document)(objectClass=organization))" >> $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 NOT search..."
224 echo "# Testing NOT search..." >> $SEARCHOUT
225 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
226          '(!(sn=kovalev))' >> $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 on objectClass..."
236 echo "# Testing NOT search on objectClass..." >> $SEARCHOUT
237 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
238          '(!(objectClass=inetOrgPerson))' >> $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 \"auxiliary\" objectClass..."
248 echo "# Testing NOT search on \"auxiliary\" objectClass..." >> $SEARCHOUT
249 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
250          '(!(objectClass=dcObject))' >> $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 #### Needs work...
260 echo "Testing NOT presence search... (disabled)"
261 ###echo "# Testing NOT search on sn..." >> $SEARCHOUT
262 ###$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
263 ###      '(!(sn=*))' >> $SEARCHOUT 2>&1
264 ###
265 ###RC=$?
266 ###if test $RC != 0 ; then
267 ###     echo "ldapsearch failed ($RC)!"
268 ###     test $KILLSERVERS != no && kill -HUP $KILLPIDS
269 ###     exit $RC
270 ###fi
271
272 echo "Testing attribute inheritance in filter..."
273 echo "# Testing attribute inheritance in filter..." >> $SEARCHOUT
274 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
275          "(name=example)" >> $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 objectClass inheritance in filter..."
285 echo "# Testing objectClass inheritance in filter..." >> $SEARCHOUT
286 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
287          "(objectClass=person)" >> $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 \"auxiliary\" objectClass in filter..."
297 echo "# Testing \"auxiliary\" objectClass in filter..." >> $SEARCHOUT
298 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
299          "(objectClass=dcObject)" >> $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 hasSubordinates in filter..."
309 echo "# Testing hasSubordinates in filter..." >> $SEARCHOUT
310 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
311          "(hasSubordinates=TRUE)" >> $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 attribute inheritance in requested attributes..."
321 echo "# Testing attribute inheritance in requested attributes..." >> $SEARCHOUT
322 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
323          "(sn=kovalev)" name >> $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 objectClass in requested attributes..."
333 echo "# Testing objectClass in requested attributes..." >> $SEARCHOUT
334 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
335          objectClass >> $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 operational attributes in request..."
345 echo "# Testing operational attributes in request..." >> $SEARCHOUT
346 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
347          '+' >> $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 -n "Testing compare (should be TRUE)... "
357 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
358          "sn:kovalev" >> $TESTOUT 2>&1
359
360 RC=$?
361 case $RC in
362 6)
363         echo "TRUE"
364         ;;
365 5)      echo "FALSE!"
366         test $KILLSERVERS != no && kill -HUP $KILLPIDS
367         exit $RC
368         ;;
369 *)      echo "failed ($RC)!"
370         test $KILLSERVERS != no && kill -HUP $KILLPIDS
371         exit $RC
372         ;;
373 esac
374
375 echo -n "Testing compare (should be FALSE)... "
376 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
377          "cn:foobar" >> $TESTOUT 2>&1
378
379 RC=$?
380 case $RC in
381 6)
382         echo "TRUE!"
383         test $KILLSERVERS != no && kill -HUP $KILLPIDS
384         exit $RC
385         ;;
386 5)      echo "FALSE"
387         ;;
388 *)      echo "failed ($RC)!"
389         test $KILLSERVERS != no && kill -HUP $KILLPIDS
390         exit $RC
391         ;;
392 esac
393
394 echo -n "Testing compare (should be UNDEFINED)... "
395 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 "$BINDDN" \
396          "o:example" >> $TESTOUT 2>&1
397
398 RC=$?
399 case $RC in
400 6)
401         echo "TRUE!"
402         test $KILLSERVERS != no && kill -HUP $KILLPIDS
403         exit $RC
404         ;;
405 5)      echo "FALSE!"
406         test $KILLSERVERS != no && kill -HUP $KILLPIDS
407         exit $RC
408         ;;
409 *)      echo "failed ($RC)"
410         ;;
411 esac
412
413 echo "Filtering ldapsearch results..."
414 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
415 echo "Filtering original ldif..."
416 . $LDIFFILTER < $SQLREAD > $LDIFFLT
417 echo "Comparing filter output..."
418 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
419         
420 if test $? != 0 ; then
421         echo "comparison failed - SQL search didn't succeed"
422         test $KILLSERVERS != no && kill -HUP $KILLPIDS
423         exit 1
424 fi
425
426 test $KILLSERVERS != no && kill -HUP $KILLPIDS
427
428 echo ">>>>> Test succeeded"
429 exit 0