3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2018 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
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>.
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"}
24 . $SRCDIR/scripts/defines.sh
28 if test $PROXYCACHE = pcacheno; then
29 echo "Proxy cache overlay not available, test skipped"
33 if test $BACKLDAP = "ldapno" ; then
34 echo "LDAP backend not available, test skipped"
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"
45 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
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
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 &
62 if test $WAIT != 0 ; then
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
75 if test $RC = 0 ; then
78 echo "Waiting 5 seconds for slapd to start..."
82 if test $RC != 0 ; then
83 echo "ldapsearch failed ($RC)!"
84 test $KILLSERVERS != no && kill -HUP $KILLPIDS
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
92 if test $RC != 0 ; then
93 echo "ldapadd failed ($RC)!"
94 test $KILLSERVERS != no && kill -HUP $KILLPIDS
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}/" \
109 $SLAPD -f $CONF2 -h $URI2 -d $LVL -d pcache > $LOG2 2>&1 &
111 if test $WAIT != 0 ; then
112 echo CACHEPID $CACHEPID
115 KILLPIDS="$KILLPIDS $CACHEPID"
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
124 if test $RC = 0 ; then
127 echo "Waiting 5 seconds for slapd to start..."
131 if test $RC != 0 ; then
132 echo "ldapsearch failed ($RC)!"
133 test $KILLSERVERS != no && kill -HUP $KILLPIDS
137 cat /dev/null > $SEARCHOUT
139 echo "Making queries on the proxy cache..."
144 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
146 echo "Query $CNT: $USERDN"
147 echo "# Query $CNT: $USERDN" >> $SEARCHOUT
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
153 if test $RC != 0 ; then
154 echo "ldapsearch failed ($RC)!"
155 test $KILLSERVERS != no && kill -HUP $KILLPIDS
159 # Check that the bind is cached
160 grep "CACHING BIND for $USERDN" $LOG2 > /dev/null
163 if test $RC != 0 ; then
164 echo "Refresh failed"
165 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
170 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
172 echo "Query $CNT: (Bind should be cached)"
173 echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT
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
179 if test $RC != 0 ; then
180 echo "ldapsearch failed ($RC)!"
181 test $KILLSERVERS != no && kill -HUP $KILLPIDS
185 grep "CACHED BIND for $USERDN" $LOG2 > /dev/null
187 if test $RC != 0 ; then
188 echo "Refresh failed"
189 test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait
194 USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com"
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
202 if test $RC != 0 ; then
203 echo "ldapsearch failed ($RC)!"
204 test $KILLSERVERS != no && kill -HUP $KILLPIDS
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
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
222 if test $RC != 0 ; then
223 echo "ldapsearch failed ($RC)!"
224 test $KILLSERVERS != no && kill -HUP $KILLPIDS
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
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
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
249 echo "Test succeeded"
251 test $KILLSERVERS != no && kill -HUP $KILLPIDS
253 test $KILLSERVERS != no && wait