Debian Codegraph @

tests/scripts/lloadd/test006-sasl

raw
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2024 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 $WITH_SASL = "yes" ; then
20 if test $USE_SASL = "no" ; then
21 echo "Not asked to test SASL, skipping test, set SLAPD_USE_SASL to enable..."
22 exit 0
23 fi
24 if test $USE_SASL = "yes" ; then
25 MECH="SCRAM-SHA-256"
26 else
27 MECH="$USE_SASL"
28 fi
29 echo "Using SASL authc[/authz] with mech=$MECH; unset SLAPD_USE_SASL to disable"
30 else
31 echo "SASL support not available, test skipped"
32 exit 0
33 fi
34
35 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
36 cp -r $DATADIR/tls $TESTDIR
37
38 cd $TESTWD
39
40 $SLAPPASSWD -g -n >$CONFIGPWF
41 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
42
43 echo "Running slapadd to build slapd database..."
44 . $CONFFILTER $BACKEND < $TLSSASLCONF > $CONF2
45 echo 'authz-regexp "^uid=([^,]*),.+" ldap:///dc=example,dc=com??sub?(|(cn=$1)(uid=$1))' >>$CONF2
46 $SLAPADD -f $CONF2 -l $LDIFORDERED
47 RC=$?
48 if test $RC != 0 ; then
49 echo "slapadd failed ($RC)!"
50 exit $RC
51 fi
52
53 echo "Starting a slapd on TCP/IP port $PORT2..."
54 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
55 PID=$!
56 if test $WAIT != 0 ; then
57 echo PID $PID
58 read foo
59 fi
60 PID2="$PID"
61 KILLPIDS="$PID"
62
63 for i in 0 1 2 3 4 5; do
64 $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
65 '(objectclass=*)' > /dev/null 2>&1
66 RC=$?
67 if test $RC = 0 ; then
68 break
69 fi
70 echo "Waiting $SLEEP1 seconds for slapd to start..."
71 sleep $SLEEP1
72 done
73 if test $RC != 0 ; then
74 echo "ldapsearch failed ($RC)!"
75 test $KILLSERVERS != no && kill -HUP $KILLPIDS
76 exit $RC
77 fi
78
79 echo "Running slapadd to build slapd database..."
80 . $CONFFILTER $BACKEND < $CONFTWO > $CONF3
81 echo 'authz-regexp "^uid=([^,]*),.+" ldap:///dc=example,dc=com??sub?(|(cn=$1)(uid=$1))' >>$CONF3
82 $SLAPADD -f $CONF3 -l $LDIFORDERED
83 RC=$?
84 if test $RC != 0 ; then
85 echo "slapadd failed ($RC)!"
86 test $KILLSERVERS != no && kill -HUP $KILLPIDS
87 exit $RC
88 fi
89
90 echo "Running slapindex to index slapd database..."
91 $SLAPINDEX -f $CONF3
92 RC=$?
93 if test $RC != 0 ; then
94 echo "warning: slapindex failed ($RC)"
95 echo " assuming no indexing support"
96 fi
97
98 echo "Starting second slapd on TCP/IP port $PORT3..."
99 $SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
100 PID=$!
101 if test $WAIT != 0 ; then
102 echo PID $PID
103 read foo
104 fi
105 PID2="$PID"
106 KILLPIDS="$KILLPIDS $PID"
107
108 sleep $SLEEP0
109
110 echo "Testing slapd searching..."
111 for i in 0 1 2 3 4 5; do
112 $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
113 '(objectclass=*)' > /dev/null 2>&1
114 RC=$?
115 if test $RC = 0 ; then
116 break
117 fi
118 echo "Waiting $SLEEP1 seconds for slapd to start..."
119 sleep $SLEEP1
120 done
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 "Starting lloadd on TCP/IP port $PORT1..."
128 . $CONFFILTER $BACKEND < $LLOADDSASLCONF > $CONF1.lloadd
129 if test $AC_lloadd = lloaddyes; then
130 $LLOADD -f $CONF1.lloadd -h $URI1 -d $LVL > $LOG1 2>&1 &
131 else
132 . $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd
133 $SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 &
134 fi
135 PID=$!
136 if test $WAIT != 0 ; then
137 echo PID $PID
138 read foo
139 fi
140 KILLPIDS="$KILLPIDS $PID"
141
142 echo "Testing lloadd searching..."
143 for i in 0 1 2 3 4 5; do
144 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
145 '(objectclass=*)' > /dev/null 2>&1
146 RC=$?
147 if test $RC = 0 ; then
148 break
149 fi
150 echo "Waiting $SLEEP1 seconds for lloadd to start..."
151 sleep $SLEEP1
152 done
153
154 if test $RC != 0 ; then
155 echo "ldapsearch failed ($RC)!"
156 test $KILLSERVERS != no && kill -HUP $KILLPIDS
157 exit $RC
158 fi
159
160 echo "Checking whether $MECH is supported..."
161 $LDAPSEARCH -s base -b "" -H $URI1 \
162 'objectClass=*' supportedSASLMechanisms > $SEARCHOUT 2>&1
163 RC=$?
164 if test $RC != 0 ; then
165 echo "ldapsearch failed ($RC)!"
166 test $KILLSERVERS != no && kill -HUP $KILLPIDS
167 exit $RC
168 fi
169
170 grep "supportedSASLMechanisms: $MECH" $SEARCHOUT > $TESTOUT
171 RC=$?
172 if test $RC != 0 ; then
173 echo "SASL mechanism $MECH is not available, test skipped"
174 test $KILLSERVERS != no && kill -HUP $KILLPIDS
175 exit 0
176 fi
177
178 AUTHZID="u:bjorn"
179 echo "Testing lloadd's identity can assert any authzid..."
180 $LDAPWHOAMI -D "$MANAGERDN" -H $URI1 -w $PASSWD \
181 -e\!"authzid=$AUTHZID" > $TESTOUT 2>&1
182 RC=$?
183 if test $RC != 0 ; then
184 echo "ldapwhoami failed ($RC)!"
185 test $KILLSERVERS != no && kill -HUP $KILLPIDS
186 exit $RC
187 fi
188
189 AUTHZID="u:bjorn"
190 echo "Testing a different identity cannot do the same thing..."
191 $LDAPWHOAMI -D "$BABSDN" -H $URI1 -w bjensen \
192 -e\!"authzid=$AUTHZID" >> $TESTOUT 2>/dev/null
193 RC=$?
194 if test $RC != 1 ; then
195 echo "ldapwhoami failed ($RC)!"
196 test $KILLSERVERS != no && kill -HUP $KILLPIDS
197 exit $RC
198 fi
199
200 echo "Validating WhoAmI? results..."
201 echo 'dn:cn=bjorn jensen,ou=information technology division,ou=people,dc=example,dc=com' > $TESTDIR/whoami.out
202 echo 'Result: Protocol error (2)
203 Additional info: proxy authorization control specified multiple times' >> $TESTDIR/whoami.out
204 $CMP $TESTDIR/whoami.out $TESTOUT > $CMPOUT
205
206 RC=$?
207 if test $RC != 0 ; then
208 echo "Comparison failed"
209 test $KILLSERVERS != no && kill -HUP $KILLPIDS
210 exit $RC
211 else
212 echo "Success"
213 fi
214
215
216 ID="jaj"
217 echo "Testing ldapsearch as $ID for \"$BASEDN\" with SASL bind and identity assertion..."
218 $LDAPSASLSEARCH -H $URI1 -b "$BASEDN" \
219 -Q -Y $MECH -O maxbufsize=0 -U "$ID" -w jaj > $SEARCHOUT 2>&1
220
221 RC=$?
222 if test $RC != 0 ; then
223 echo "ldapsearch failed ($RC)!"
224 test $KILLSERVERS != no && kill -HUP $KILLPIDS
225 exit $RC
226 fi
227
228 echo "Filtering ldapsearch results..."
229 $LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
230 echo "Filtering original ldif used to create database..."
231 $LDIFFILTER -s e < $LDIF > $LDIFFLT
232 echo "Comparing filter output..."
233 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
234
235 if test $? != 0 ; then
236 echo "comparison failed - search with SASL bind and identity assertion didn't succeed"
237 test $KILLSERVERS != no && kill -HUP $KILLPIDS
238 exit 1
239 fi
240
241 test $KILLSERVERS != no && kill -HUP $KILLPIDS
242
243 if test $RC != 0 ; then
244 echo ">>>>> Test failed"
245 else
246 echo ">>>>> Test succeeded"
247 RC=0
248 fi
249
250 test $KILLSERVERS != no && wait
251
252 exit $RC