]> git.sur5r.net Git - openldap/blob - tests/scripts/test032-chain
de27ec0fce855c383982382ac3fc599630eb6534
[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 echo "Using ldapsearch to check that first slapd is running..."
66 for i in 0 1 2 3 4 5; do
67         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
68                 'objectclass=*' > /dev/null 2>&1
69         RC=$?
70         if test $RC = 0 ; then
71                 break
72         fi
73         echo "Waiting 5 seconds for slapd to start..."
74         sleep 5
75 done
76
77 echo "Using ldapsearch to check that second slapd is running..."
78 for i in 0 1 2 3 4 5; do
79         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
80                 'objectclass=*' > /dev/null 2>&1
81         RC=$?
82         if test $RC = 0 ; then
83                 break
84         fi
85         echo "Waiting 5 seconds for slapd to start..."
86         sleep 5
87 done
88
89 for P in $PORT1 $PORT2 ; do
90         echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
91         $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
92                  > $SEARCHOUT 2>&1
93
94         RC=$?
95         if test $RC != 0 ; then
96                 echo "ldapsearch failed ($RC)!"
97                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
98                 exit $RC
99         fi
100
101         echo "Filtering ldapsearch results..."
102         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
103         echo "Filtering original ldif used to create database..."
104         . $LDIFFILTER < $CHAINOUT > $LDIFFLT
105         echo "Comparing filter output..."
106         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
107         
108         if test $? != 0 ; then
109                 echo "comparison failed - chained search didn't succeed"
110                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
111                 exit 1
112         fi
113 done
114
115 #
116 # Testing writes to first server
117 #
118 echo "Writing to first server with scope on second server..."
119 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
120         $TESTOUT 2>&1 << EOMODS
121 dn: cn=New Group,ou=Groups,dc=example,dc=com
122 changetype: add
123 objectClass: groupOfNames
124 cn: New Group
125 member:
126
127 dn: cn=New Group,ou=Groups,dc=example,dc=com
128 changetype: modify
129 add: description
130 description: testing chain overlay writes...
131 -
132 replace: member
133 member: cn=New Group,ou=Groups,dc=example,dc=com
134 member: cn=Manager,dc=example,dc=com
135 -
136 add: owner
137 owner: cn=Manager,dc=example,dc=com
138 -
139
140 dn: cn=New Group,ou=Groups,dc=example,dc=com
141 changetype: modrdn
142 newrdn: cn=Renamed Group
143 deleteoldrdn: 1
144
145 dn: cn=All Staff,ou=Groups,dc=example,dc=com
146 changetype: delete
147 EOMODS
148
149 RC=$?
150 if test $RC != 0 ; then
151         echo "ldapmodify failed ($RC)!"
152         test $KILLSERVERS != no && kill -HUP $KILLPIDS
153         exit $RC
154 fi
155
156 #
157 # Testing writes to second server
158 #
159 echo "Writing to second server with scope on first server..."
160 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
161         $TESTOUT 2>&1 << EOMODS
162 dn: cn=New User,ou=People,dc=example,dc=com
163 changetype: add
164 objectClass: person
165 cn: New User
166 sn: User
167 seeAlso: cn=New Group,ou=Groups,dc=example,dc=com
168
169 dn: cn=New User,ou=People,dc=example,dc=com
170 changetype: modify
171 add: description
172 description: testing chain overlay writes...
173 -
174 replace: seeAlso
175 seeAlso: cn=Renamed Group,ou=Groups,dc=example,dc=com
176 -
177
178 dn: cn=New User,ou=People,dc=example,dc=com
179 changetype: modrdn
180 newrdn: cn=Renamed User
181 deleteoldrdn: 1
182
183 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com
184 changetype: delete
185 EOMODS
186
187 RC=$?
188 if test $RC != 0 ; then
189         echo "ldapmodify failed ($RC)!"
190         test $KILLSERVERS != no && kill -HUP $KILLPIDS
191         exit $RC
192 fi
193
194 for P in $PORT1 $PORT2 ; do
195         echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
196         $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
197                  > $SEARCHOUT 2>&1
198
199         RC=$?
200         if test $RC != 0 ; then
201                 echo "ldapsearch failed ($RC)!"
202                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
203                 exit $RC
204         fi
205
206         echo "Filtering ldapsearch results..."
207         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
208         echo "Filtering original ldif used to create database..."
209         . $LDIFFILTER < $CHAINMODOUT > $LDIFFLT
210         echo "Comparing filter output..."
211         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
212         
213         if test $? != 0 ; then
214                 echo "comparison failed - chained search didn't succeed"
215                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
216                 exit 1
217         fi
218 done
219
220 NEWPW=newsecret
221 echo "Using ldappasswd on second server with scope on first server..."
222 $LDAPPASSWD -h $LOCALHOST -p $PORT2 \
223         -w secret -s $NEWPW \
224         -D "$MANAGERDN" "$BJORNSDN" >> $TESTOUT 2>&1
225 RC=$?
226 if test $RC != 0 ; then
227         echo "ldappasswd failed ($RC)!"
228         test $KILLSERVERS != no && kill -HUP $KILLPIDS
229         exit $RC
230 fi
231
232 echo "Binding with newly changed password on first server..."
233 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
234         -D "$BJORNSDN" -w $NEWPW
235 RC=$?
236 if test $RC != 0 ; then
237         echo "ldapwhoami failed ($RC)!"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS
239         exit $RC
240 fi
241
242 test $KILLSERVERS != no && kill -HUP $KILLPIDS
243
244 echo ">>>>> Test succeeded"
245 exit 0
246