]> git.sur5r.net Git - openldap/blob - tests/scripts/test028-idassert
4418a1c331a1d64862547152b1e3948d0ad7e77a
[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 echo "### This test requires the ldap backend."
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 $RWM = rwmno ; then 
31         echo "Rewrite/remap 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
51
52 echo "Running slapadd to build slapd database..."
53 . $CONFFILTER $BACKEND $MONITORDB < $IDASSERTCONF > $ADDCONF
54 $SLAPADD -f $ADDCONF -l $LDIFIDASSERT1 -n 1
55 RC=$?
56 if test $RC != 0 ; then
57         echo "slapadd -n 1 failed ($RC)!"
58         exit $RC
59 fi
60 $SLAPADD -f $ADDCONF -l $LDIFIDASSERT2 -n 2
61 RC=$?
62 if test $RC != 0 ; then
63         echo "slapadd -n 2 failed ($RC)!"
64         exit $RC
65 fi
66
67 echo "Starting slapd on TCP/IP port $PORT..."
68 . $CONFFILTER $BACKEND $MONITORDB < $IDASSERTCONF > $CONF1
69 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
70 PID=$!
71 if test $WAIT != 0 ; then
72     echo PID $PID
73     read foo
74 fi
75 KILLPIDS="$PID"
76
77 echo "Using ldapsearch to check that slapd is running..."
78 for i in 0 1 2 3 4 5; do
79         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
80                 'objectclass=*' > /dev/null 2>&1
81         RC=$?
82         if test $RC = 0 ; then
83                 break
84         fi
85         echo "Waiting 5 seconds for slapd to start..."
86         sleep 5
87 done
88
89 echo "Testing ldapwhoami as proxy US..."
90 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy
91 RC=$?
92 if test $RC != 0 ; then
93         echo "ldapwhoami failed ($RC)!"
94         test $KILLSERVERS != no && kill -HUP $KILLPIDS
95         exit $RC
96 fi
97
98 AUTHZID="u:it/jaj"
99 echo "Testing ldapwhoami as proxy US, $AUTHZID..."
100 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
101 RC=$?
102 if test $RC != 0 ; then
103         echo "ldapwhoami failed ($RC)!"
104         test $KILLSERVERS != no && kill -HUP $KILLPIDS
105         exit $RC
106 fi
107
108 AUTHZID="u:bjorn"
109 echo "Testing ldapwhoami as proxy US, $AUTHZID... (should fail)"
110 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
111 RC=$?
112 if test $RC != 1 ; then
113         echo "ldapwhoami should have failed ($RC)!"
114         test $KILLSERVERS != no && kill -HUP $KILLPIDS
115         exit $RC
116 fi
117
118 AUTHZID="u:bjensen"
119 echo "Testing ldapwhoami as proxy US, $AUTHZID... (should fail)"
120 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy US,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
121 RC=$?
122 if test $RC != 1 ; then
123         echo "ldapwhoami should have failed ($RC)!"
124         test $KILLSERVERS != no && kill -HUP $KILLPIDS
125         exit $RC
126 fi
127
128 echo "Testing ldapwhoami as proxy IT..."
129 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy
130 RC=$?
131 if test $RC != 0 ; then
132         echo "ldapwhoami failed ($RC)!"
133         test $KILLSERVERS != no && kill -HUP $KILLPIDS
134         exit $RC
135 fi
136
137 AUTHZID="u:it/jaj"
138 echo "Testing ldapwhoami as proxy IT, $AUTHZID... (should fail)"
139 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
140 RC=$?
141 if test $RC != 1 ; then
142         echo "ldapwhoami should have failed ($RC)!"
143         test $KILLSERVERS != no && kill -HUP $KILLPIDS
144         exit $RC
145 fi
146
147 AUTHZID="u:bjorn"
148 echo "Testing ldapwhoami as proxy IT, $AUTHZID... (should fail)"
149 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
150 RC=$?
151 if test $RC != 1 ; then
152         echo "ldapwhoami should have failed ($RC)!"
153         test $KILLSERVERS != no && kill -HUP $KILLPIDS
154         exit $RC
155 fi
156
157 AUTHZID="dn:cn=Sandbox,ou=Admin,dc=example,dc=com"
158 echo "Testing ldapwhoami as proxy IT, $AUTHZID..."
159 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "cn=proxy IT,ou=Admin,dc=example,dc=com" -w proxy -e\!"authzid=$AUTHZID"
160 RC=$?
161 if test $RC != 0 ; then
162         echo "ldapwhoami failed ($RC)!"
163         test $KILLSERVERS != no && kill -HUP $KILLPIDS
164         exit $RC
165 fi
166
167 AUTHZID="dn:uid=bjorn,ou=People,o=Example,c=US"
168 echo "Testing ldapwhoami as bjorn, $AUTHZID..."
169 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "uid=bjorn,ou=people,dc=example,dc=com" -w bjorn -e\!"authzid=$AUTHZID"
170 RC=$?
171 if test $RC != 0 ; then
172         echo "ldapwhoami failed ($RC)!"
173         test $KILLSERVERS != no && kill -HUP $KILLPIDS
174         exit $RC
175 fi
176
177 AUTHZID="dn:uid=bjorn,ou=People,o=Esempio,c=IT"
178 echo "Testing ldapwhoami as bjorn, $AUTHZID..."
179 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "uid=bjorn,ou=people,dc=example,dc=com" -w bjorn -e\!"authzid=$AUTHZID"
180 RC=$?
181 if test $RC != 0 ; then
182         echo "ldapwhoami failed ($RC)!"
183         test $KILLSERVERS != no && kill -HUP $KILLPIDS
184         exit $RC
185 fi
186
187 ID="uid=jaj,ou=People,dc=example,dc=it"
188 BASE="o=Example,c=US"
189 echo "Testing ldapsearch as $ID for \"$BASE\"..."
190 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
191         -D "$ID" -w jaj > $SEARCHOUT 2>&1
192
193 RC=$?
194 if test $RC != 0 ; then
195         echo "ldapsearch failed ($RC)!"
196         test $KILLSERVERS != no && kill -HUP $KILLPIDS
197         exit $RC
198 fi
199
200 echo "Filtering ldapsearch results..."
201 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
202 echo "Filtering original ldif used to create database..."
203 . $LDIFFILTER < $IDASSERTOUT > $LDIFFLT
204 echo "Comparing filter output..."
205 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
206         
207 if test $? != 0 ; then
208         echo "comparison failed - search with identity assertion didn't succeed"
209         test $KILLSERVERS != no && kill -HUP $KILLPIDS
210         exit 1
211 fi
212
213 if test $USE_SASL != "no" ; then
214         ID="it/jaj"
215         BASE="o=Example,c=US"
216         echo "Testing ldapsearch as $ID for \"$BASE\" with SASL bind and identity assertion..."
217         $LDAPSASLSEARCH -h $LOCALHOST -p $PORT1 -b "$BASE" \
218                 -Q -U "$ID" -w jaj -Y $MECH > $SEARCHOUT 2>&1
219
220         RC=$?
221         if test $RC != 0 ; then
222                 echo "ldapsearch failed ($RC)!"
223                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
224                 exit $RC
225         fi
226
227         echo "Filtering ldapsearch results..."
228         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
229         echo "Filtering original ldif used to create database..."
230         . $LDIFFILTER < $IDASSERTOUT > $LDIFFLT
231         echo "Comparing filter output..."
232         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
233         
234         if test $? != 0 ; then
235                 echo "comparison failed - search with SASL bind and identity assertion didn't succeed"
236                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
237                 exit 1
238         fi
239 fi
240
241 test $KILLSERVERS != no && kill -HUP $KILLPIDS
242
243 echo ">>>>> Test succeeded"
244 exit 0
245