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