Home | History | Annotate | Line # | Download | only in scripts
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2024 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 echo "running defines.sh"
     17 . $SRCDIR/scripts/defines.sh
     18 LVL=acl
     19 
     20 mkdir -p $TESTDIR $DBDIR1
     21 
     22 echo "Running slapadd to build slapd database..."
     23 . $CONFFILTER $BACKEND < $VALREGEXCONF > $CONF1
     24 $SLAPADD -f $CONF1 -l $LDIFORDERED
     25 RC=$?
     26 if test $RC != 0 ; then
     27 	echo "slapadd failed ($RC)!"
     28 	exit $RC
     29 fi
     30 
     31 echo "Starting slapd on TCP/IP port $PORT1..."
     32 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
     33 PID=$!
     34 if test $WAIT != 0 ; then
     35     echo PID $PID
     36     read foo
     37 fi
     38 KILLPIDS="$PID"
     39 
     40 sleep 1
     41 
     42 echo "Testing attribute value regex substitution..."
     43 for i in 0 1 2 3 4 5; do
     44 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
     45 		'objectclass=*' > /dev/null 2>&1
     46 	RC=$?
     47 	if test $RC = 0 ; then
     48 		break
     49 	fi
     50 	echo "Waiting 5 seconds for slapd to start..."
     51 	sleep 5
     52 done
     53 
     54 if test $RC != 0 ; then
     55 	echo "ldapsearch failed ($RC)!"
     56 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     57 	exit $RC
     58 fi
     59 
     60 cat /dev/null > $SEARCHOUT
     61 
     62 echo "# Try an attribute vale regex that match, but substitute does not"
     63 echo "# this should fail"
     64 $LDAPMODIFY -D "$JAJDN" -H $URI1 -w jaj >> \
     65 	$TESTOUT 2>&1 << EOMODS
     66 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
     67 changetype: modify
     68 replace: sn
     69 sn: foobarbuz
     70 EOMODS
     71 RC=$?
     72 case $RC in
     73 50)
     74 	echo "ldapmodify failed as expected"
     75 	;;
     76 0)
     77 	if test $BACKEND != null ; then
     78 		echo "ldapmodify should have failed ($RC)!"
     79 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
     80 		exit 1
     81 	fi
     82 	;;
     83 *)
     84 	echo "ldapmodify failed ($RC)!"
     85 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     86 	exit $RC
     87 	;;
     88 esac
     89 
     90 echo "# Try an attribute vale regex that match and substitute does"
     91 echo "# this should succeed"
     92 $LDAPMODIFY -D "$JAJDN" -H $URI1 -w jaj >> \
     93 	$TESTOUT 2>&1 << EOMODS
     94 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
     95 changetype: modify
     96 replace: sn
     97 sn: James A Jones 1
     98 EOMODS
     99 RC=$?
    100 
    101 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    102 
    103 case $RC in
    104 0)
    105 	echo "ldapmodify succeed as expected"
    106 	;;
    107 *)
    108 	echo "ldapmodify failed ($RC)!"
    109 	exit $RC
    110 	;;
    111 esac
    112 
    113 echo ">>>>> Test succeeded"
    114 
    115 test $KILLSERVERS != no && wait
    116 
    117 exit 0
    118