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 if test "$SYNCPROV" = syncprovno; then 
     23 	echo "Syncrepl provider overlay not available, test skipped"
     24 	exit 0
     25 fi 
     26 
     27 . ${SCRIPTDIR}/common.sh
     28 
     29 if test "$SYNCPROV" = syncprovmod; then
     30 	$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
     31 	> $TESTOUT 2>&1 <<EOMOD
     32 dn: cn=module{0},cn=config
     33 changetype: modify
     34 add: olcModuleLoad
     35 olcModuleLoad: $LDAP_BUILD/servers/slapd/overlays/syncprov.la
     36 EOMOD
     37 
     38 	RC=$?
     39 	if test $RC != 0 ; then
     40 		echo "ldapmodify failed ($RC)!"
     41 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
     42 		exit $RC
     43 	fi
     44 fi
     45 
     46 echo "Configuring syncprov on the provider..."
     47 $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
     48 	> $TESTOUT 2>&1 <<EOMOD
     49 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
     50 changetype: add
     51 objectclass: olcSyncProvConfig
     52 EOMOD
     53 RC=$?
     54 if test $RC != 0 ; then
     55 	echo "ldapmodify failed ($RC)!"
     56 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     57 	exit $RC
     58 fi
     59 
     60 mkdir $DBDIR4 $TESTDIR/confdir-consumer
     61 
     62 echo "Starting consumer slapd on TCP/IP port $PORT4..."
     63 . $CONFFILTER $BACKEND $MONITORDB < $P1SRCONSUMERCONF > $CONF4
     64 
     65 echo "database config" >>$CONF4
     66 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF4
     67 
     68 $SLAPD -f $CONF4 -F $TESTDIR/confdir-consumer -h $URI4 -d $LVL > $LOG4 2>&1 &
     69 CONSUMERPID=$!
     70 if test $WAIT != 0 ; then
     71 	echo CONSUMERPID $CONSUMERPID
     72 	read foo
     73 fi
     74 KILLPIDS="$KILLPIDS $CONSUMERPID"
     75 
     76 sleep $SLEEP0
     77 
     78 echo "Setting up variant overlay on consumer..."
     79 $LDAPSEARCH -D cn=config -H $URI4 -y $CONFIGPWF \
     80 	-s base -b 'cn=module{0},cn=config' 1.1 >$TESTOUT 2>&1
     81 RC=$?
     82 case $RC in
     83 0)
     84 	$LDAPMODIFY -v -D cn=config -H $URI4 -y $CONFIGPWF \
     85 	>> $TESTOUT 2>&1 <<EOMOD
     86 dn: cn=module{0},cn=config
     87 changetype: modify
     88 add: olcModuleLoad
     89 olcModuleLoad: `pwd`/../variant.la
     90 EOMOD
     91 	;;
     92 32)
     93 	$LDAPMODIFY -v -D cn=config -H $URI4 -y $CONFIGPWF \
     94 	>> $TESTOUT 2>&1 <<EOMOD
     95 dn: cn=module,cn=config
     96 changetype: add
     97 objectClass: olcModuleList
     98 olcModuleLoad: `pwd`/../variant.la
     99 EOMOD
    100 	;;
    101 *)
    102 	echo "Failed testing for module load entry"
    103 	exit $RC;
    104 	;;
    105 esac
    106 
    107 RC=$?
    108 if test $RC != 0 ; then
    109 	echo "ldapmodify failed ($RC)!"
    110 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    111 	exit $RC
    112 fi
    113 
    114 . $CONFFILTER $BACKEND $MONITORDB < $OVERLAY_CONFIG | \
    115 $LDAPMODIFY -v -D cn=config -H $URI4 -y $CONFIGPWF \
    116 	> $TESTOUT 2>&1
    117 RC=$?
    118 if test $RC != 0 ; then
    119 	echo "ldapmodify failed ($RC)!"
    120 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    121 	exit $RC
    122 fi
    123 
    124 for i in 0 1 2 3 4 5; do
    125 	$LDAPSEARCH -s base -b "$BASEDN" -H $URI4 \
    126 		'objectclass=*' > /dev/null 2>&1
    127 	RC=$?
    128 	if test $RC = 0 ; then
    129 		break
    130 	fi
    131 	echo "Waiting ${SLEEP1} seconds for consumer to start replication..."
    132 	sleep ${SLEEP1}
    133 done
    134 
    135 echo "Waiting ${SLEEP1} seconds for consumer to finish replicating..."
    136 sleep ${SLEEP1}
    137 
    138 echo "Testing searches against regular entries..."
    139 echo "# Testing searches against regular entries..." >> $SEARCHOUT
    140 $LDAPSEARCH -b "$BASEDN" -H $URI4 \
    141 	"(|(name=Elliot)(description=*hiker*))" \
    142 	>> $SEARCHOUT 2>&1
    143 RC=$?
    144 if test $RC != 0 ; then
    145 	echo "ldapsearch failed ($RC)!"
    146 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    147 	exit $RC
    148 fi
    149 
    150 echo "Testing searches listing replicated variants..."
    151 echo >> $SEARCHOUT
    152 echo "# Testing searches listing replicated variants..." >> $SEARCHOUT
    153 $LDAPSEARCH -b "$BASEDN" -s one -H $URI4 \
    154 	>> $SEARCHOUT 2>&1
    155 RC=$?
    156 if test $RC != 0 ; then
    157 	echo "ldapsearch failed ($RC)!"
    158 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    159 	exit $RC
    160 fi
    161 
    162 echo >> $SEARCHOUT
    163 $LDAPSEARCH -b "$BASEDN" -s base -H $URI4 \
    164 	>> $SEARCHOUT 2>&1
    165 RC=$?
    166 if test $RC != 0 ; then
    167 	echo "ldapsearch failed ($RC)!"
    168 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    169 	exit $RC
    170 fi
    171 
    172 echo >> $SEARCHOUT
    173 $LDAPSEARCH -s base -H $URI4 \
    174 	-b "cn=Bjorn Jensen,ou=Information Technology Division,ou=People,$BASEDN" \
    175 	'(ou=Information Technology Division)' \
    176 	>> $SEARCHOUT 2>&1
    177 RC=$?
    178 if test $RC != 0 ; then
    179 	echo "ldapsearch failed ($RC)!"
    180 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    181 	exit $RC
    182 fi
    183 
    184 echo >> $SEARCHOUT
    185 $LDAPSEARCH -b "cn=ITD Staff,ou=Groups,$BASEDN" -s base -H $URI4 \
    186 	>> $SEARCHOUT 2>&1
    187 RC=$?
    188 if test $RC != 0 ; then
    189 	echo "ldapsearch failed ($RC)!"
    190 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    191 	exit $RC
    192 fi
    193 
    194 echo "Testing searches filtering on replicated variants..."
    195 echo >> $SEARCHOUT
    196 echo "# Testing searches filtering on replicated variants..." >> $SEARCHOUT
    197 $LDAPSEARCH -b "$BASEDN" -H $URI4 \
    198 	"(st=Alumni Association)" st \
    199 	>> $SEARCHOUT 2>&1
    200 RC=$?
    201 if test $RC != 0 ; then
    202 	echo "ldapsearch failed ($RC)!"
    203 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    204 	exit $RC
    205 fi
    206 
    207 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    208 
    209 LDIF=data/test003-out.ldif
    210 
    211 echo "Filtering ldapsearch results..."
    212 $LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
    213 echo "Filtering expected entries..."
    214 $LDIFFILTER -s e < $LDIF > $LDIFFLT
    215 echo "Comparing filter output..."
    216 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    217 
    218 if test $? != 0 ; then
    219 	echo "Comparison failed"
    220 	exit 1
    221 fi
    222 
    223 echo ">>>>> Test succeeded"
    224 
    225 test $KILLSERVERS != no && wait
    226 
    227 exit 0
    228