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 2016-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 ## ACKNOWLEDGEMENTS:
     17 ## This module was written in 2016 by Ondej Kuznk for Symas Corp.
     18 
     19 echo "running defines.sh"
     20 . $SRCDIR/scripts/defines.sh
     21 
     22 . ${SCRIPTDIR}/common.sh
     23 
     24 echo "Adding entries (should fail this time)..."
     25 $LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
     26 	-c -f data/test002-entry.ldif >> $TESTOUT 2>&1
     27 RC=$?
     28 case $RC in
     29 0)
     30 	echo "ldapmodify should have failed ($RC)!"
     31 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     32 	exit 1
     33 	;;
     34 19)
     35 	echo "ldapmodify failed ($RC)"
     36 	;;
     37 *)
     38 	echo "ldapmodify failed ($RC)!"
     39 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     40 	exit $RC
     41 	;;
     42 esac
     43 
     44 echo "Adding other entries (should fail)..."
     45 $LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
     46 	-f data/test002-fail.ldif >> $TESTOUT 2>&1
     47 RC=$?
     48 case $RC in
     49 0)
     50 	echo "ldapmodify should have failed ($RC)!"
     51 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     52 	exit 1
     53 	;;
     54 19)
     55 	echo "ldapmodify failed ($RC)"
     56 	;;
     57 *)
     58 	echo "ldapmodify failed ($RC)!"
     59 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     60 	exit $RC
     61 	;;
     62 esac
     63 
     64 $LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
     65 	-f data/test002-transformed-rdn.ldif >> $TESTOUT 2>&1
     66 RC=$?
     67 case $RC in
     68 0)
     69 	echo "ldapmodify should have failed ($RC)!"
     70 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     71 	exit 1
     72 	;;
     73 32)
     74 	echo "ldapmodify failed ($RC)"
     75 	;;
     76 *)
     77 	echo "ldapmodify failed ($RC)!"
     78 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     79 	exit $RC
     80 	;;
     81 esac
     82 
     83 echo "Configuring new value..."
     84 . $CONFFILTER $BACKEND $MONITORDB < data/test002-config.ldif | \
     85 $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
     86 	>> $TESTOUT 2>&1
     87 RC=$?
     88 if test $RC != 0 ; then
     89 	echo "ldapmodify failed ($RC)!"
     90 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     91 	exit $RC
     92 fi
     93 
     94 echo "Adding some of the entries again..."
     95 $LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \
     96 	-f data/test002-entry.ldif >> $TESTOUT 2>&1
     97 RC=$?
     98 if test $RC != 0 ; then
     99 	echo "ldapmodify failed ($RC)!"
    100 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    101 	exit $RC
    102 fi
    103 
    104 echo "Saving search output..."
    105 $LDAPSEARCH -H $URI1 -b "$BASEDN" \
    106 	"(|(cn=Gern Jensen)(ou=New Unit))" \
    107 	>> $SEARCHOUT 2>&1
    108 RC=$?
    109 if test $RC != 0 ; then
    110 	echo "ldapsearch failed ($RC)!"
    111 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    112 	exit $RC
    113 fi
    114 
    115 echo "Removing entry..."
    116 $LDAPDELETE -D $MANAGERDN -H $URI1 -w $PASSWD \
    117 	"cn=Gern Jensen,ou=Information Technology Division,ou=People,$BASEDN" \
    118 	"ou=New Unit,$BASEDN" \
    119 	>> $TESTOUT 2>&1
    120 RC=$?
    121 if test $RC != 0 ; then
    122 	echo "ldapdelete failed ($RC)!"
    123 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    124 	exit $RC
    125 fi
    126 
    127 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    128 
    129 LDIF=data/test002-entry.ldif
    130 
    131 echo "Filtering ldapsearch results..."
    132 $LDIFFILTER -s ae < $SEARCHOUT > $SEARCHFLT
    133 echo "Filtering expected entries..."
    134 $LDIFFILTER -s ae < $LDIF | grep -v '^changetype:' > $LDIFFLT
    135 echo "Comparing filter output..."
    136 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    137 
    138 if test $? != 0 ; then
    139 	echo "Comparison failed"
    140 	exit 1
    141 fi
    142 
    143 echo ">>>>> Test succeeded"
    144 
    145 test $KILLSERVERS != no && wait
    146 
    147 exit 0
    148