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