]> git.sur5r.net Git - openldap/blob - tests/scripts/test014-whoami
e0339031e2feb7df0ffc09169a620945f6d8a392
[openldap] / tests / scripts / test014-whoami
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 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $WHOAMICONF > $ADDCONF
23 $SLAPADD -f $ADDCONF -l $LDIFWHOAMI
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Starting slapd on TCP/IP port $PORT..."
31 . $CONFFILTER $BACKEND $MONITORDB < $WHOAMICONF > $CONF1
32 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
33 PID=$!
34 if test $WAIT != 0 ; then
35     echo PID $PID
36     read foo
37 fi
38 KILLPIDS="$PID"
39
40 sleep 1
41
42 echo "Using ldapsearch to check that slapd is running..."
43 for i in 0 1 2 3 4 5; do
44         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
45                 'objectclass=*' > /dev/null 2>&1
46         RC=$?
47         if test $RC = 0 ; then
48                 break
49         fi
50         echo "Waiting 5 seconds for slapd to start..."
51         sleep 5
52 done
53
54 echo "Testing ldapwhoami as anonymous..."
55 $LDAPWHOAMI -h $LOCALHOST -p $PORT1
56
57 RC=$?
58 if test $RC != 0 ; then
59         echo "ldapwhoami failed ($RC)!"
60         test $KILLSERVERS != no && kill -HUP $KILLPIDS
61         exit $RC
62 fi
63
64 echo "Testing ldapwhoami as ${MANAGERDN}..."
65 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD
66
67 RC=$?
68 if test $RC != 0 ; then
69         echo "ldapwhoami failed ($RC)!"
70         test $KILLSERVERS != no && kill -HUP $KILLPIDS
71         exit $RC
72 fi
73
74 echo "Testing ldapwhoami as ${MANAGERDN} for anonymous..."
75 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD \
76         -e \!authzid=""
77
78 RC=$?
79 if test $RC != 0 ; then
80         echo "ldapwhoami failed ($RC)!"
81         test $KILLSERVERS != no && kill -HUP $KILLPIDS
82         exit $RC
83 fi
84
85 echo "Testing ldapwhoami as ${MANAGERDN} for dn:$BABSDN..."
86 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD \
87         -e \!authzid="dn:$BABSDN"
88
89 RC=$?
90 if test $RC != 0 ; then
91         echo "ldapwhoami failed ($RC)!"
92         test $KILLSERVERS != no && kill -HUP $KILLPIDS
93         exit $RC
94 fi
95
96 echo "Testing ldapwhoami as ${MANAGERDN} for u:uham..."
97 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD \
98         -e \!authzid="u:uham"
99
100 RC=$?
101 if test $RC != 0 ; then
102         echo "ldapwhoami failed ($RC)!"
103         test $KILLSERVERS != no && kill -HUP $KILLPIDS
104         exit $RC
105 fi
106
107 # authzFrom: someone else => bjorn
108 echo "Testing authzFrom..."
109
110 BINDDN="cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
111 BINDPW=bjensen
112 AUTHZID="u:bjorn"
113 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.exact)..."
114 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
115         -e \!authzid="$AUTHZID"
116
117 RC=$?
118 if test $RC != 0 ; then
119         echo "ldapwhoami failed ($RC)!"
120         test $KILLSERVERS != no && kill -HUP $KILLPIDS
121         exit $RC
122 fi
123
124 BINDDN="cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com"
125 BINDPW=melliot
126 AUTHZID="u:bjorn"
127 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (u)..."
128 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
129         -e \!authzid="$AUTHZID"
130
131 RC=$?
132 if test $RC != 0 ; then
133         echo "ldapwhoami failed ($RC)!"
134         test $KILLSERVERS != no && kill -HUP $KILLPIDS
135         exit $RC
136 fi
137
138 BINDDN="cn=Jane Doe,ou=Alumni Association,ou=People,dc=example,dc=com"
139 BINDPW=jdoe
140 AUTHZID="u:bjorn"
141 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (URI)..."
142 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
143         -e \!authzid="$AUTHZID"
144
145 RC=$?
146 if test $RC != 0 ; then
147         echo "ldapwhoami failed ($RC)!"
148         test $KILLSERVERS != no && kill -HUP $KILLPIDS
149         exit $RC
150 fi
151
152 BINDDN="cn=James A Jones 2,ou=Information Technology Division,ou=People,dc=example,dc=com"
153 BINDPW=jjones
154 AUTHZID="u:bjorn"
155 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (group)..."
156 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
157         -e \!authzid="$AUTHZID"
158
159 RC=$?
160 if test $RC != 0 ; then
161         echo "ldapwhoami failed ($RC)!"
162         test $KILLSERVERS != no && kill -HUP $KILLPIDS
163         exit $RC
164 fi
165
166 BINDDN="cn=No One,ou=Information Technology Division,ou=People,dc=example,dc=com"
167 BINDPW=noone
168 AUTHZID="u:bjorn"
169 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.onelevel)..."
170 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
171         -e \!authzid="$AUTHZID"
172
173 RC=$?
174 if test $RC != 0 ; then
175         echo "ldapwhoami failed ($RC)!"
176         test $KILLSERVERS != no && kill -HUP $KILLPIDS
177         exit $RC
178 fi
179
180 BINDDN="cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com"
181 BINDPW=dots
182 AUTHZID="u:bjorn"
183 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.regex)..."
184 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
185         -e \!authzid="$AUTHZID"
186
187 RC=$?
188 if test $RC != 0 ; then
189         echo "ldapwhoami failed ($RC)!"
190         test $KILLSERVERS != no && kill -HUP $KILLPIDS
191         exit $RC
192 fi
193
194 BINDDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
195 BINDPW=jaj
196 AUTHZID="u:bjorn"
197 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.children)..."
198 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
199         -e \!authzid="$AUTHZID"
200
201 RC=$?
202 if test $RC != 0 ; then
203         echo "ldapwhoami failed ($RC)!"
204         test $KILLSERVERS != no && kill -HUP $KILLPIDS
205         exit $RC
206 fi
207
208 BINDDN="cn=ITD Staff,ou=Groups,dc=example,dc=com"
209 BINDPW=ITD
210 AUTHZID="u:bjorn"
211 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.subtree)..."
212 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
213         -e \!authzid="$AUTHZID"
214
215 RC=$?
216 if test $RC != 0 ; then
217         echo "ldapwhoami failed ($RC)!"
218         test $KILLSERVERS != no && kill -HUP $KILLPIDS
219         exit $RC
220 fi
221
222 BINDDN="cn=Should Fail,dc=example,dc=com"
223 BINDPW=fail
224 AUTHZID="u:bjorn"
225 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (URI; should fail)..."
226 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
227         -e \!authzid="$AUTHZID"
228
229 RC=$?
230 if test $RC != 1 ; then
231         echo "ldapwhoami failed ($RC)!"
232         test $KILLSERVERS != no && kill -HUP $KILLPIDS
233         exit $RC
234 fi
235
236 BINDDN="cn=Must Fail,dc=example,dc=com"
237 BINDPW=fail
238 AUTHZID="u:bjorn"
239 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (URI; should fail)..."
240 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
241         -e \!authzid="$AUTHZID"
242
243 RC=$?
244 if test $RC != 1 ; then
245         echo "ldapwhoami failed ($RC)!"
246         test $KILLSERVERS != no && kill -HUP $KILLPIDS
247         exit $RC
248 fi
249
250 # authzTo: bjorn => someone else
251 echo "Testing authzTo..."
252
253 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
254 BINDPW=bjorn
255 AUTHZID="u:bjensen"
256 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.exact)..."
257 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
258         -e \!authzid="$AUTHZID"
259
260 RC=$?
261 if test $RC != 0 ; then
262         echo "ldapwhoami failed ($RC)!"
263         test $KILLSERVERS != no && kill -HUP $KILLPIDS
264         exit $RC
265 fi
266
267 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
268 BINDPW=bjorn
269 AUTHZID="u:melliot"
270 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (u)..."
271 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
272         -e \!authzid="$AUTHZID"
273
274 RC=$?
275 if test $RC != 0 ; then
276         echo "ldapwhoami failed ($RC)!"
277         test $KILLSERVERS != no && kill -HUP $KILLPIDS
278         exit $RC
279 fi
280
281 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
282 BINDPW=bjorn
283 AUTHZID="u:jdoe"
284 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (URI)..."
285 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
286         -e \!authzid="$AUTHZID"
287
288 RC=$?
289 if test $RC != 0 ; then
290         echo "ldapwhoami failed ($RC)!"
291         test $KILLSERVERS != no && kill -HUP $KILLPIDS
292         exit $RC
293 fi
294
295 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
296 BINDPW=bjorn
297 AUTHZID="u:jjones"
298 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (group)..."
299 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
300         -e \!authzid="$AUTHZID"
301
302 RC=$?
303 if test $RC != 0 ; then
304         echo "ldapwhoami failed ($RC)!"
305         test $KILLSERVERS != no && kill -HUP $KILLPIDS
306         exit $RC
307 fi
308
309 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
310 BINDPW=bjorn
311 AUTHZID="u:noone"
312 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.onelevel)..."
313 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
314         -e \!authzid="$AUTHZID"
315
316 RC=$?
317 if test $RC != 0 ; then
318         echo "ldapwhoami failed ($RC)!"
319         test $KILLSERVERS != no && kill -HUP $KILLPIDS
320         exit $RC
321 fi
322
323 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
324 BINDPW=bjorn
325 AUTHZID="u:dots"
326 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.regex)..."
327 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
328         -e \!authzid="$AUTHZID"
329
330 RC=$?
331 if test $RC != 0 ; then
332         echo "ldapwhoami failed ($RC)!"
333         test $KILLSERVERS != no && kill -HUP $KILLPIDS
334         exit $RC
335 fi
336
337 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
338 BINDPW=bjorn
339 AUTHZID="u:jaj"
340 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.children)..."
341 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
342         -e \!authzid="$AUTHZID"
343
344 RC=$?
345 if test $RC != 0 ; then
346         echo "ldapwhoami failed ($RC)!"
347         test $KILLSERVERS != no && kill -HUP $KILLPIDS
348         exit $RC
349 fi
350
351 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
352 BINDPW=bjorn
353 AUTHZID="u:group/itd staff"
354 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (dn.subtree)..."
355 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
356         -e \!authzid="$AUTHZID"
357
358 RC=$?
359 if test $RC != 0 ; then
360         echo "ldapwhoami failed ($RC)!"
361         test $KILLSERVERS != no && kill -HUP $KILLPIDS
362         exit $RC
363 fi
364
365 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
366 BINDPW=bjorn
367 AUTHZID="u:fail"
368 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (URI; should fail)..."
369 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
370         -e \!authzid="$AUTHZID"
371
372 RC=$?
373 if test $RC != 1 ; then
374         echo "ldapwhoami failed ($RC)!"
375         test $KILLSERVERS != no && kill -HUP $KILLPIDS
376         exit $RC
377 fi
378
379 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
380 BINDPW=bjorn
381 AUTHZID="dn:cn=Should Fail,dc=example,dc=com"
382 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (URI; should fail)..."
383 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
384         -e \!authzid="$AUTHZID"
385
386 RC=$?
387 if test $RC != 1 ; then
388         echo "ldapwhoami failed ($RC)!"
389         test $KILLSERVERS != no && kill -HUP $KILLPIDS
390         exit $RC
391 fi
392
393 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
394 BINDPW=bjorn
395 AUTHZID="dn:"
396 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID} (no authzTo; should fail)..."
397 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
398         -e \!authzid="$AUTHZID"
399
400 RC=$?
401 if test $RC != 1 ; then
402         echo "ldapwhoami failed ($RC)!"
403         test $KILLSERVERS != no && kill -HUP $KILLPIDS
404         exit $RC
405 fi
406
407 BINDDN="dc=example,dc=com"
408 BINDPW=example
409 AUTHZID="dn:"
410 echo "Testing ldapwhoami as ${BINDDN} for ${AUTHZID}\"\" (dn.exact; should succeed)..."
411 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW \
412         -e \!authzid="$AUTHZID"
413
414 RC=$?
415 if test $RC != 0 ; then
416         echo "ldapwhoami failed ($RC)!"
417         test $KILLSERVERS != no && kill -HUP $KILLPIDS
418         exit $RC
419 fi
420
421 test $KILLSERVERS != no && kill -HUP $KILLPIDS
422
423 echo ">>>>> Test succeeded"
424 exit 0
425
426 ## Note to developers: when SLAPD_DEBUG=-1 the command
427 ## awk '/^do_extended$/ {if (c) {print c} c=0} /<===slap_sasl_match:/ {c++} END {print c}' $TESTDIR/slapd.1.log
428 ## must return the sequence 1 2 3 4 5 6 7 8 9 9 1 2 3 4 5 6 7 8 9 9 9 1
429 ## to indicate that the authzFrom and authzTo rules applied in the right order.