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