]> git.sur5r.net Git - openldap/blob - tests/scripts/test065-proxyauthz
Do not require ac/string.h for lber_pvt.h
[openldap] / tests / scripts / test065-proxyauthz
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2018 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 PCACHETTL=${PCACHETTL-"1m"}
17 PCACHENTTL=${PCACHENTTL-"1m"}
18 PCACHESTTL=${PCACHESTTL-"1m"}
19 PCACHE_ENTRY_LIMIT=${PCACHE_ENTRY_LIMIT-"6"}
20 PCACHE_CCPERIOD=${PCACHE_CCPERIOD-"2"}
21 PCACHETTR=${PCACHETTR-"2"}
22 PCACHEBTTR=${PCACHEBTTR-"5"}
23
24 . $SRCDIR/scripts/defines.sh
25
26 LVL=0x100
27
28 if test $PROXYCACHE = pcacheno; then 
29         echo "Proxy cache overlay not available, test skipped"
30         exit 0
31 fi 
32
33 if test $BACKLDAP = "ldapno" ; then 
34         echo "LDAP backend not available, test skipped"
35         exit 0
36 fi 
37
38 if test $BACKEND = ldif ; then
39         # The (mail=example.com*) queries hit a sizelimit, so which
40         # entry is returned depends on the ordering in the backend.
41         echo "Test does not support $BACKEND backend, test skipped"
42         exit 0
43 fi
44
45 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
46
47 # Test proxy caching:
48 # - start master
49 # - start proxy cache
50 # - populate master 
51 # - perform a first search
52 # - verify cacheability
53 # - perform a second search with the same filter and same user 
54 # - verify answerability and cacheability of the bind
55 # - perform a third search with the same user but a different filter
56 # - verify cacheability of the bind and the non-answerability of the result 
57
58 echo "Starting master slapd on TCP/IP port $PORT1..."
59 . $CONFFILTER < $PROXYAUTHZMASTERCONF > $CONF1
60 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
61 PID=$!
62 if test $WAIT != 0 ; then
63         echo PID $PID
64         read foo
65 fi
66 KILLPIDS="$PID"
67
68 sleep 1
69
70 echo "Using ldapsearch to check that master 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                 -D "cn=Manager,dc=example,dc=com" -w secret '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 if test $RC != 0 ; then
83         echo "ldapsearch failed ($RC)!"
84         test $KILLSERVERS != no && kill -HUP $KILLPIDS
85         exit $RC
86 fi
87
88 echo "Using ldapadd to populate the master directory..."
89 $LDAPADD -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
90         $LDIFORDERED > /dev/null 2>&1
91 RC=$?
92 if test $RC != 0 ; then
93         echo "ldapadd failed ($RC)!"
94         test $KILLSERVERS != no && kill -HUP $KILLPIDS
95         exit $RC
96 fi
97
98 echo "Starting proxy cache on TCP/IP port $PORT2..."
99 . $CONFFILTER < $PROXYAUTHZCONF | sed \
100         -e "s/@TTL@/${PCACHETTL}/"                      \
101         -e "s/@NTTL@/${PCACHENTTL}/"            \
102         -e "s/@STTL@/${PCACHENTTL}/"            \
103         -e "s/@TTR@/${PCACHETTR}/"                      \
104         -e "s/@ENTRY_LIMIT@/${PCACHE_ENTRY_LIMIT}/"     \
105         -e "s/@CCPERIOD@/${PCACHE_CCPERIOD}/"                   \
106         -e "s/@BTTR@/${PCACHEBTTR}/"                    \
107         > $CONF2
108
109 $SLAPD -f $CONF2 -h $URI2 -d $LVL -d pcache > $LOG2 2>&1 &
110 CACHEPID=$!
111 if test $WAIT != 0 ; then
112         echo CACHEPID $CACHEPID
113         read foo
114 fi
115 KILLPIDS="$KILLPIDS $CACHEPID"
116
117 sleep 1
118
119 echo "Using ldapsearch to check that proxy slapd is running..."
120 for i in 0 1 2 3 4 5; do
121         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
122                 -D "cn=Manager,dc=example,dc=com" -w secret 'objectclass=*' > /dev/null 2>&1
123         RC=$?
124         if test $RC = 0 ; then
125                 break
126         fi
127         echo "Waiting 5 seconds for slapd to start..."
128         sleep 5
129 done
130
131 if test $RC != 0 ; then
132         echo "ldapsearch failed ($RC)!"
133         test $KILLSERVERS != no && kill -HUP $KILLPIDS
134         exit $RC
135 fi
136
137 cat /dev/null > $SEARCHOUT
138
139 echo "Making queries on the proxy cache..." 
140 CNT=0
141
142
143 CNT=`expr $CNT + 1`
144 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
145 UPASSWD="jaj"
146 echo "Query $CNT: $USERDN"
147 echo "# Query $CNT: $USERDN" >> $SEARCHOUT
148
149 $LDAPSEARCH -S "" -b "dc=example,dc=com" -s SUB -h $LOCALHOST -p $PORT2 \
150         -D "$USERDN" -w "$UPASSWD" "(sn=je*)" sn >> $SEARCHOUT 2>> $TESTOUT
151 RC=$?
152
153 if test $RC != 0 ; then
154         echo "ldapsearch failed ($RC)!"
155         test $KILLSERVERS != no && kill -HUP $KILLPIDS
156         exit $RC
157 fi
158
159 # Check that the bind is cached
160 grep "CACHING BIND for $USERDN" $LOG2 > /dev/null
161
162 RC=$?
163 if test $RC != 0 ; then
164         echo "Refresh failed"
165         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
166         exit 1
167 fi
168
169 CNT=`expr $CNT + 1`
170 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
171 UPASSWD="jaj"
172 echo "Query $CNT: (Bind should be cached)"
173 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
174
175 $LDAPSEARCH -S "" -b "dc=example,dc=com" -s SUB -h $LOCALHOST -p $PORT2 \
176         -D "$USERDN" -w "$UPASSWD" "(sn=je*)" sn >> $SEARCHOUT 2>> $TESTOUT
177
178 RC=$?
179 if test $RC != 0 ; then
180         echo "ldapsearch failed ($RC)!"
181         test $KILLSERVERS != no && kill -HUP $KILLPIDS
182         exit $RC
183 fi
184
185 grep "CACHED BIND for $USERDN" $LOG2 > /dev/null
186 RC=$?
187 if test $RC != 0 ; then
188         echo "Refresh failed"
189         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
190         exit 1
191 fi
192
193 CNT=`expr $CNT + 1`
194 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
195
196 echo "Query $CNT: (Bind should be cached)"
197 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
198 $LDAPSEARCH -S "" -b "dc=example,dc=com" -s SUB -h $LOCALHOST -p $PORT2 \
199         -D "$USERDN" -w "$UPASSWD" "(sn=je*)" sn >> $SEARCHOUT 2>> $TESTOUT
200
201 RC=$?
202 if test $RC != 0 ; then
203         echo "ldapsearch failed ($RC)!"
204         test $KILLSERVERS != no && kill -HUP $KILLPIDS
205         exit $RC
206 fi
207
208 RC=`grep "CACHED BIND for $USERDN" $LOG2 | wc -l`
209 if test $RC != 2 ; then
210         echo "Bind wasn't answered from cache"
211         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
212         exit 1
213 fi
214
215 echo "=== New search on (sn=jo*)"
216 cat /dev/null > $SEARCHOUT
217 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
218 $LDAPSEARCH -S "" -b "dc=example,dc=com" -s SUB -h $LOCALHOST -p $PORT2 \
219         -D "$USERDN" -w "$UPASSWD" "(sn=jo*)" sn >> $SEARCHOUT 2>> $TESTOUT
220
221 RC=$?
222 if test $RC != 0 ; then
223         echo "ldapsearch failed ($RC)!"
224         test $KILLSERVERS != no && kill -HUP $KILLPIDS
225         exit $RC
226 fi
227
228 RC=`grep "CACHED BIND for $USERDN" $LOG2 | wc -l`
229 if test $RC != 3 ; then
230         echo "Bind wasn't answered from cache"
231         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
232         exit 1
233 fi
234
235 RC=`grep "QUERY NOT ANSWERABLE" $LOG2 | wc -l`
236 if test $RC != 3 ; then
237         echo "Search wasn't searched on remote peer"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
239         exit 1
240 fi
241
242 RC=`grep "dn: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com" $SEARCHOUT | wc -l`
243 if test $RC != 1 ; then
244         echo "Search wasn't retrieved on remote peer"
245         test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
246         exit 1
247 fi
248
249 echo "Test succeeded"
250
251 test $KILLSERVERS != no && kill -HUP $KILLPIDS
252
253 test $KILLSERVERS != no && wait
254
255 exit 0