]> git.sur5r.net Git - openldap/blob - tests/scripts/test030-relay
3d89fe0823edb60aabc7350c77e0a8cbdaad1fd1
[openldap] / tests / scripts / test030-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 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $BACKRELAY = relayno ; then 
20         echo "relay backend not available, test skipped"
21         exit 0
22 fi 
23
24 if test $RWM = rwmno ; then 
25         echo "Rewrite/remap overlay 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 < $RWMCONF > $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: 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/ou=Referrals,$BASEDN
165
166 dn: ou=Referrals,$BASEDN
167 changetype: modify
168 replace: ref
169 ref: ldap://ldap.example.com/ou=Referrals,$BASEDN
170 -
171 add: description
172 description: ...and modified as ldap://ldap.example.com/ou=Referrals,$BASEDN
173 -
174 EOMODS
175
176 if test $RC != 0 ; then
177         echo "Modify failed ($RC)!"
178         test $KILLSERVERS != no && kill -HUP $KILLPIDS
179         exit $RC
180 fi
181
182 echo "searching base=\"$BASEDN\"..."
183 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
184 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
185 RC=$?
186 if test $RC != 0 ; then
187         echo "Search failed ($RC)!"
188         test $KILLSERVERS != no && kill -HUP $KILLPIDS
189         exit $RC
190 fi
191
192 BASEDN="o=Esempio,c=IT"
193 echo "searching base=\"$BASEDN\"..."
194 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
195 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
196 RC=$?
197 if test $RC != 0 ; then
198         echo "Search failed ($RC)!"
199         test $KILLSERVERS != no && kill -HUP $KILLPIDS
200         exit $RC
201 fi
202
203 FILTER="(objectClass=referral)"
204 echo "searching filter=\"$FILTER\""
205 echo "  attrs=\"'*' ref\""
206
207 BASEDN="dc=example,dc=com"
208 echo "  base=\"$BASEDN\"..."
209 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
210 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
211         -e manageDSAit >> $SEARCHOUT 2>&1
212 RC=$?
213 if test $RC != 0 ; then
214         echo "Search failed ($RC)!"
215         test $KILLSERVERS != no && kill -HUP $KILLPIDS
216         exit $RC
217 fi
218
219 BASEDN="o=Example,c=US"
220 echo "  base=\"$BASEDN\"..."
221 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
222 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
223         -e manageDSAit >> $SEARCHOUT 2>&1
224 RC=$?
225 if test $RC != 0 ; then
226         echo "Search failed ($RC)!"
227         test $KILLSERVERS != no && kill -HUP $KILLPIDS
228         exit $RC
229 fi
230
231 BASEDN="o=Esempio,c=IT"
232 echo "  base=\"$BASEDN\"..."
233 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
234 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
235         -e manageDSAit >> $SEARCHOUT 2>&1
236 RC=$?
237 if test $RC != 0 ; then
238         echo "Search failed ($RC)!"
239         test $KILLSERVERS != no && kill -HUP $KILLPIDS
240         exit $RC
241 fi
242
243 BASEDN="o=Example,c=US"
244 FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
245 echo "searching filter=\"$FILTER\""
246 echo "  attrs=\"seeAlso\""
247 echo "  base=\"$BASEDN\"..."
248 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
249 echo "#         attrs=\"seeAlso\"" >> $SEARCHOUT
250 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
251 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" seeAlso \
252         >> $SEARCHOUT 2>&1
253 RC=$?
254 if test $RC != 0 ; then
255         echo "Search failed ($RC)!"
256         test $KILLSERVERS != no && kill -HUP $KILLPIDS
257         exit $RC
258 fi
259
260 echo "Filtering ldapsearch results..."
261 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
262 echo "Filtering original ldif used to create database..."
263 . $LDIFFILTER < $RELAYOUT > $LDIFFLT
264 echo "Comparing filter output..."
265 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
266         
267 if test $? != 0 ; then
268         echo "comparison failed - relay search/modification didn't succeed"
269         test $KILLSERVERS != no && kill -HUP $KILLPIDS
270         exit 1
271 fi
272
273 BASEDN="o=Example,c=US"
274 echo "changing password to database \"$BASEDN\"..."
275 $LDAPPASSWD -h $LOCALHOST -p $PORT1 -D "cn=Manager,$BASEDN" -w $PASSWD \
276         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
277         -s $PASSWD >> $TESTOUT 2>&1
278 RC=$?
279 if test $RC != 0 ; then
280         echo "Passwd ExOp failed ($RC)!"
281         test $KILLSERVERS != no && kill -HUP $KILLPIDS
282         exit $RC
283 fi
284
285 BASEDN="o=Beispiel,c=DE"
286 echo "binding with newly changed password to database \"$BASEDN\"..."
287 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
288         -D "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
289         -w $PASSWD >> $TESTOUT 2>&1
290 RC=$?
291 if test $RC != 0 ; then
292         echo "WhoAmI failed ($RC)!"
293         test $KILLSERVERS != no && kill -HUP $KILLPIDS
294         exit $RC
295 fi
296
297 BASEDN="o=Esempio,c=IT"
298 echo "comparing to database \"$BASEDN\"..."
299 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
300         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
301         "seeAlso:cn=All Staff,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
302 RC=$?
303 if test $RC != 6 ; then
304         echo "Compare failed ($RC)!"
305         test $KILLSERVERS != no && kill -HUP $KILLPIDS
306         exit $RC
307 fi
308
309 test $KILLSERVERS != no && kill -HUP $KILLPIDS
310
311 echo ">>>>> Test succeeded"
312 exit 0
313