mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-23 16:19:35 -05:00
Add a test for attribute value regex substitution. Cf ITS#5804
This commit is contained in:
parent
03b0a71014
commit
245bb35eca
3 changed files with 195 additions and 0 deletions
73
tests/data/slapd-valregex.conf
Normal file
73
tests/data/slapd-valregex.conf
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# master slapd config -- for testing
|
||||
# $OpenLDAP$
|
||||
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
##
|
||||
## 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
|
||||
## <http://www.OpenLDAP.org/license.html>.
|
||||
|
||||
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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
121
tests/scripts/test055-valregex
Executable file
121
tests/scripts/test055-valregex
Executable file
|
|
@ -0,0 +1,121 @@
|
|||
#! /bin/sh
|
||||
# $OpenLDAP$
|
||||
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
||||
##
|
||||
## 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
|
||||
## <http://www.OpenLDAP.org/license.html>.
|
||||
|
||||
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
|
||||
Loading…
Reference in a new issue