]> git.sur5r.net Git - openldap/blob - tests/scripts/test028-idassert
improve SASL in id assertion test
[openldap] / tests / scripts / test028-idassert
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 if test $BACKLDAP = "ldapno" ; then 
20         echo "LDAP backend not available, test skipped"
21         exit 0
22 fi 
23
24 if test $WITH_SASL = "yes" ; then
25         if test $USE_SASL != "no" ; then
26                 if test $USE_SASL = "yes" ; then
27                         MECH="DIGEST-MD5"
28                 else
29                         MECH="$USE_SASL"
30                 fi
31                 echo "Using SASL authc/authz with mech=$MECH; unset SLAPD_USE_SASL to disable"
32         else
33                 echo "Using proxyAuthz with simple authc..."
34                 echo "        set SLAPD_USE_SASL={yes|<mech>} to enable SASL authc/authz"
35                 echo "        if SLAPD_USE_SASL=\"yes\", <mech> defaults to DIGEST-MD5"
36                 echo "        FIXME: should be mandatory, right?"
37                 echo "        FIXME: authz with CRAM-MD5 does not work..."
38         fi
39 else
40         echo "SASL not available; using proxyAuthz with simple authc..."
41 fi
42
43 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
44
45 echo "Running slapadd to build slapd database..."
46 . $CONFFILTER $BACKEND $MONITORDB < $IDASSERTCONF > $ADDCONF
47 $SLAPADD -f $ADDCONF -l $LDIFIDASSERT1 -n 1
48 RC=$?
49 if test $RC != 0 ; then
50         echo "slapadd -n 1 failed ($RC)!"
51         exit $RC
52 fi
53 $SLAPADD -f $ADDCONF -l $LDIFIDASSERT2 -n 2
54 RC=$?
55 if test $RC != 0 ; then
56         echo "slapadd -n 2 failed ($RC)!"
57         exit $RC
58 fi
59
60 echo "Starting slapd on TCP/IP port $PORT..."
61 . $CONFFILTER $BACKEND $MONITORDB < $IDASSERTCONF > $CONF1
62 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
63 PID=$!
64 if test $WAIT != 0 ; then
65     echo PID $PID
66     read foo
67 fi
68 KILLPIDS="$PID"
69
70 echo "Using ldapsearch to check that slapd is running..."
71 for i in 0 1 2 3 4 5; do
72         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
73                 'objectclass=*' > /dev/null 2>&1
74         RC=$?
75         if test $RC = 0 ; then
76                 break
77         fi
78         echo "Waiting 5 seconds for slapd to start..."
79         sleep 5
80 done
81
82 echo "Testing ldapwhoami as proxy US..."
83 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy
84 RC=$?
85 if test $RC != 0 ; then
86         echo "ldapwhoami failed ($RC)!"
87         test $KILLSERVERS != no && kill -HUP $KILLPIDS
88         exit $RC
89 fi
90
91 AUTHZID="u:it/jaj"
92 echo "Testing ldapwhoami as proxy US, $AUTHZID..."
93 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
94 RC=$?
95 if test $RC != 0 ; then
96         echo "ldapwhoami failed ($RC)!"
97         test $KILLSERVERS != no && kill -HUP $KILLPIDS
98         exit $RC
99 fi
100
101 AUTHZID="u:bjorn"
102 echo "Testing ldapwhoami as proxy US, $AUTHZID..."
103 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
104 RC=$?
105 if test $RC != 1 ; then
106         echo "ldapwhoami should have failed ($RC)!"
107         test $KILLSERVERS != no && kill -HUP $KILLPIDS
108         exit $RC
109 fi
110
111 AUTHZID="u:bjensen"
112 echo "Testing ldapwhoami as proxy US, $AUTHZID..."
113 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
114 RC=$?
115 if test $RC != 1 ; then
116         echo "ldapwhoami should have failed ($RC)!"
117         test $KILLSERVERS != no && kill -HUP $KILLPIDS
118         exit $RC
119 fi
120
121 echo "Testing ldapwhoami as proxy IT..."
122 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy
123 RC=$?
124 if test $RC != 0 ; then
125         echo "ldapwhoami failed ($RC)!"
126         test $KILLSERVERS != no && kill -HUP $KILLPIDS
127         exit $RC
128 fi
129
130 AUTHZID="u:it/jaj"
131 echo "Testing ldapwhoami as proxy IT, $AUTHZID..."
132 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
133 RC=$?
134 if test $RC != 1 ; then
135         echo "ldapwhoami should have failed ($RC)!"
136         test $KILLSERVERS != no && kill -HUP $KILLPIDS
137         exit $RC
138 fi
139
140 AUTHZID="u:bjorn"
141 echo "Testing ldapwhoami as proxy IT, $AUTHZID..."
142 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
143 RC=$?
144 if test $RC != 1 ; then
145         echo "ldapwhoami should have failed ($RC)!"
146         test $KILLSERVERS != no && kill -HUP $KILLPIDS
147         exit $RC
148 fi
149
150 AUTHZID="dn:cn=Sandbox,ou=Admin,dc=example,dc=com"
151 echo "Testing ldapwhoami as proxy IT, $AUTHZID..."
152 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
153 RC=$?
154 if test $RC != 0 ; then
155         echo "ldapwhoami failed ($RC)!"
156         test $KILLSERVERS != no && kill -HUP $KILLPIDS
157         exit $RC
158 fi
159
160 AUTHZID="dn:uid=bjorn,ou=People,o=Example,c=US"
161 echo "Testing ldapwhoami as bjorn, $AUTHZID..."
162 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "uid=bjorn,ou=people,dc=example,dc=com" -w bjorn -e\!"authzid=$AUTHZID"
163 RC=$?
164 if test $RC != 0 ; then
165         echo "ldapwhoami failed ($RC)!"
166         test $KILLSERVERS != no && kill -HUP $KILLPIDS
167         exit $RC
168 fi
169
170 AUTHZID="dn:uid=bjorn,ou=People,o=Esempio,c=IT"
171 echo "Testing ldapwhoami as bjorn, $AUTHZID..."
172 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "uid=bjorn,ou=people,dc=example,dc=com" -w bjorn -e\!"authzid=$AUTHZID"
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 ID="uid=jaj,ou=People,dc=example,dc=it"
181 BASE="o=Example,c=US"
182 echo "Testing ldapsearch as $ID for \"$BASE\"..."
183 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
184         -D "$ID" -w jaj > $SEARCHOUT 2>&1
185
186 RC=$?
187 if test $RC != 0 ; then
188         echo "ldapsearch failed ($RC)!"
189         test $KILLSERVERS != no && kill -HUP $KILLPIDS
190         exit $RC
191 fi
192
193 echo "Filtering ldapsearch results..."
194 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
195 echo "Filtering original ldif used to create database..."
196 . $LDIFFILTER < $IDASSERTOUT > $LDIFFLT
197 echo "Comparing filter output..."
198 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
199         
200 if test $? != 0 ; then
201         echo "comparison failed - search with identity assertion didn't succeed"
202         exit 1
203 fi
204
205 if test $USE_SASL != "no" ; then
206         ID="it/jaj"
207         BASE="o=Example,c=US"
208         echo "Testing ldapsearch as $ID for \"$BASE\" with SASL bind and identity assertion..."
209         $LDAPSASLSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
210                 -Q -U "$ID" -w jaj -Y $MECH > $SEARCHOUT 2>&1
211
212         RC=$?
213         if test $RC != 0 ; then
214                 echo "ldapsearch failed ($RC)!"
215                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
216                 exit $RC
217         fi
218
219         echo "Filtering ldapsearch results..."
220         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
221         echo "Filtering original ldif used to create database..."
222         . $LDIFFILTER < $IDASSERTOUT > $LDIFFLT
223         echo "Comparing filter output..."
224         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
225         
226         if test $? != 0 ; then
227                 echo "comparison failed - search with SASL bind and identity assertion didn't succeed"
228                 exit 1
229         fi
230 fi
231
232 test $KILLSERVERS != no && kill -HUP $KILLPIDS
233
234 echo ">>>>> Test succeeded"
235 exit 0
236