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