From 245bb35eca7cbf7c9e0ca2ac39f47d61a27c49f7 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Sat, 15 Nov 2008 16:51:56 +0000 Subject: [PATCH] Add a test for attribute value regex substitution. Cf ITS#5804 --- tests/data/slapd-valregex.conf | 73 ++++++++++++++++++++ tests/scripts/defines.sh | 1 + tests/scripts/test055-valregex | 121 +++++++++++++++++++++++++++++++++ 3 files changed, 195 insertions(+) create mode 100644 tests/data/slapd-valregex.conf create mode 100755 tests/scripts/test055-valregex diff --git a/tests/data/slapd-valregex.conf b/tests/data/slapd-valregex.conf new file mode 100644 index 0000000000..ecded22db1 --- /dev/null +++ b/tests/data/slapd-valregex.conf @@ -0,0 +1,73 @@ +# master slapd config -- for testing +# $OpenLDAP$ +## This work is part of OpenLDAP Software . +## +## Copyright 1998-2008 The OpenLDAP Foundation. +## All rights reserved. +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted only as authorized by the OpenLDAP +## Public License. +## +## A copy of this license is available in the file LICENSE in the +## top-level directory of the distribution or, alternatively, at +## . + +include @SCHEMADIR@/core.schema +include @SCHEMADIR@/cosine.schema +include @SCHEMADIR@/inetorgperson.schema +include @SCHEMADIR@/openldap.schema +include @SCHEMADIR@/nis.schema +pidfile @TESTDIR@/slapd.1.pid +argsfile @TESTDIR@/slapd.1.args + +# global ACLs +# +# normal installations should protect root dse, cn=monitor, cn=subschema +# + +access to dn.exact="" attrs=objectClass + by users read +access to * + by * read + +#mod#modulepath ../servers/slapd/back-@BACKEND@/ +#mod#moduleload back_@BACKEND@.la +#monitormod#modulepath ../servers/slapd/back-monitor/ +#monitormod#moduleload back_monitor.la + +####################################################################### +# database definitions +####################################################################### + +database @BACKEND@ + +suffix "dc=example,dc=com" +directory @TESTDIR@/db.1.a +rootdn "cn=Manager,dc=example,dc=com" +rootpw secret +#bdb#index objectClass eq +#bdb#index cn,sn,uid pres,eq,sub +#hdb#index objectClass eq +#hdb#index cn,sn,uid pres,eq,sub +#ndb#dbname db_1 +#ndb#include @DATADIR@/ndb.conf + +access to attrs=userPassword + by anonymous auth + by * none stop + +access to attrs=sn val.regex="^(.*)$" + by dn.exact,expand="cn=${v1},ou=Alumni Association,ou=People,dc=example,dc=com" write + by * read stop + +access to attrs=sn val.regex="." + by * read stop + +access to attrs=sn + by dn.exact="cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com" write + by * read stop + +# fall into global ACLs + +#monitor#database monitor diff --git a/tests/scripts/defines.sh b/tests/scripts/defines.sh index 6f77c0c5bf..f8813125cc 100755 --- a/tests/scripts/defines.sh +++ b/tests/scripts/defines.sh @@ -131,6 +131,7 @@ DDSCONF=$DATADIR/slapd-dds.conf PASSWDCONF=$DATADIR/slapd-passwd.conf UNDOCONF=$DATADIR/slapd-config-undo.conf NAKEDCONF=$DATADIR/slapd-config-naked.conf +VALREGEXCONF=$DATADIR/slapd-valregex.conf DYNAMICCONF=$DATADIR/slapd-dynamic.ldif diff --git a/tests/scripts/test055-valregex b/tests/scripts/test055-valregex new file mode 100755 index 0000000000..4c18a0ce2c --- /dev/null +++ b/tests/scripts/test055-valregex @@ -0,0 +1,121 @@ +#! /bin/sh +# $OpenLDAP$ +## This work is part of OpenLDAP Software . +## +## Copyright 1998-2008 The OpenLDAP Foundation. +## All rights reserved. +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted only as authorized by the OpenLDAP +## Public License. +## +## A copy of this license is available in the file LICENSE in the +## top-level directory of the distribution or, alternatively, at +## . + +case "$BACKEND" in +bdb|hdb) + ;; +*) + echo "Test does not support $BACKEND backend" + exit 0 +esac + +echo "running defines.sh" +. $SRCDIR/scripts/defines.sh +LVL=acl + +mkdir -p $TESTDIR $DBDIR1 + +echo "Running slapadd to build slapd database..." +. $CONFFILTER $BACKEND $MONITORDB < $VALREGEXCONF > $CONF1 +$SLAPADD -f $CONF1 -l $LDIFORDERED +RC=$? +if test $RC != 0 ; then + echo "slapadd failed ($RC)!" + exit $RC +fi + +echo "Starting slapd on TCP/IP port $PORT1..." +$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & +PID=$! +if test $WAIT != 0 ; then + echo PID $PID + read foo +fi +KILLPIDS="$PID" + +sleep 1 + +echo "Testing attribute value regex subsitution..." +for i in 0 1 2 3 4 5; do + $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ + 'objectclass=*' > /dev/null 2>&1 + RC=$? + if test $RC = 0 ; then + break + fi + echo "Waiting 5 seconds for slapd to start..." + sleep 5 +done + +if test $RC != 0 ; then + echo "ldapsearch failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC +fi + +cat /dev/null > $SEARCHOUT + +echo "# Try an attribute vale regex that match, but substitute does not" +echo "# this should fail" +$LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \ + $TESTOUT 2>&1 << EOMODS +dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com +changetype: modify +replace: sn +sn: foobarbuz +EOMODS +RC=$? +case $RC in +50) + echo "ldapmodify failed as expected" + ;; +0) + echo "ldapmodify should have failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit -1 + ;; +*) + echo "ldapmodify failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC + ;; +esac + +echo "# Try an attribute vale regex that match and substitute does" +echo "# this should succeed" +$LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \ + $TESTOUT 2>&1 << EOMODS +dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com +changetype: modify +replace: sn +sn: James A Jones 1 +EOMODS +RC=$? +case $RC in +0) + echo "ldapmodify succeed as expected" + ;; +*) + echo "ldapmodify failed ($RC)!" + test $KILLSERVERS != no && kill -HUP $KILLPIDS + exit $RC + ;; +esac + +echo ">>>>> Test succeeded" + +test $KILLSERVERS != no && wait + +exit 0 -- 2.39.5