]> git.sur5r.net Git - openldap/blob - tests/scripts/sql-test900-write
rework SQL tests invocation; improve all tests
[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-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 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 BASEDN="dc=example,dc=com"
65 case ${RDBMS} in
66         # list here the RDBMSes whose mapping allows writes
67 postgres)
68         MANAGERDN="cn=Manager,${BASEDN}"
69         echo "Testing add..."
70         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
71                 -h $LOCALHOST -p $PORT1 > \
72                 $TESTOUT 2>&1 << EOMODS
73 version: 1
74
75 # Adding an organization...
76 dn: o=An Org,${BASEDN}
77 changetype: add
78 objectClass: organization
79 o: An Org
80
81 # Adding an organization with an "auxiliary" objectClass..
82 dn: dc=subnet,${BASEDN}
83 changetype: add
84 objectClass: organization
85 objectClass: dcObject
86 o: SubNet
87 dc: subnet
88
89 # Adding a person...
90 dn: cn=Lev Tolstoij,${BASEDN}
91 changetype: add
92 objectClass: inetOrgPerson
93 cn: Lev Tolstoij
94 sn: Tolstoij
95 givenName: Lev
96 telephoneNumber: +39 02 XXXX YYYY
97 telephoneNumber: +39 02 XXXX ZZZZ
98
99 # Adding a person with an "auxiliary" objectClass...
100 dn: cn=Some One,${BASEDN}
101 changetype: add
102 objectClass: inetOrgPerson
103 objectClass: simpleSecurityObject
104 cn: Some One
105 sn: One
106 givenName: Some
107 telephoneNumber: +1 800 900 1234
108 telephoneNumber: +1 800 900 1235
109 userPassword: someone
110
111 # Adding a person in another subtree...
112 dn: cn=SubNet User,dc=subnet,${BASEDN}
113 changetype: add
114 objectClass: inetOrgPerson
115 cn: SubNet User
116 sn: User
117 givenName: SubNet
118
119 # Adding a document...
120 dn: documentTitle=War and Peace,${BASEDN}
121 changetype: add
122 objectClass: document
123 description: Historical novel
124 documentTitle: War and Peace
125 documentAuthor: cn=Lev Tolstoij,dc=example,dc=com
126 documentIdentifier: document 3
127
128 EOMODS
129
130         RC=$?
131         if test $RC != 0 ; then
132                 echo "ldapmodify failed ($RC)!"
133                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
134                 exit $RC
135         fi
136
137         echo "Testing modify..."
138         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
139                 -h $LOCALHOST -p $PORT1 > \
140                 $TESTOUT 2>&1 << EOMODS
141 version: 1
142
143 # Deleting all telephone numbers...
144 dn: cn=Some One,${BASEDN}
145 changetype: modify
146 delete: telephoneNumber
147 -
148
149 # Adding a telephone number...
150 dn: cn=Mitya Kovalev,${BASEDN}
151 changetype: modify
152 add: telephoneNumber
153 telephoneNumber: +1 800 123 4567
154 -
155
156 # Deleting a specific telephone number and adding a new one...
157 dn: cn=Lev Tolstoij,${BASEDN}
158 changetype: modify
159 delete: telephoneNumber
160 telephoneNumber: +39 02 XXXX YYYY
161 -
162 add: telephoneNumber
163 telephoneNumber: +39 333 ZZZ 1234
164 -
165
166 # Adding an author to a document...
167 dn: documentTitle=book1,${BASEDN}
168 changetype: modify
169 add: documentAuthor
170 documentAuthor: cn=Lev Tolstoij,${BASEDN}
171 -
172
173 # Adding an author to another document...
174 dn: documentTitle=book2,${BASEDN}
175 changetype: modify
176 add: documentAuthor
177 documentAuthor: cn=Lev Tolstoij,${BASEDN}
178 -
179
180 # Adding an "auxiliary" objectClass...
181 dn: cn=Mitya Kovalev,${BASEDN}
182 changetype: modify
183 add: objectClass
184 objectClass: simpleSecurityObject
185 -
186
187 # Deleting an "auxiliary" objectClass...
188 dn: cn=Some One,${BASEDN}
189 changetype: modify
190 delete: objectClass
191 objectClass: simpleSecurityObject
192 -
193 delete: userPassword
194 -
195
196 EOMODS
197
198         RC=$?
199         if test $RC != 0 ; then
200                 echo "ldapmodify failed ($RC)!"
201                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
202                 exit $RC
203         fi
204
205         echo "Testing delete..."
206         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
207                 -h $LOCALHOST -p $PORT1 > \
208                 $TESTOUT 2>&1 << EOMODS
209 version: 1
210
211 # Deleting a person...
212 dn: cn=Torvlobnor Puzdoy,${BASEDN}
213 changetype: delete
214
215 # Deleting a document...
216 dn: documentTitle=book1,dc=example,dc=com
217 changetype: delete
218
219 # Deleting a person with an "auxiliary" objectClass...
220 dn: cn=Akakiy Zinberstein,dc=example,dc=com
221 changetype: delete
222
223 EOMODS
224
225         RC=$?
226         if test $RC != 0 ; then
227                 echo "ldapmodify failed ($RC)!"
228                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
229                 exit $RC
230         fi
231
232         echo "Testing rename..."
233         $LDAPMODIFY -v -c -D "$MANAGERDN" -w $PASSWD \
234                 -h $LOCALHOST -p $PORT1 > \
235                 $TESTOUT 2>&1 << EOMODS
236 version: 1
237
238 # Renaming an organization
239 dn: o=An Org,${BASEDN}
240 changetype: modrdn
241 newrdn: o=Another Org
242 deleteoldrdn: 1
243
244 EOMODS
245
246         RC=$?
247         if test $RC != 0 ; then
248                 echo "ldapmodify failed ($RC)!"
249                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
250                 exit $RC
251         fi
252
253         BINDDN="cn=Mitya Kovalev,${BASEDN}"
254         BINDPW="mit"
255         NEWPW="newsecret"
256         echo "Testing passwd change..."
257         $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
258                 -D "${BINDDN}" -w ${BINDPW} -s ${NEWPW} \
259                 "$BINDDN" >> $TESTOUT 2>&1
260
261         RC=$?
262         if test $RC != 0 ; then
263                 echo "ldappasswd failed ($RC)!"
264                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
265                 exit $RC
266         fi
267
268         echo -n "Testing bind with new secret... "
269         $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $NEWPW
270         RC=$?
271         if test $RC != 0 ; then
272                 echo "ldapwhoami failed ($RC)!"
273                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
274                 exit $RC
275         fi
276
277         BINDDN="cn=Some One,${BASEDN}"
278         BINDPW="someone"
279         echo -n "Testing bind with newly added user... "
280         $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
281         RC=$?
282         if test $RC != 0 ; then
283                 echo "ldapwhoami failed ($RC)!"
284                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
285                 exit $RC
286         fi
287
288         echo "Using ldapsearch to retrieve all the entries..."
289         $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" \
290                  "objectClass=*" > $SEARCHOUT 2>&1
291
292         RC=$?
293         if test $RC != 0 ; then
294                 echo "ldapsearch failed ($RC)!"
295                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
296                 exit $RC
297         fi
298
299         echo "Filtering ldapsearch results..."
300         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
301         echo "Filtering modified ldif..."
302         . $LDIFFILTER < $SQLWRITE > $LDIFFLT
303         echo "Comparing filter output..."
304         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
305
306         if test $? != 0 ; then
307                 echo "comparison failed - SQL mods search didn't succeed"
308                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
309                 exit 1
310         fi
311         ;;
312
313 *)
314         echo "apparently ${RDBMS} does not support writes; skipping..."
315         ;;
316 esac
317
318 test $KILLSERVERS != no && kill -HUP $KILLPIDS
319
320 echo ">>>>> Test succeeded"
321 exit 0
322