From: Howard Chu Date: Fri, 21 Aug 2009 13:25:38 +0000 (+0000) Subject: ITS#6152 add tests for cache refresh and Bind caching X-Git-Tag: ACLCHECK_0~253 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=27c39c56c4eaca4df72ac44d26aa53a256d8d368;p=openldap ITS#6152 add tests for cache refresh and Bind caching --- diff --git a/servers/slapd/overlays/pcache.c b/servers/slapd/overlays/pcache.c index fc886a30ce..1ed62fc14e 100644 --- a/servers/slapd/overlays/pcache.c +++ b/servers/slapd/overlays/pcache.c @@ -2563,7 +2563,7 @@ pc_setpw( Operation *op, struct berval *pwd, cache_manager *cm ) op->o_dn = op->o_bd->be_rootdn; op->o_ndn = op->o_bd->be_rootndn; op->o_callback = &cb; - Debug( pcache_debug, "pc_setpw: caching bind for %s\n", + Debug( pcache_debug, "pc_setpw: CACHING BIND for %s\n", op->o_req_dn.bv_val, 0, 0 ); rc = op->o_bd->be_modify( op, &sr ); ch_free( vals[0].bv_val ); @@ -2845,6 +2845,9 @@ pcache_op_bind( BackendDB *be = op->o_bd; op->o_bd = &cm->db; + Debug( pcache_debug, "pcache_op_bind: CACHED BIND for %s\n", + op->o_req_dn.bv_val, 0, 0 ); + if ( op->o_bd->be_bind( op, rs ) == LDAP_SUCCESS ) { op->o_conn->c_authz_cookie = cm->db.be_private; } diff --git a/tests/data/slapd-proxycache.conf b/tests/data/slapd-proxycache.conf index f5427d01a9..e0da53b26b 100644 --- a/tests/data/slapd-proxycache.conf +++ b/tests/data/slapd-proxycache.conf @@ -44,13 +44,15 @@ uri "@URI1@" limits dn="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com" size=1 overlay pcache -proxycache @BACKEND@ 100 2 @ENTRY_LIMIT@ @CACHETTL@ -proxyattrset 0 sn cn title uid -proxyattrset 1 mail postaladdress telephonenumber cn uid -proxytemplate (|(cn=)(sn=)) 0 @CACHETTL@ @NCACHETTL@ @SCACHETTL@ -proxytemplate (sn=) 0 @CACHETTL@ @NCACHETTL@ @SCACHETTL@ -proxytemplate (uid=) 1 @CACHETTL@ @NCACHETTL@ @SCACHETTL@ -proxytemplate (mail=) 0 @CACHETTL@ @NCACHETTL@ @SCACHETTL@ +pcache @BACKEND@ 100 2 @ENTRY_LIMIT@ @CCPERIOD@ +pcacheattrset 0 sn cn title uid +pcacheattrset 1 mail postaladdress telephonenumber cn uid +pcachetemplate (|(cn=)(sn=)) 0 @TTL@ @NTTL@ @STTL@ +pcachetemplate (sn=) 0 @TTL@ @NTTL@ @STTL@ +pcachetemplate (uid=) 1 @TTL@ @NTTL@ @STTL@ +pcachetemplate (mail=) 0 @TTL@ @NTTL@ @STTL@ +pcachetemplate (&(objectclass=)(uid=)) 1 @TTL@ @NTTL@ @STTL@ @TTR@ +pcachebind (&(objectclass=person)(uid=)) 1 @BTTR@ sub "ou=Alumni Association,ou=people,dc=example,dc=com" #bdb#cachesize 20 #hdb#cachesize 20 diff --git a/tests/scripts/conf.sh b/tests/scripts/conf.sh index c537b00a2a..ed6f034e2c 100755 --- a/tests/scripts/conf.sh +++ b/tests/scripts/conf.sh @@ -71,10 +71,6 @@ sed -e "s/@BACKEND@/${BACKEND}/" \ -e "s;@PORT5@;${PORT5};" \ -e "s;@PORT6@;${PORT6};" \ -e "s/@SASL_MECH@/${SASL_MECH}/" \ - -e "s/@CACHETTL@/${CACHETTL}/" \ - -e "s/@NCACHETTL@/${NCACHETTL}/" \ - -e "s/@SCACHETTL@/${SCACHETTL}/" \ - -e "s/@ENTRY_LIMIT@/${CACHE_ENTRY_LIMIT}/" \ -e "s;@TESTDIR@;${TESTDIR};" \ -e "s;@DATADIR@;${DATADIR};" \ -e "s;@SCHEMADIR@;${SCHEMADIR};" diff --git a/tests/scripts/test020-proxycache b/tests/scripts/test020-proxycache index 4feed27053..8502b4eda1 100755 --- a/tests/scripts/test020-proxycache +++ b/tests/scripts/test020-proxycache @@ -13,10 +13,13 @@ ## top-level directory of the distribution or, alternatively, at ## . -CACHETTL="1m" -NCACHETTL="1m" -SCACHETTL="1m" -CACHE_ENTRY_LIMIT=6 +PCACHETTL=${PCACHETTL-"1m"} +PCACHENTTL=${PCACHENTTL-"1m"} +PCACHESTTL=${PCACHESTTL-"1m"} +PCACHE_ENTRY_LIMIT=${PCACHE_ENTRY_LIMIT-"6"} +PCACHE_CCPERIOD=${PCACHE_CCPERIOD-"2"} +PCACHETTR=${PCACHETTR-"2"} +PCACHEBTTR=${PCACHEBTTR-"5"} . $SRCDIR/scripts/defines.sh @@ -82,7 +85,16 @@ if test $RC != 0 ; then fi echo "Starting proxy cache on TCP/IP port $PORT2..." -. $CONFFILTER < $PROXYCACHECONF > $CONF2 +. $CONFFILTER < $PROXYCACHECONF | sed \ + -e "s/@TTL@/${PCACHETTL}/" \ + -e "s/@NTTL@/${PCACHENTTL}/" \ + -e "s/@STTL@/${PCACHENTTL}/" \ + -e "s/@TTR@/${PCACHETTR}/" \ + -e "s/@ENTRY_LIMIT@/${PCACHE_ENTRY_LIMIT}/" \ + -e "s/@CCPERIOD@/${PCACHE_CCPERIOD}/" \ + -e "s/@BTTR@/${PCACHEBTTR}/" \ + > $CONF2 + $SLAPD -f $CONF2 -h $URI2 -d $LVL -d pcache > $LOG2 2>&1 & CACHEPID=$! if test $WAIT != 0 ; then @@ -226,11 +238,11 @@ CNT=`expr $CNT + 1` FILTER="(mail=*example.com)" ATTRS="cn sn title uid" USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com" -PASSWD="bjorn" +UPASSWD="bjorn" echo "Query $CNT: filter:$FILTER attrs:$ATTRS" echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ - -D "$USERDN" -w "$PASSWD" \ + -D "$USERDN" -w "$UPASSWD" \ "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT RC=$? case $RC in @@ -253,11 +265,11 @@ CNT=`expr $CNT + 1` FILTER="(uid=b*)" ATTRS="mail" USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com" -PASSWD="bjorn" +UPASSWD="bjorn" echo "Query $CNT: filter:$FILTER attrs:$ATTRS" echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ - -D "$USERDN" -w "$PASSWD" \ + -D "$USERDN" -w "$UPASSWD" \ "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT RC=$? case $RC in @@ -362,11 +374,11 @@ CNT=`expr $CNT + 1` FILTER="(mail=*example.com)" ATTRS="cn sn title uid" USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com" -PASSWD="bjorn" +UPASSWD="bjorn" echo "Query $CNT: filter:$FILTER attrs:$ATTRS" echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ - -D "$USERDN" -w "$PASSWD" \ + -D "$USERDN" -w "$UPASSWD" \ "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT RC=$? case $RC in @@ -389,11 +401,11 @@ CNT=`expr $CNT + 1` FILTER="(uid=b*)" ATTRS="mail" USERDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com" -PASSWD="bjorn" +UPASSWD="bjorn" echo "Query $CNT: filter:$FILTER attrs:$ATTRS" echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ - -D "$USERDN" -w "$PASSWD" \ + -D "$USERDN" -w "$UPASSWD" \ "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT RC=$? case $RC in @@ -434,12 +446,11 @@ ANSWERED=`grep ANSWERABLE $LOG2 | awk "BEGIN {FIRST=$FIRST}"'{ } }'` -test $KILLSERVERS != no && kill -HUP $KILLPIDS - if test "$ANSWERABILITY" = "$ANSWERED" ; then echo "Successfully verified answerability" else echo "Error in verifying answerability" + test $KILLSERVERS != no && kill -HUP $KILLPIDS exit 1 fi @@ -452,9 +463,109 @@ $CMP $SEARCHFLT $LDIFFLT > $CMPOUT if test $? != 0 ; then echo "Comparison failed" + test $KILLSERVERS != no && kill -HUP $KILLPIDS exit 1 fi +echo "" +echo "Testing cache refresh" + +CNT=`expr $CNT + 1` +FILTER="(&(objectclass=person)(uid=dots))" +ATTRS="cn mail telephonenumber" +echo "Query $CNT: filter:$FILTER attrs:$ATTRS" +echo "# Query $CNT: filter:$FILTER attrs:$ATTRS" >> $SEARCHOUT +$LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ + "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +$LDAPMODIFY -x -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < /dev/null 2>&1 +dn: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com +changetype: modify +replace: mail +mail: dots@admin.example2.com +- + +EOF + +SLEEP=`expr $PCACHETTR + $PCACHE_CCPERIOD` +echo "Waiting $SLEEP seconds for cache to refresh" + +sleep $SLEEP + +echo "Checking entry again" +$LDAPSEARCH -x -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ + "$FILTER" $ATTRS >> $SEARCHOUT 2>> $TESTOUT +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +grep "^mail: dots@admin" $SEARCHOUT > /dev/null +RC=$? +if test $RC != 0 ; then + echo "Refresh failed" + test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait + exit 0 +fi + +echo "" +echo "Testing Bind caching" + +CNT=`expr $CNT + 1` +USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com" +UPASSWD="jaj" +echo "Query $CNT: $USERDN" +echo "# Query $CNT: $USERDN" >> $SEARCHOUT +$LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \ + -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +grep "CACHING BIND" $LOG2 > /dev/null +RC=$? +if test $RC != 0 ; then + echo "Refresh failed" + test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait + exit 0 +fi + +CNT=`expr $CNT + 1` +USERDN="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com" +UPASSWD="jaj" +echo "Query $CNT: (Bind should be cached)" +echo "# Query $CNT: (Bind should be cached)" >> $SEARCHOUT +$LDAPSEARCH -S "" -b "" -s base -h $LOCALHOST -p $PORT2 \ + -D "$USERDN" -w "$UPASSWD" >> $SEARCHOUT 2>> $TESTOUT +RC=$? +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +grep "CACHED BIND" $LOG2 > /dev/null +RC=$? +if test $RC != 0 ; then + echo "Refresh failed" + test $KILLSERVERS != no && kill -HUP $KILLPIDS && wait + exit 0 +fi + +test $KILLSERVERS != no && kill -HUP $KILLPIDS + echo ">>>>> Test succeeded" test $KILLSERVERS != no && wait