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