]> git.sur5r.net Git - openldap/blob - tests/scripts/test029-ldapglue
Add missing 'kill -HUP $KILLPIDS' statement before an exit.
[openldap] / tests / scripts / test029-ldapglue
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 echo "### This test requires the ldap backend and glue overlay."
20 echo "### If available, and explicitly requested, it can use SASL bind;"
21 echo "### note that SASL must be properly set up, and the requested"
22 echo "### mechanism must be available.  Define SLAPD_USE_SASL={yes|<mech>},"
23 echo "### with \"yes\" defaulting to DIGEST-MD5 to enable SASL authc[/authz]."
24
25 if test $BACKLDAP = "ldapno" ; then 
26         echo "LDAP backend not available, test skipped"
27         exit 0
28 fi 
29
30 if test $WITH_SASL = "yes" ; then
31         if test $USE_SASL != "no" ; then
32                 if test $USE_SASL = "yes" ; then
33                         MECH="DIGEST-MD5"
34                 else
35                         MECH="$USE_SASL"
36                 fi
37                 echo "Using SASL authc[/authz] with mech=$MECH; unset SLAPD_USE_SASL to disable"
38         else
39                 echo "Using proxyAuthz with simple authc..."
40         fi
41 else
42         echo "SASL not available; using proxyAuthz with simple authc..."
43 fi
44
45 mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3
46
47 echo "Running slapadd to build slapd database..."
48 . $CONFFILTER $BACKEND $MONITORDB < $LDAPGLUECONF1 > $ADDCONF
49 $SLAPADD -f $ADDCONF -l $LDIFLDAPGLUE1
50 RC=$?
51 if test $RC != 0 ; then
52         echo "slapadd 1 failed ($RC)!"
53         exit $RC
54 fi
55
56 . $CONFFILTER $BACKEND $MONITORDB < $LDAPGLUECONF2 > $ADDCONF
57 $SLAPADD -f $ADDCONF -l $LDIFLDAPGLUE2
58 RC=$?
59 if test $RC != 0 ; then
60         echo "slapadd 2 failed ($RC)!"
61         exit $RC
62 fi
63
64 . $CONFFILTER $BACKEND $MONITORDB < $LDAPGLUECONF3 > $ADDCONF
65 $SLAPADD -f $ADDCONF -l $LDIFLDAPGLUE3
66 RC=$?
67 if test $RC != 0 ; then
68         echo "slapadd 3 failed ($RC)!"
69         exit $RC
70 fi
71
72 echo "Starting local slapd on TCP/IP port $PORT1..."
73 . $CONFFILTER $BACKEND $MONITORDB < $LDAPGLUECONF1 > $CONF1
74 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
75 PID1=$!
76 if test $WAIT != 0 ; then
77     echo PID $PID1
78     read foo
79 fi
80
81 echo "Starting remote slapd 1 on TCP/IP port $PORT2..."
82 . $CONFFILTER $BACKEND $MONITORDB < $LDAPGLUECONF2 > $CONF2
83 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
84 PID2=$!
85 if test $WAIT != 0 ; then
86     echo PID $PID2
87     read foo
88 fi
89
90 echo "Starting remote slapd 2 on TCP/IP port $PORT3..."
91 . $CONFFILTER $BACKEND $MONITORDB < $LDAPGLUECONF3 > $CONF3
92 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
93 PID3=$!
94 if test $WAIT != 0 ; then
95     echo PID $PID3
96     read foo
97 fi
98 KILLPIDS="$PID1 $PID2 $PID3"
99
100 echo "Using ldapsearch to check that slapd is running..."
101 for i in 0 1 2 3 4 5; do
102         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
103                 'objectclass=*' > /dev/null 2>&1
104         RC=$?
105         if test $RC = 0 ; then
106                 break
107         fi
108         echo "Waiting 5 seconds for slapd to start..."
109         sleep 5
110 done
111
112 echo "Using ldapsearch to check that slapd is running..."
113 for i in 0 1 2 3 4 5; do
114         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
115                 'objectclass=*' > /dev/null 2>&1
116         RC=$?
117         if test $RC = 0 ; then
118                 break
119         fi
120         echo "Waiting 5 seconds for slapd to start..."
121         sleep 5
122 done
123
124 echo "Using ldapsearch to check that slapd is running..."
125 for i in 0 1 2 3 4 5; do
126         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
127                 'objectclass=*' > /dev/null 2>&1
128         RC=$?
129         if test $RC = 0 ; then
130                 break
131         fi
132         echo "Waiting 5 seconds for slapd to start..."
133         sleep 5
134 done
135
136 ID="uid=bjorn,ou=People,dc=example,dc=com"
137 BASE="dc=example,dc=com"
138 echo "Testing ldapsearch as $ID for \"$BASE\"..."
139 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
140         -D "$ID" -w bjorn > $SEARCHOUT 2>&1
141
142 RC=$?
143 if test $RC != 0 ; then
144         echo "ldapsearch failed ($RC)!"
145         test $KILLSERVERS != no && kill -HUP $KILLPIDS
146         exit $RC
147 fi
148
149 echo "Filtering ldapsearch results..."
150 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
151 echo "Filtering original ldif used to create database..."
152 . $LDIFFILTER < $LDAPGLUEOUT > $LDIFFLT
153 echo "Comparing filter output..."
154 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
155         
156 if test $? != 0 ; then
157         echo "comparison failed - glued search with identity assertion didn't succeed"
158         test $KILLSERVERS != no && kill -HUP $KILLPIDS
159         exit 1
160 fi
161
162 BASE="dc=example,dc=com"
163 echo "Testing ldapsearch as anonymous for \"$BASE\"..."
164 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
165          > $SEARCHOUT 2>&1
166
167 RC=$?
168 if test $RC != 0 ; then
169         echo "ldapsearch failed ($RC)!"
170         test $KILLSERVERS != no && kill -HUP $KILLPIDS
171         exit $RC
172 fi
173
174 echo "Filtering ldapsearch results..."
175 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
176 echo "Filtering original ldif used to create database..."
177 . $LDIFFILTER < $LDAPGLUEANONYMOUSOUT > $LDIFFLT
178 echo "Comparing filter output..."
179 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
180         
181 if test $? != 0 ; then
182         echo "comparison failed - anonymous glued search with identity assertion didn't succeed"
183         test $KILLSERVERS != no && kill -HUP $KILLPIDS
184         exit 1
185 fi
186
187 # FIXME: this cannot work as is, because SASL bind cannot be proxied!
188 if test $USE_SASL != "no" ; then
189         ID="bjorn"
190         BASE="dc=example,dc=com"
191         echo "Testing ldapsearch as $ID for \"$BASE\" with SASL bind and identity assertion..."
192         $LDAPSASLSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
193                 -Q -U "$ID" -w bjorn -Y $MECH > $SEARCHOUT 2>&1
194
195         RC=$?
196         if test $RC != 0 ; then
197                 echo "ldapsearch failed ($RC)!"
198                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
199                 exit $RC
200         fi
201
202         echo "Filtering ldapsearch results..."
203         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
204         echo "Filtering original ldif used to create database..."
205         . $LDIFFILTER < $LDAPGLUEOUT > $LDIFFLT
206         echo "Comparing filter output..."
207         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
208         
209         if test $? != 0 ; then
210                 echo "comparison failed - glued search with SASL bind and identity assertion didn't succeed"
211                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
212                 exit 1
213         fi
214 fi
215
216 test $KILLSERVERS != no && kill -HUP $KILLPIDS
217
218 echo ">>>>> Test succeeded"
219 exit 0
220