]> git.sur5r.net Git - openldap/blob - tests/scripts/test030-relay
56a41b7e514202f7f8728a392e7d4256c1e3b03f
[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 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
73 RC=$?
74 if test $RC != 0 ; then
75         echo "Search failed ($RC)!"
76         test $KILLSERVERS != no && kill -HUP $KILLPIDS
77         exit $RC
78 fi
79
80 BASEDN="o=Example,c=US"
81 echo "searching base=\"$BASEDN\"..."
82 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
83 RC=$?
84 if test $RC != 0 ; then
85         echo "Search failed ($RC)!"
86         test $KILLSERVERS != no && kill -HUP $KILLPIDS
87         exit $RC
88 fi
89
90 BASEDN="o=Esempio,c=IT"
91 echo "searching base=\"$BASEDN\"..."
92 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
93 RC=$?
94 if test $RC != 0 ; then
95         echo "Search failed ($RC)!"
96         test $KILLSERVERS != no && kill -HUP $KILLPIDS
97         exit $RC
98 fi
99
100 BASEDN="o=Beispiel,c=DE"
101 echo "searching base=\"$BASEDN\"..."
102 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
103 RC=$?
104 if test $RC != 0 ; then
105         echo "Search failed ($RC)!"
106         test $KILLSERVERS != no && kill -HUP $KILLPIDS
107         exit $RC
108 fi
109
110 #
111 # Do some modifications
112 #
113
114 BASEDN="o=Beispiel,c=DE"
115 echo "modifying database \"$BASEDN\"..."
116 $LDAPMODIFY -v -D "cn=Manager,$BASEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
117         -e manageDSAit >> $TESTOUT 2>&1 << EOMODS
118 dn: cn=Added User,ou=Alumni Association,ou=People,$BASEDN
119 changetype: add
120 objectClass: OpenLDAPperson
121 cn: Added User
122 sn: User
123 uid: auser
124 seealso: cn=All Staff,ou=Groups,$BASEDN
125 homephone: +49 1234567890
126 drink: Beer
127 mail: auser@mail.alumni.example.com
128 telephonenumber: +49 1234-567-890
129 description: Just added in o=Beispiel,c=DE naming context
130
131 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
132 changetype: modify
133 add: seeAlso
134 seeAlso: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
135 -
136 add: description
137 description: Just added self to seeAlso in $BASEDN virtual naming context
138 -
139
140 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN
141 changetype: delete
142
143 dn: cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN
144 changetype: modrdn
145 newrdn: cn=John P. Doe
146 deleteoldrdn: 1
147
148 dn: cn=Jane Doe,ou=Alumni Association,ou=People,$BASEDN
149 changetype: modrdn
150 newrdn: cn=Jane Q. Doe
151 deleteoldrdn: 1
152 newsuperior: ou=Information Technology Division,ou=People,$BASEDN
153
154 dn: ou=Referrals,$BASEDN
155 changetype: add
156 objectclass: referral
157 objectclass: extensibleObject
158 ou: Referrals
159 ref: ldap://localhost.localdomain/ou=Referrals,$BASEDN
160 description: Just added as ldap://localhost.localdomain/ou=Referrals,$BASEDN
161
162 dn: ou=Referrals,$BASEDN
163 changetype: modify
164 replace: ref
165 ref: ldap://ldap.example.com/ou=Referrals,$BASEDN
166 -
167 add: description
168 description: ...and modified as ldap://ldap.example.com/ou=Referrals,$BASEDN
169 -
170 EOMODS
171
172 if test $RC != 0 ; then
173         echo "Modify failed ($RC)!"
174         test $KILLSERVERS != no && kill -HUP $KILLPIDS
175         exit $RC
176 fi
177
178 BASEDN="o=Esempio,c=IT"
179 echo "searching base=\"$BASEDN\"..."
180 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
181 RC=$?
182 if test $RC != 0 ; then
183         echo "Search failed ($RC)!"
184         test $KILLSERVERS != no && kill -HUP $KILLPIDS
185         exit $RC
186 fi
187
188 FILTER="(objectClass=referral)"
189 echo "searching filter=\"$FILTER\""
190 echo "  attrs=\"'*' ref\""
191
192 BASEDN="dc=example,dc=com"
193 echo "  base=\"$BASEDN\"..."
194 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
195         -e manageDSAit >> $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 BASEDN="o=Example,c=US"
204 echo "  base=\"$BASEDN\"..."
205 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
206         -e manageDSAit >> $SEARCHOUT 2>&1
207 RC=$?
208 if test $RC != 0 ; then
209         echo "Search failed ($RC)!"
210         test $KILLSERVERS != no && kill -HUP $KILLPIDS
211         exit $RC
212 fi
213
214 BASEDN="o=Esempio,c=IT"
215 echo "  base=\"$BASEDN\"..."
216 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" "*" ref \
217         -e manageDSAit >> $SEARCHOUT 2>&1
218 RC=$?
219 if test $RC != 0 ; then
220         echo "Search failed ($RC)!"
221         test $KILLSERVERS != no && kill -HUP $KILLPIDS
222         exit $RC
223 fi
224
225 BASEDN="o=Example,c=US"
226 FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
227 echo "searching filter=\"$FILTER\""
228 echo "  attrs=\"seeAlso\""
229 echo "  base=\"$BASEDN\"..."
230 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" seeAlso \
231         >> $SEARCHOUT 2>&1
232 RC=$?
233 if test $RC != 0 ; then
234         echo "Search failed ($RC)!"
235         test $KILLSERVERS != no && kill -HUP $KILLPIDS
236         exit $RC
237 fi
238
239 echo "Filtering ldapsearch results..."
240 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
241 echo "Filtering original ldif used to create database..."
242 . $LDIFFILTER < $RELAYOUT > $LDIFFLT
243 echo "Comparing filter output..."
244 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
245         
246 if test $? != 0 ; then
247         echo "comparison failed - relay search/modification didn't succeed"
248         test $KILLSERVERS != no && kill -HUP $KILLPIDS
249         exit 1
250 fi
251
252 BASEDN="o=Example,c=US"
253 echo "changing password to database \"$BASEDN\"..."
254 $LDAPPASSWD -h $LOCALHOST -p $PORT1 -D "cn=Manager,$BASEDN" -w $PASSWD \
255         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
256         -s $PASSWD >> $TESTOUT 2>&1
257 RC=$?
258 if test $RC != 0 ; then
259         echo "Passwd ExOp failed ($RC)!"
260         test $KILLSERVERS != no && kill -HUP $KILLPIDS
261         exit $RC
262 fi
263
264 BASEDN="o=Beispiel,c=DE"
265 echo "binding with newly changed password to database \"$BASEDN\"..."
266 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
267         -D "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
268         -w $PASSWD >> $TESTOUT 2>&1
269 RC=$?
270 if test $RC != 0 ; then
271         echo "WhoAmI failed ($RC)!"
272         test $KILLSERVERS != no && kill -HUP $KILLPIDS
273         exit $RC
274 fi
275
276 BASEDN="o=Esempio,c=IT"
277 echo "comparing to database \"$BASEDN\"..."
278 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
279         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
280         "seeAlso:cn=All Staff,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
281 RC=$?
282 if test $RC != 6 ; then
283         echo "Compare failed ($RC)!"
284         test $KILLSERVERS != no && kill -HUP $KILLPIDS
285         exit $RC
286 fi
287
288 test $KILLSERVERS != no && kill -HUP $KILLPIDS
289
290 echo ">>>>> Test succeeded"
291 exit 0
292