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