]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test900-write
c692e1e26d56c26158a031617d84c243622567cf
[openldap] / tests / scripts / sql-test900-write
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 if test "${RDBMSWRITE}" != "yes"; then
30         echo "write test disabled for ${RDBMS}; set SLAPD_USE_SQLWRITE=yes to enable"
31         exit 0
32 fi
33
34 mkdir -p $TESTDIR
35
36 echo "Starting slapd on TCP/IP port $PORT1..."
37 . $CONFFILTER $BACKEND $MONITORDB < $SQLCONF > $CONF1
38 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
39 PID=$!
40 if test $WAIT != 0 ; then
41     echo PID $PID
42     read foo
43 fi
44 KILLPIDS="$PID"
45
46 echo "Testing SQL backend write operations..."
47 for i in 0 1 2 3 4 5; do
48         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
49                 'objectclass=*' > /dev/null 2>&1
50         RC=$?
51         if test $RC = 0 ; then
52                 break
53         fi
54         echo "Waiting 5 seconds for slapd to start..."
55         sleep 5
56 done
57
58 if test $RC != 0 ; then
59         echo "ldapsearch failed ($RC)!"
60         test $KILLSERVERS != no && kill -HUP $KILLPIDS
61         exit $RC
62 fi
63
64 cat /dev/null > $SEARCHOUT
65
66 BASEDN="dc=example,dc=com"
67
68 echo "Using ldapsearch to retrieve all the entries..."
69 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
70 $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
71          "objectClass=*" >> $SEARCHOUT 2>&1
72
73 RC=$?
74 if test $RC != 0 ; then
75         echo "ldapsearch failed ($RC)!"
76         test $KILLSERVERS != no && kill -HUP $KILLPIDS
77         exit $RC
78 fi
79
80 case ${RDBMS} in
81         # list here the RDBMSes whose mapping allows writes
82 postgres|ibmdb2)
83         MANAGERDN="cn=Manager,${BASEDN}"
84         echo "Testing add..."
85         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
86                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
87 version: 1
88
89 # Adding an organization...
90 dn: o=An Org,${BASEDN}
91 changetype: add
92 objectClass: organization
93 o: An Org
94
95 # Adding an organization with an "auxiliary" objectClass..
96 dn: dc=subnet,${BASEDN}
97 changetype: add
98 objectClass: organization
99 objectClass: dcObject
100 o: SubNet
101 dc: subnet
102
103 # Adding another organization with an "auxiliary" objectClass..
104 dn: dc=subnet2,${BASEDN}
105 changetype: add
106 objectClass: organization
107 objectClass: dcObject
108 o: SubNet 2
109 dc: subnet2
110
111 # Adding a person...
112 dn: cn=Lev Tolstoij,${BASEDN}
113 changetype: add
114 objectClass: inetOrgPerson
115 cn: Lev Tolstoij
116 sn: Tolstoij
117 givenName: Lev
118 telephoneNumber: +39 02 XXXX YYYY
119 telephoneNumber: +39 02 XXXX ZZZZ
120 userPassword: tanja
121
122 # Adding a person with an "auxiliary" objectClass...
123 dn: cn=Some One,${BASEDN}
124 changetype: add
125 objectClass: inetOrgPerson
126 objectClass: simpleSecurityObject
127 cn: Some One
128 sn: One
129 givenName: Some
130 telephoneNumber: +1 800 900 1234
131 telephoneNumber: +1 800 900 1235
132 userPassword: someone
133
134 # Adding a person in another subtree...
135 dn: cn=SubNet User,dc=subnet,${BASEDN}
136 changetype: add
137 objectClass: inetOrgPerson
138 cn: SubNet User
139 sn: User
140 givenName: SubNet
141
142 # Adding a document...
143 dn: documentTitle=War and Peace,${BASEDN}
144 changetype: add
145 objectClass: document
146 description: Historical novel
147 documentTitle: War and Peace
148 documentAuthor: cn=Lev Tolstoij,dc=example,dc=com
149 documentIdentifier: document 3
150 EOMODS
151
152         RC=$?
153         if test $RC != 0 ; then
154                 echo "ldapmodify failed ($RC)!"
155                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
156                 exit $RC
157         fi
158
159         echo "Using ldapsearch to retrieve all the entries..."
160         echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
161         $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
162                  "objectClass=*" >> $SEARCHOUT 2>&1
163
164         RC=$?
165         if test $RC != 0 ; then
166                 echo "ldapsearch failed ($RC)!"
167                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
168                 exit $RC
169         fi
170
171         echo "Testing modify..."
172         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
173                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
174 version: 1
175
176 # Deleting all telephone numbers...
177 dn: cn=Some One,${BASEDN}
178 changetype: modify
179 delete: telephoneNumber
180 -
181
182 # Adding a telephone number...
183 dn: cn=Mitya Kovalev,${BASEDN}
184 changetype: modify
185 add: telephoneNumber
186 telephoneNumber: +1 800 123 4567
187 -
188
189 # Deleting a specific telephone number and adding a new one...
190 dn: cn=Lev Tolstoij,${BASEDN}
191 changetype: modify
192 delete: telephoneNumber
193 telephoneNumber: +39 02 XXXX YYYY
194 -
195 add: telephoneNumber
196 telephoneNumber: +39 333 ZZZ 1234
197 -
198
199 # Adding an author to a document...
200 dn: documentTitle=book1,${BASEDN}
201 changetype: modify
202 add: documentAuthor
203 documentAuthor: cn=Lev Tolstoij,${BASEDN}
204 -
205
206 # Adding an author to another document...
207 dn: documentTitle=book2,${BASEDN}
208 changetype: modify
209 add: documentAuthor
210 documentAuthor: cn=Lev Tolstoij,${BASEDN}
211 -
212
213 # Adding an "auxiliary" objectClass...
214 dn: cn=Mitya Kovalev,${BASEDN}
215 changetype: modify
216 add: objectClass
217 objectClass: simpleSecurityObject
218 -
219
220 # Deleting an "auxiliary" objectClass...
221 dn: cn=Some One,${BASEDN}
222 changetype: modify
223 delete: objectClass
224 objectClass: simpleSecurityObject
225 -
226
227 # Deleting userPasswords
228 dn: cn=Lev Tolstoij,${BASEDN}
229 changetype: modify
230 delete: userPassword
231 -
232 EOMODS
233
234         RC=$?
235         if test $RC != 0 ; then
236                 echo "ldapmodify failed ($RC)!"
237                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
238                 exit $RC
239         fi
240
241         echo "Using ldapsearch to retrieve all the entries..."
242         echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
243         $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
244                  "objectClass=*" >> $SEARCHOUT 2>&1
245
246         RC=$?
247         if test $RC != 0 ; then
248                 echo "ldapsearch failed ($RC)!"
249                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
250                 exit $RC
251         fi
252
253         echo "Testing delete..."
254         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
255                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
256 version: 1
257
258 # Deleting a person...
259 dn: cn=Torvlobnor Puzdoy,${BASEDN}
260 changetype: delete
261
262 # Deleting a document...
263 dn: documentTitle=book1,${BASEDN}
264 changetype: delete
265
266 # Deleting an organization with an "auxiliary" objectClass...
267 dn: dc=subnet2,${BASEDN}
268 changetype: delete
269 EOMODS
270
271         RC=$?
272         if test $RC != 0 ; then
273                 echo "ldapmodify failed ($RC)!"
274                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
275                 exit $RC
276         fi
277
278         echo "Using ldapsearch to retrieve all the entries..."
279         echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
280         $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
281                  "objectClass=*" >> $SEARCHOUT 2>&1
282
283         RC=$?
284         if test $RC != 0 ; then
285                 echo "ldapsearch failed ($RC)!"
286                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
287                 exit $RC
288         fi
289
290         echo "Testing rename..."
291         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
292                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
293 version: 1
294
295 # Renaming an organization...
296 dn: o=An Org,${BASEDN}
297 changetype: modrdn
298 newrdn: o=Renamed Org
299 deleteoldrdn: 1
300
301 # Moving a person to another subtree...
302 dn: cn=Lev Tolstoij,${BASEDN}
303 changetype: modrdn
304 newrdn: cn=Lev Tolstoij
305 deleteoldrdn: 0
306 newsuperior: dc=subnet,${BASEDN}
307
308 # Renaming a book...
309 dn: documentTitle=book2,${BASEDN}
310 changetype: modrdn
311 newrdn: documentTitle=Renamed Book
312 deleteoldrdn: 1
313 EOMODS
314
315         RC=$?
316         if test $RC != 0 ; then
317                 echo "ldapmodify failed ($RC)!"
318                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
319                 exit $RC
320         fi
321
322         echo "Using ldapsearch to retrieve all the entries..."
323         echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
324         $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
325                  "objectClass=*" >> $SEARCHOUT 2>&1
326
327         RC=$?
328         if test $RC != 0 ; then
329                 echo "ldapsearch failed ($RC)!"
330                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
331                 exit $RC
332         fi
333
334         echo "Adding a child to a referral (should fail)..."
335         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
336                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
337 version: 1
338
339 dn: cn=Should Fail,cn=Akakiy Zinberstein,${BASEDN}
340 changetype: add
341 objectClass: inetOrgPerson
342 cn: Should Fail
343 sn: Fail
344 telephoneNumber: +39 02 23456789
345 EOMODS
346
347         RC=$?
348         if test $RC = 0 ; then
349                 echo "ldapmodify should have failed ($RC)!"
350                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
351                 exit $RC
352         fi
353
354         echo "Modifying a referral (should fail)..."
355         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
356                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
357 version: 1
358
359 dn: cn=Akakiy Zinberstein,${BASEDN}
360 changetype: modify
361 replace: ref
362 ref: ldap://localhost:9009/
363 -
364 EOMODS
365
366         RC=$?
367         if test $RC = 0 ; then
368                 echo "ldapmodify should have failed ($RC)!"
369                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
370                 exit $RC
371         fi
372
373         echo "Renaming a referral (should fail)..."
374         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
375                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
376 version: 1
377
378 dn: cn=Akakiy Zinberstein,${BASEDN}
379 changetype: modrdn
380 newrdn: cn=Akakiy Zinber
381 deleteoldrdn: 1
382 EOMODS
383
384         RC=$?
385         if test $RC = 0 ; then
386                 echo "ldapmodify should have failed ($RC)!"
387                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
388                 exit $RC
389         fi
390
391         echo "Deleting a referral (should fail)..."
392         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
393                 -h $LOCALHOST -p $PORT1 >> $TESTOUT 2>&1 << EOMODS
394 version: 1
395
396 dn: cn=Akakiy Zinberstein,${BASEDN}
397 changetype: delete
398 EOMODS
399
400         RC=$?
401         if test $RC = 0 ; then
402                 echo "ldapmodify should have failed ($RC)!"
403                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
404                 exit $RC
405         fi
406
407         echo "Modifying a referral with manageDSAit..."
408         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
409                 -h $LOCALHOST -p $PORT1 -M >> $TESTOUT 2>&1 << EOMODS
410 version: 1
411
412 dn: cn=Akakiy Zinberstein,${BASEDN}
413 changetype: modify
414 replace: ref
415 ref: ldap://localhost:9009/
416 -
417 EOMODS
418
419         RC=$?
420         if test $RC != 0 ; then
421                 echo "ldapmodify failed ($RC)!"
422                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
423                 exit $RC
424         fi
425
426         echo "Using ldapsearch to retrieve the modified entry..."
427         echo "# Using ldapsearch to retrieve the modified entry..." >> $SEARCHOUT
428         $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "cn=Akakiy Zinberstein,$BASEDN" -M \
429                  "objectClass=*" '*' ref >> $SEARCHOUT 2>&1
430
431         RC=$?
432         if test $RC != 0 ; then
433                 echo "ldapsearch failed ($RC)!"
434                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
435                 exit $RC
436         fi
437
438         echo "Renaming a referral with manageDSAit..."
439         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
440                 -h $LOCALHOST -p $PORT1 -M >> $TESTOUT 2>&1 << EOMODS
441 version: 1
442
443 dn: cn=Akakiy Zinberstein,${BASEDN}
444 changetype: modrdn
445 newrdn: cn=Akakiy Zinber
446 deleteoldrdn: 1
447 EOMODS
448
449         RC=$?
450         if test $RC != 0 ; then
451                 echo "ldapmodify failed ($RC)!"
452                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
453                 exit $RC
454         fi
455
456         echo "Using ldapsearch to retrieve the renamed entry..."
457         echo "# Using ldapsearch to retrieve the renamed entry..." >> $SEARCHOUT
458         $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "cn=Akakiy Zinber,$BASEDN" -M \
459                  "objectClass=*" '*' ref >> $SEARCHOUT 2>&1
460
461         RC=$?
462         if test $RC != 0 ; then
463                 echo "ldapsearch failed ($RC)!"
464                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
465                 exit $RC
466         fi
467
468         echo "Deleting a referral with manageDSAit..."
469         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
470                 -h $LOCALHOST -p $PORT1 -M >> $TESTOUT 2>&1 << EOMODS
471 version: 1
472
473 dn: cn=Akakiy Zinber,${BASEDN}
474 changetype: delete
475 EOMODS
476
477         RC=$?
478         if test $RC != 0 ; then
479                 echo "ldapmodify failed ($RC)!"
480                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
481                 exit $RC
482         fi
483
484         BINDDN="cn=Mitya Kovalev,${BASEDN}"
485         BINDPW="mit"
486         NEWPW="newsecret"
487         echo "Testing passwd change..."
488         $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
489                 -D "${BINDDN}" -w ${BINDPW} -s ${NEWPW} \
490                 "$BINDDN" >> $TESTOUT 2>&1
491
492         RC=$?
493         if test $RC != 0 ; then
494                 echo "ldappasswd failed ($RC)!"
495                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
496                 exit $RC
497         fi
498
499         echo -n "Testing bind with new secret... "
500         $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $NEWPW
501         RC=$?
502         if test $RC != 0 ; then
503                 echo "ldapwhoami failed ($RC)!"
504                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
505                 exit $RC
506         fi
507
508         BINDDN="cn=Some One,${BASEDN}"
509         BINDPW="someone"
510         echo -n "Testing bind with newly added user... "
511         $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
512         RC=$?
513         if test $RC != 0 ; then
514                 echo "ldapwhoami failed ($RC)!"
515                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
516                 exit $RC
517         fi
518
519         echo "Using ldapsearch to retrieve all the entries..."
520         echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
521         $LDAPSEARCH -S "" -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
522                  "objectClass=*" >> $SEARCHOUT 2>&1
523
524         RC=$?
525         if test $RC != 0 ; then
526                 echo "ldapsearch failed ($RC)!"
527                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
528                 exit $RC
529         fi
530
531         echo "Filtering ldapsearch results..."
532         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
533         echo "Filtering modified ldif..."
534         . $LDIFFILTER < $SQLWRITE > $LDIFFLT
535         echo "Comparing filter output..."
536         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
537
538         if test $? != 0 ; then
539                 echo "comparison failed - SQL mods search didn't succeed"
540                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
541                 exit 1
542         fi
543         ;;
544
545 *)
546         echo "apparently ${RDBMS} does not support writes; skipping..."
547         ;;
548 esac
549
550 test $KILLSERVERS != no && kill -HUP $KILLPIDS
551
552 echo ">>>>> Test succeeded"
553 exit 0
554