Home | History | Annotate | Line # | Download | only in scripts
test062-config-delete revision 1.1
      1  1.1  christos #! /bin/sh
      2  1.1  christos # $OpenLDAP$
      3  1.1  christos ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4  1.1  christos ##
      5  1.1  christos ## Copyright 1998-2021 The OpenLDAP Foundation.
      6  1.1  christos ## All rights reserved.
      7  1.1  christos ##
      8  1.1  christos ## Redistribution and use in source and binary forms, with or without
      9  1.1  christos ## modification, are permitted only as authorized by the OpenLDAP
     10  1.1  christos ## Public License.
     11  1.1  christos ##
     12  1.1  christos ## A copy of this license is available in the file LICENSE in the
     13  1.1  christos ## top-level directory of the distribution or, alternatively, at
     14  1.1  christos ## <http://www.OpenLDAP.org/license.html>.
     15  1.1  christos 
     16  1.1  christos echo "running defines.sh"
     17  1.1  christos . $SRCDIR/scripts/defines.sh
     18  1.1  christos 
     19  1.1  christos if test $SYNCPROV = syncprovno; then
     20  1.1  christos 	echo "Syncrepl provider overlay not available, test skipped"
     21  1.1  christos 	exit 0
     22  1.1  christos fi
     23  1.1  christos 
     24  1.1  christos CONFDIR=$TESTDIR/slapd.d
     25  1.1  christos DBDIR=$TESTDIR/db
     26  1.1  christos RCOUT=$TESTDIR/rcout
     27  1.1  christos 
     28  1.1  christos mkdir -p $TESTDIR $CONFDIR $DBDIR
     29  1.1  christos 
     30  1.1  christos $SLAPPASSWD -g -n >$CONFIGPWF
     31  1.1  christos 
     32  1.1  christos #
     33  1.1  christos # Test dynamic add/delete of syncprov overlay:
     34  1.1  christos # - Create minimal back-conf setup
     35  1.1  christos # - Add syncprov overlay to the cn=config database
     36  1.1  christos # - Remove the overlay again
     37  1.1  christos #
     38  1.1  christos 
     39  1.1  christos echo "Starting slapd on TCP/IP port $PORT1... $PWD"
     40  1.1  christos . $CONFFILTER $BACKEND < $DYNAMICCONF > $CONFLDIF
     41  1.1  christos $SLAPADD -F $CONFDIR -n 0 -l $CONFLDIF
     42  1.1  christos cd $TESTDIR
     43  1.1  christos $SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
     44  1.1  christos PID=$!
     45  1.1  christos if test $WAIT != 0 ; then
     46  1.1  christos     echo PID $PID
     47  1.1  christos     read foo
     48  1.1  christos fi
     49  1.1  christos KILLPIDS="$PID"
     50  1.1  christos cd $TESTWD
     51  1.1  christos 
     52  1.1  christos sleep 1
     53  1.1  christos 
     54  1.1  christos echo "Using ldapsearch to check that slapd is running..."
     55  1.1  christos for i in 0 1 2 3 4 5; do
     56  1.1  christos 	$LDAPSEARCH -s base -b "" -H $URI1 \
     57  1.1  christos 		'objectclass=*' > /dev/null 2>&1
     58  1.1  christos 	RC=$?
     59  1.1  christos 	if test $RC = 0 ; then
     60  1.1  christos 		break
     61  1.1  christos 	fi
     62  1.1  christos 	echo "Waiting 5 seconds for slapd to start..."
     63  1.1  christos 	sleep 5
     64  1.1  christos done
     65  1.1  christos 
     66  1.1  christos if test $RC != 0 ; then
     67  1.1  christos 	echo "ldapsearch failed ($RC)!"
     68  1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     69  1.1  christos 	exit $RC
     70  1.1  christos fi
     71  1.1  christos 
     72  1.1  christos echo "Inserting syncprov overlay ..."
     73  1.1  christos if [ "$SYNCPROV" = syncprovmod ]; then
     74  1.1  christos 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
     75  1.1  christos dn: cn=module,cn=config
     76  1.1  christos objectClass: olcModuleList
     77  1.1  christos cn: module
     78  1.1  christos olcModulePath: $TESTWD/../servers/slapd/overlays
     79  1.1  christos olcModuleLoad: syncprov.la
     80  1.1  christos EOF
     81  1.1  christos 	RC=$?
     82  1.1  christos 	if test $RC != 0 ; then
     83  1.1  christos 		echo "ldapadd failed for moduleLoad ($RC)!"
     84  1.1  christos 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
     85  1.1  christos 		exit $RC
     86  1.1  christos 	fi
     87  1.1  christos fi
     88  1.1  christos read CONFIGPW < $CONFIGPWF
     89  1.1  christos $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
     90  1.1  christos dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
     91  1.1  christos changetype: add
     92  1.1  christos objectClass: olcOverlayConfig
     93  1.1  christos objectClass: olcSyncProvConfig
     94  1.1  christos olcOverlay: syncprov
     95  1.1  christos EOF
     96  1.1  christos 
     97  1.1  christos RC=$?
     98  1.1  christos if test $RC != 0 ; then
     99  1.1  christos 	echo "ldapmodify failed for syncrepl config ($RC)!"
    100  1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    101  1.1  christos 	exit $RC
    102  1.1  christos fi
    103  1.1  christos 
    104  1.1  christos echo "Starting a refreshAndPersist search in background"
    105  1.1  christos rm -f $RCOUT
    106  1.1  christos (
    107  1.1  christos   $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=rp >/dev/null 2>&1
    108  1.1  christos   RC=$?
    109  1.1  christos   echo $RC > $RCOUT
    110  1.1  christos   exit $RC
    111  1.1  christos ) &
    112  1.1  christos 
    113  1.1  christos SEARCHPID=$!
    114  1.1  christos 
    115  1.1  christos sleep 2
    116  1.1  christos 
    117  1.1  christos echo "Removing syncprov overlay again ..."
    118  1.1  christos $LDAPDELETE -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    119  1.1  christos olcOverlay={0}syncprov,olcDatabase={0}config,cn=config
    120  1.1  christos EOF
    121  1.1  christos RC=$?
    122  1.1  christos 
    123  1.1  christos if test $RC != 0 ; then
    124  1.1  christos 	echo "ldapmodify failed for syncrepl config ($RC)!"
    125  1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    126  1.1  christos 	exit $RC
    127  1.1  christos fi
    128  1.1  christos 
    129  1.1  christos for i in 0 1 2 3 4; do
    130  1.1  christos 	if test -f "$RCOUT" ; then
    131  1.1  christos 		break
    132  1.1  christos 	else
    133  1.1  christos 		echo "Waiting 2 seconds for RefreshAndPersist search to end ..."
    134  1.1  christos 		sleep 2
    135  1.1  christos 	fi
    136  1.1  christos done
    137  1.1  christos 
    138  1.1  christos if test -f "$RCOUT" ; then
    139  1.1  christos 	wait $SEARCHPID
    140  1.1  christos 	SEARCHRC=`cat $RCOUT`
    141  1.1  christos 	echo "Checking return code of backgrounded RefreshAndPersist search ..."
    142  1.1  christos 	if test 52 != "$SEARCHRC" ; then
    143  1.1  christos 		echo "Error: Backgrounded ldapsearch returned the wrong error code: $SEARCHRC"
    144  1.1  christos 		RC=1
    145  1.1  christos 	else
    146  1.1  christos 		echo "Exit code correct."
    147  1.1  christos 	fi
    148  1.1  christos else
    149  1.1  christos 	echo "Backgrounded ldapsearch did not exit after overlay removal."
    150  1.1  christos 	kill -HUP $SEARCHPID
    151  1.1  christos 	RC=2
    152  1.1  christos fi
    153  1.1  christos if test $RC != 0 ; then
    154  1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    155  1.1  christos 	exit $RC
    156  1.1  christos fi
    157  1.1  christos 
    158  1.1  christos echo "Running a refreshOnly search, should fail..."
    159  1.1  christos $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=ro > /dev/null 2>&1
    160  1.1  christos 
    161  1.1  christos RC=$?
    162  1.1  christos if test $RC != 12 ; then
    163  1.1  christos 	echo "ldapsearch should have failed with Critical extension is unavailable (12)!"
    164  1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    165  1.1  christos 	exit $RC
    166  1.1  christos else
    167  1.1  christos 	echo "Failed with \"Critical extension is unavailable (12)\". Ok."
    168  1.1  christos fi
    169  1.1  christos 
    170  1.1  christos 
    171  1.1  christos test $KILLSERVERS != no && kill -HUP $KILLPIDS
    172  1.1  christos 
    173  1.1  christos echo ">>>>> Test succeeded"
    174  1.1  christos 
    175  1.1  christos test $KILLSERVERS != no && wait
    176  1.1  christos 
    177  1.1  christos exit 0
    178