Home | History | Annotate | Line # | Download | only in scripts
test062-config-delete revision 1.1.1.2
      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.1.2  christos ## Copyright 1998-2024 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.1.2  christos RC=$?
     43  1.1.1.2  christos if test $RC != 0 ; then
     44  1.1.1.2  christos 	echo "slapadd failed ($RC)!"
     45  1.1.1.2  christos 	exit $RC
     46  1.1.1.2  christos fi
     47  1.1.1.2  christos 
     48      1.1  christos cd $TESTDIR
     49      1.1  christos $SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
     50      1.1  christos PID=$!
     51      1.1  christos if test $WAIT != 0 ; then
     52      1.1  christos     echo PID $PID
     53      1.1  christos     read foo
     54      1.1  christos fi
     55      1.1  christos KILLPIDS="$PID"
     56      1.1  christos cd $TESTWD
     57      1.1  christos 
     58      1.1  christos sleep 1
     59      1.1  christos 
     60      1.1  christos echo "Using ldapsearch to check that slapd is running..."
     61      1.1  christos for i in 0 1 2 3 4 5; do
     62      1.1  christos 	$LDAPSEARCH -s base -b "" -H $URI1 \
     63      1.1  christos 		'objectclass=*' > /dev/null 2>&1
     64      1.1  christos 	RC=$?
     65      1.1  christos 	if test $RC = 0 ; then
     66      1.1  christos 		break
     67      1.1  christos 	fi
     68      1.1  christos 	echo "Waiting 5 seconds for slapd to start..."
     69      1.1  christos 	sleep 5
     70      1.1  christos done
     71      1.1  christos 
     72      1.1  christos if test $RC != 0 ; then
     73      1.1  christos 	echo "ldapsearch failed ($RC)!"
     74      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     75      1.1  christos 	exit $RC
     76      1.1  christos fi
     77      1.1  christos 
     78      1.1  christos echo "Inserting syncprov overlay ..."
     79      1.1  christos if [ "$SYNCPROV" = syncprovmod ]; then
     80      1.1  christos 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
     81      1.1  christos dn: cn=module,cn=config
     82      1.1  christos objectClass: olcModuleList
     83      1.1  christos cn: module
     84      1.1  christos olcModulePath: $TESTWD/../servers/slapd/overlays
     85      1.1  christos olcModuleLoad: syncprov.la
     86      1.1  christos EOF
     87      1.1  christos 	RC=$?
     88      1.1  christos 	if test $RC != 0 ; then
     89      1.1  christos 		echo "ldapadd failed for moduleLoad ($RC)!"
     90      1.1  christos 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
     91      1.1  christos 		exit $RC
     92      1.1  christos 	fi
     93      1.1  christos fi
     94      1.1  christos read CONFIGPW < $CONFIGPWF
     95      1.1  christos $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
     96      1.1  christos dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
     97      1.1  christos changetype: add
     98      1.1  christos objectClass: olcOverlayConfig
     99      1.1  christos objectClass: olcSyncProvConfig
    100      1.1  christos olcOverlay: syncprov
    101      1.1  christos EOF
    102      1.1  christos 
    103      1.1  christos RC=$?
    104      1.1  christos if test $RC != 0 ; then
    105      1.1  christos 	echo "ldapmodify failed for syncrepl config ($RC)!"
    106      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    107      1.1  christos 	exit $RC
    108      1.1  christos fi
    109      1.1  christos 
    110      1.1  christos echo "Starting a refreshAndPersist search in background"
    111      1.1  christos rm -f $RCOUT
    112      1.1  christos (
    113      1.1  christos   $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=rp >/dev/null 2>&1
    114      1.1  christos   RC=$?
    115      1.1  christos   echo $RC > $RCOUT
    116      1.1  christos   exit $RC
    117      1.1  christos ) &
    118      1.1  christos 
    119      1.1  christos SEARCHPID=$!
    120      1.1  christos 
    121      1.1  christos sleep 2
    122      1.1  christos 
    123      1.1  christos echo "Removing syncprov overlay again ..."
    124      1.1  christos $LDAPDELETE -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    125      1.1  christos olcOverlay={0}syncprov,olcDatabase={0}config,cn=config
    126      1.1  christos EOF
    127      1.1  christos RC=$?
    128      1.1  christos 
    129      1.1  christos if test $RC != 0 ; then
    130      1.1  christos 	echo "ldapmodify failed for syncrepl config ($RC)!"
    131      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    132      1.1  christos 	exit $RC
    133      1.1  christos fi
    134      1.1  christos 
    135      1.1  christos for i in 0 1 2 3 4; do
    136      1.1  christos 	if test -f "$RCOUT" ; then
    137      1.1  christos 		break
    138      1.1  christos 	else
    139      1.1  christos 		echo "Waiting 2 seconds for RefreshAndPersist search to end ..."
    140      1.1  christos 		sleep 2
    141      1.1  christos 	fi
    142      1.1  christos done
    143      1.1  christos 
    144      1.1  christos if test -f "$RCOUT" ; then
    145      1.1  christos 	wait $SEARCHPID
    146      1.1  christos 	SEARCHRC=`cat $RCOUT`
    147      1.1  christos 	echo "Checking return code of backgrounded RefreshAndPersist search ..."
    148      1.1  christos 	if test 52 != "$SEARCHRC" ; then
    149      1.1  christos 		echo "Error: Backgrounded ldapsearch returned the wrong error code: $SEARCHRC"
    150      1.1  christos 		RC=1
    151      1.1  christos 	else
    152      1.1  christos 		echo "Exit code correct."
    153      1.1  christos 	fi
    154      1.1  christos else
    155      1.1  christos 	echo "Backgrounded ldapsearch did not exit after overlay removal."
    156      1.1  christos 	kill -HUP $SEARCHPID
    157      1.1  christos 	RC=2
    158      1.1  christos fi
    159      1.1  christos if test $RC != 0 ; then
    160      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    161      1.1  christos 	exit $RC
    162      1.1  christos fi
    163      1.1  christos 
    164      1.1  christos echo "Running a refreshOnly search, should fail..."
    165      1.1  christos $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=ro > /dev/null 2>&1
    166      1.1  christos 
    167      1.1  christos RC=$?
    168      1.1  christos if test $RC != 12 ; then
    169      1.1  christos 	echo "ldapsearch should have failed with Critical extension is unavailable (12)!"
    170      1.1  christos 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    171      1.1  christos 	exit $RC
    172      1.1  christos else
    173      1.1  christos 	echo "Failed with \"Critical extension is unavailable (12)\". Ok."
    174      1.1  christos fi
    175      1.1  christos 
    176      1.1  christos 
    177      1.1  christos test $KILLSERVERS != no && kill -HUP $KILLPIDS
    178      1.1  christos 
    179      1.1  christos echo ">>>>> Test succeeded"
    180      1.1  christos 
    181      1.1  christos test $KILLSERVERS != no && wait
    182      1.1  christos 
    183      1.1  christos exit 0
    184