]> git.sur5r.net Git - openldap/blob - tests/scripts/test032-proxymassage
fix test after ldapmodify
[openldap] / tests / scripts / test032-proxymassage
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 $RWM = rwmno ; then 
20         echo "Rewrite/remap overlay not available, test skipped"
21         exit 0
22 fi 
23
24 if test $BACKLDAP = "ldapno" ; then 
25         echo "LDAP backend not available, test skipped"
26         exit 0
27 fi 
28
29 mkdir -p $TESTDIR $DBDIR1
30
31 echo "Starting slapd on TCP/IP port $PORT1..."
32 . $CONFFILTER $BACKEND $MONITORDB < $PROXYMASSAGECONF > $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 "Using ldapsearch to check that slapd is running..."
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 if test $RC != 0 ; then
53         echo "ldapsearch failed $(RC)!"
54         test $KILLSERVERS != no && kill -HUP $KILLPIDS
55         exit $RC
56 fi
57
58 echo "Using ldapadd to populate the database..."
59 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
60         $LDIFORDERED > $TESTOUT 2>&1
61 RC=$?
62 if test $RC != 0 ; then
63         echo "ldapadd failed ($RC)!"
64         test $KILLSERVERS != no && kill -HUP $KILLPIDS
65         exit $RC
66 fi
67
68 cat /dev/null > $SEARCHOUT
69
70 BASEDN="dc=example,dc=com"
71 echo "searching base=\"$BASEDN\"..."
72 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
73 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
74 RC=$?
75 if test $RC != 0 ; then
76         echo "Search failed ($RC)!"
77         test $KILLSERVERS != no && kill -HUP $KILLPIDS
78         exit $RC
79 fi
80
81 BASEDN="o=Example,c=US"
82 echo "searching base=\"$BASEDN\"..."
83 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
84 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
85 RC=$?
86 if test $RC != 0 ; then
87         echo "Search failed ($RC)!"
88         test $KILLSERVERS != no && kill -HUP $KILLPIDS
89         exit $RC
90 fi
91
92 BASEDN="o=Esempio,c=IT"
93 echo "searching base=\"$BASEDN\"..."
94 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
95 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
96 RC=$?
97 if test $RC != 0 ; then
98         echo "Search failed ($RC)!"
99         test $KILLSERVERS != no && kill -HUP $KILLPIDS
100         exit $RC
101 fi
102
103 BASEDN="o=Beispiel,c=DE"
104 echo "searching base=\"$BASEDN\"..."
105 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
106 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
107 RC=$?
108 if test $RC != 0 ; then
109         echo "Search failed ($RC)!"
110         test $KILLSERVERS != no && kill -HUP $KILLPIDS
111         exit $RC
112 fi
113
114 #
115 # Do some modifications
116 #
117
118 BASEDN="o=Beispiel,c=DE"
119 echo "modifying database \"$BASEDN\"..."
120 $LDAPMODIFY -v -D "cn=Manager,$BASEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
121         -e manageDSAit >> $TESTOUT 2>&1 << EOMODS
122 dn: cn=Added User,ou=Alumni Association,ou=People,$BASEDN
123 changetype: add
124 objectClass: OpenLDAPperson
125 cn: Added User
126 sn: User
127 uid: auser
128 seealso: cn=All Staff,ou=Groups,$BASEDN
129 homephone: +49 1234567890
130 drink: Beer
131 mail: auser@mail.alumni.example.com
132 telephonenumber: +49 1234-567-890
133 description: Just added in o=Beispiel,c=DE naming context
134
135 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
136 changetype: modify
137 add: seeAlso
138 seeAlso: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
139 -
140 add: description
141 description: Just added self to seeAlso in $BASEDN virtual naming context
142 -
143
144 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN
145 changetype: delete
146
147 dn: cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN
148 changetype: modrdn
149 newrdn: cn=John P. Doe
150 deleteoldrdn: 1
151
152 dn: cn=Jane Doe,ou=Alumni Association,ou=People,$BASEDN
153 changetype: modrdn
154 newrdn: cn=Jane Q. Doe
155 deleteoldrdn: 1
156 newsuperior: ou=Information Technology Division,ou=People,$BASEDN
157
158 dn: cn=Jane Q. Doe,ou=Information Technology Division,ou=People,$BASEDN
159 changetype: modify
160 add: cn
161 cn: Jane Qissapaolo Doe
162 -
163
164 dn: ou=Referrals,$BASEDN
165 changetype: add
166 objectclass: referral
167 objectclass: extensibleObject
168 ou: Referrals
169 ref: ldap://localhost.localdomain/ou=Referrals,$BASEDN
170 description: Just added as ldap://localhost.localdomain:389/ou=Referrals,$BASEDN
171
172 dn: ou=Referrals,$BASEDN
173 changetype: modify
174 replace: ref
175 ref: ldap://ldap.example.com:389/ou=Referrals,${BASEDN}
176 -
177 add: description
178 description: ...and modified as ldap://ldap.example.com:389/ou=Referrals,${BASEDN}
179 -
180 EOMODS
181
182 RC=$?
183 if test $RC != 0 ; then
184         echo "Modify failed ($RC)!"
185         test $KILLSERVERS != no && kill -HUP $KILLPIDS
186         exit $RC
187 fi
188
189 echo "searching base=\"$BASEDN\"..."
190 echo "# searching base=\"$BASEDN\"..."  >> $SEARCHOUT
191 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
192 RC=$?
193 if test $RC != 0 ; then
194         echo "Search failed ($RC)!"
195         test $KILLSERVERS != no && kill -HUP $KILLPIDS
196         exit $RC
197 fi
198
199 BASEDN="o=Esempio,c=IT"
200 echo "searching base=\"$BASEDN\"..."
201 echo "# searching base=\"$BASEDN\"..."  >> $SEARCHOUT
202 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
203 RC=$?
204 if test $RC != 0 ; then
205         echo "Search failed ($RC)!"
206         test $KILLSERVERS != no && kill -HUP $KILLPIDS
207         exit $RC
208 fi
209
210 FILTER="(objectClass=referral)"
211 echo "searching filter=\"$FILTER\""
212 echo "  attrs=\"'*' ref\""
213 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
214 echo "#         attrs=\"'*' ref\"" >> $SEARCHOUT
215
216 BASEDN="dc=example,dc=com"
217 echo "  base=\"$BASEDN\"..."
218 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
219 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
220         -e manageDSAit >> $SEARCHOUT 2>&1
221 RC=$?
222 if test $RC != 0 ; then
223         echo "Search failed ($RC)!"
224         test $KILLSERVERS != no && kill -HUP $KILLPIDS
225         exit $RC
226 fi
227
228 BASEDN="o=Example,c=US"
229 echo "  base=\"$BASEDN\"..."
230 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
231 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
232         -e manageDSAit >> $SEARCHOUT 2>&1
233 RC=$?
234 if test $RC != 0 ; then
235         echo "Search failed ($RC)!"
236         test $KILLSERVERS != no && kill -HUP $KILLPIDS
237         exit $RC
238 fi
239
240 BASEDN="o=Esempio,c=IT"
241 echo "  base=\"$BASEDN\"..."
242 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
243 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
244         -e manageDSAit >> $SEARCHOUT 2>&1
245 RC=$?
246 if test $RC != 0 ; then
247         echo "Search failed ($RC)!"
248         test $KILLSERVERS != no && kill -HUP $KILLPIDS
249         exit $RC
250 fi
251
252 BASEDN="o=Example,c=US"
253 FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
254 echo "searching filter=\"$FILTER\""
255 echo "  attrs=\"seeAlso\""
256 echo "  base=\"$BASEDN\"..."
257 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
258 echo "#         attrs=\"seeAlso\"" >> $SEARCHOUT
259 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
260 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" seeAlso \
261         >> $SEARCHOUT 2>&1
262 RC=$?
263 if test $RC != 0 ; then
264         echo "Search failed ($RC)!"
265         test $KILLSERVERS != no && kill -HUP $KILLPIDS
266         exit $RC
267 fi
268
269 echo "Filtering ldapsearch results..."
270 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
271 echo "Filtering original ldif used to create database..."
272 . $LDIFFILTER < $PROXYMASSAGEOUT > $LDIFFLT
273 echo "Comparing filter output..."
274 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
275         
276 if test $? != 0 ; then
277         echo "comparison failed - back-ldap search/modification didn't succeed"
278         test $KILLSERVERS != no && kill -HUP $KILLPIDS
279         exit 1
280 fi
281
282 BASEDN="o=Example,c=US"
283 echo "changing password to database \"$BASEDN\"..."
284 $LDAPPASSWD -h $LOCALHOST -p $PORT1 -D "cn=Manager,$BASEDN" -w $PASSWD \
285         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
286         -s $PASSWD >> $TESTOUT 2>&1
287 RC=$?
288 if test $RC != 0 ; then
289         echo "Passwd ExOp failed ($RC)!"
290         test $KILLSERVERS != no && kill -HUP $KILLPIDS
291         exit $RC
292 fi
293
294 BASEDN="o=Beispiel,c=DE"
295 echo "binding with newly changed password to database \"$BASEDN\"..."
296 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
297         -D "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
298         -w $PASSWD >> $TESTOUT 2>&1
299 RC=$?
300 if test $RC != 0 ; then
301         echo "WhoAmI failed ($RC)!"
302         test $KILLSERVERS != no && kill -HUP $KILLPIDS
303         exit $RC
304 fi
305
306 BASEDN="o=Esempio,c=IT"
307 echo "comparing to database \"$BASEDN\"..."
308 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
309         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
310         "seeAlso:cn=All Staff,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
311 RC=$?
312 if test $RC != 6 ; then
313         echo "Compare failed ($RC)!"
314         test $KILLSERVERS != no && kill -HUP $KILLPIDS
315         exit $RC
316 fi
317
318 test $KILLSERVERS != no && kill -HUP $KILLPIDS
319
320 echo ">>>>> Test succeeded"
321 exit 0
322