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