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