]> git.sur5r.net Git - openldap/blob - tests/scripts/test032-chain
b6eb6b8dc58f3922cf8317c263da3b4afc945c5a
[openldap] / tests / scripts / test032-chain
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2017 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 $BACKLDAP = "ldapno" ; then 
20         echo "LDAP backend not available, test skipped"
21         exit 0
22 fi 
23
24 rm -rf $TESTDIR
25
26 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
27
28 echo "Running slapadd to build slapd database..."
29 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $ADDCONF
30 . $CONFFILTER < $LDIFCHAIN1 > $SEARCHOUT
31 $SLAPADD -f $ADDCONF -l $SEARCHOUT
32 RC=$?
33 if test $RC != 0 ; then
34         echo "slapadd 1 failed ($RC)!"
35         exit $RC
36 fi
37
38 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $ADDCONF
39 . $CONFFILTER < $LDIFCHAIN2 > $SEARCHOUT
40 $SLAPADD -f $ADDCONF -l $SEARCHOUT
41 RC=$?
42 if test $RC != 0 ; then
43         echo "slapadd 2 failed ($RC)!"
44         exit $RC
45 fi
46
47 echo "Starting first slapd on TCP/IP port $PORT1..."
48 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $CONF1
49 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
50 PID1=$!
51 if test $WAIT != 0 ; then
52     echo PID $PID1
53     read foo
54 fi
55 KILLPIDS="$PID1"
56
57 echo "Starting second slapd on TCP/IP port $PORT2..."
58 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $CONF2
59 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
60 PID2=$!
61 if test $WAIT != 0 ; then
62     echo PID $PID2
63     read foo
64 fi
65
66 KILLPIDS="$KILLPIDS $PID2"
67
68 sleep 1
69
70 echo "Using ldapsearch to check that first slapd is running..."
71 for i in 0 1 2 3 4 5; do
72         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
73                 'objectclass=*' > /dev/null 2>&1
74         RC=$?
75         if test $RC = 0 ; then
76                 break
77         fi
78         echo "Waiting 5 seconds for slapd to start..."
79         sleep 5
80 done
81
82 if test $RC != 0 ; then
83         echo "ldapsearch failed ($RC)!"
84         test $KILLSERVERS != no && kill -HUP $KILLPIDS
85         exit $RC
86 fi
87
88 echo "Using ldapsearch to check that second slapd is running..."
89 for i in 0 1 2 3 4 5; do
90         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
91                 'objectclass=*' > /dev/null 2>&1
92         RC=$?
93         if test $RC = 0 ; then
94                 break
95         fi
96         echo "Waiting 5 seconds for slapd to start..."
97         sleep 5
98 done
99
100 if test $RC != 0 ; then
101         echo "ldapsearch failed ($RC)!"
102         test $KILLSERVERS != no && kill -HUP $KILLPIDS
103         exit $RC
104 fi
105
106 for P in $PORT1 $PORT2 ; do
107         echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
108         $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
109                  > $SEARCHOUT 2>&1
110
111         RC=$?
112         if test $RC != 0 ; then
113                 echo "ldapsearch failed ($RC)!"
114                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
115                 exit $RC
116         fi
117
118         echo "Filtering ldapsearch results..."
119         $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
120         echo "Filtering original ldif used to create database..."
121         $LDIFFILTER < $CHAINOUT > $LDIFFLT
122         echo "Comparing filter output..."
123         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
124         
125         if test $? != 0 ; then
126                 echo "comparison failed - chained search didn't succeed"
127                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
128                 exit 1
129         fi
130
131         echo "Reading the referral entry \"ou=Other,$BASEDN\" as anonymous on port $P..."
132         $LDAPSEARCH -h $LOCALHOST -p $P -b "ou=Other,$BASEDN" -S "" \
133                  > $SEARCHOUT 2>&1
134
135         RC=$?
136         if test $RC != 0 ; then
137                 echo "ldapsearch failed ($RC)!"
138                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
139                 exit $RC
140         fi
141
142         echo "Filtering ldapsearch results..."
143         $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
144         echo "Filtering original ldif used to create database..."
145         $LDIFFILTER < $CHAINREFOUT > $LDIFFLT
146         echo "Comparing filter output..."
147         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
148                 
149         if test $? != 0 ; then
150                 echo "comparison failed - chained search didn't succeed"
151                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
152                 exit 1
153         fi
154
155         DN="cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN"
156         echo "Comparing \"$DN\" on port $P..."
157         $LDAPCOMPARE -h $LOCALHOST -p $P "$DN" "cn:Mark Elliot" \
158                  > $TESTOUT 2>&1
159
160         RC=$?
161         if test $RC != 6 && test $RC,$BACKEND != 5,null ; then
162                 echo "ldapcompare failed ($RC)!"
163                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
164                 exit 1
165         fi
166
167         DN="ou=Other,$BASEDN"
168         echo "Comparing \"$DN\" on port $P with manageDSAit control..."
169         $LDAPCOMPARE -h $LOCALHOST -p $P -M "$DN" "ou:Other" \
170                  > $TESTOUT 2>&1
171
172         RC=$?
173         if test $RC != 6 && test $RC,$BACKEND != 5,null ; then
174                 echo "ldapcompare failed ($RC)!"
175                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
176                 exit 1
177         fi
178 done
179
180 #
181 # Testing writes to first server
182 #
183 echo "Writing to first server with scope on second server..."
184 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
185         $TESTOUT 2>&1 << EOMODS
186 dn: cn=New Group,ou=Groups,dc=example,dc=com
187 changetype: add
188 objectClass: groupOfNames
189 cn: New Group
190 member:
191
192 dn: cn=New Group,ou=Groups,dc=example,dc=com
193 changetype: modify
194 add: description
195 description: testing chain overlay writes...
196 -
197 replace: member
198 member: cn=New Group,ou=Groups,dc=example,dc=com
199 member: cn=Manager,dc=example,dc=com
200 -
201 add: owner
202 owner: cn=Manager,dc=example,dc=com
203 -
204
205 dn: cn=New Group,ou=Groups,dc=example,dc=com
206 changetype: modrdn
207 newrdn: cn=Renamed Group
208 deleteoldrdn: 1
209
210 dn: cn=All Staff,ou=Groups,dc=example,dc=com
211 changetype: delete
212 EOMODS
213
214 RC=$?
215 if test $RC != 0 ; then
216         echo "ldapmodify failed ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219 fi
220
221 #
222 # Testing writes to second server
223 #
224 echo "Writing to second server with scope on first server..."
225 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
226         $TESTOUT 2>&1 << EOMODS
227 dn: cn=New User,ou=People,dc=example,dc=com
228 changetype: add
229 objectClass: person
230 cn: New User
231 sn: User
232 seeAlso: cn=New Group,ou=Groups,dc=example,dc=com
233
234 dn: cn=New User,ou=People,dc=example,dc=com
235 changetype: modify
236 add: description
237 description: testing chain overlay writes...
238 -
239 replace: seeAlso
240 seeAlso: cn=Renamed Group,ou=Groups,dc=example,dc=com
241 -
242
243 dn: cn=New User,ou=People,dc=example,dc=com
244 changetype: modrdn
245 newrdn: cn=Renamed User
246 deleteoldrdn: 1
247
248 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com
249 changetype: delete
250 EOMODS
251
252 RC=$?
253 if test $RC != 0 ; then
254         echo "ldapmodify failed ($RC)!"
255         test $KILLSERVERS != no && kill -HUP $KILLPIDS
256         exit $RC
257 fi
258
259 for P in $PORT1 $PORT2 ; do
260         echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
261         $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
262                  > $SEARCHOUT 2>&1
263
264         RC=$?
265         if test $RC != 0 ; then
266                 echo "ldapsearch failed ($RC)!"
267                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
268                 exit $RC
269         fi
270
271         echo "Filtering ldapsearch results..."
272         $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
273         echo "Filtering original ldif used to create database..."
274         $LDIFFILTER < $CHAINMODOUT > $LDIFFLT
275         echo "Comparing filter output..."
276         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
277         
278         if test $? != 0 ; then
279                 echo "comparison failed - chained search didn't succeed"
280                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
281                 exit 1
282         fi
283 done
284
285 NEWPW=newsecret
286 echo "Using ldappasswd on second server with scope on first server..."
287 $LDAPPASSWD -h $LOCALHOST -p $PORT2 \
288         -w secret -s $NEWPW \
289         -D "$MANAGERDN" "$BJORNSDN" >> $TESTOUT 2>&1
290 RC=$?
291 if test $RC != 0 ; then
292         echo "ldappasswd failed ($RC)!"
293         test $KILLSERVERS != no && kill -HUP $KILLPIDS
294         exit $RC
295 fi
296
297 echo "Binding with newly changed password on first server..."
298 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
299         -D "$BJORNSDN" -w $NEWPW
300 RC=$?
301 if test $RC != 0 ; then
302         echo "ldapwhoami failed ($RC)!"
303         test $KILLSERVERS != no && kill -HUP $KILLPIDS
304         exit $RC
305 fi
306
307 # ITS#57??
308 $LDAPADD -h $LOCALHOST -p $PORT1 \
309         -D "$MANAGERDN" -w secret \
310         >> $TESTOUT 2>&1 \
311         << EOMODS
312 dn: ou=Can't Contact,dc=example,dc=com
313 changetype: add
314 objectclass: referral
315 objectclass: extensibleobject
316 ou: Can't Contact
317 # invalid URI to test broken connectivity handling (search only)
318 ref: ${URI3}ou=Can't%20Contact,dc=example,dc=com
319 EOMODS
320
321 echo "Reading the referral entry \"ou=Can't Contact,$BASEDN\" as anonymous on port $PORT1..."
322 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=Can't Contact)" \
323          > $SEARCHOUT 2>&1
324
325 RC=$?
326 if test $RC != 0 ; then
327         echo "ldapsearch failed ($RC)!"
328         test $KILLSERVERS != no && kill -HUP $KILLPIDS
329         exit $RC
330 fi
331
332 test $KILLSERVERS != no && kill -HUP $KILLPIDS
333
334 echo ">>>>> Test succeeded"
335
336 test $KILLSERVERS != no && wait
337
338 exit 0