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 $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
     30 	> $TESTOUT 2>&1 <<EOMOD
     31 dn: olcOverlay={0}variant,olcDatabase={1}$BACKEND,cn=config
     32 changetype: modify
     33 replace: olcVariantPassReplication
     34 olcVariantPassReplication: FALSE
     35 EOMOD
     36 RC=$?
     37 if test $RC != 0 ; then
     38 	echo "ldapmodify failed ($RC)!"
     39 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     40 	exit $RC
     41 fi
     42 
     43 if test "$SYNCPROV" = syncprovmod; then
     44 	$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
     45 	> $TESTOUT 2>&1 <<EOMOD
     46 dn: cn=module{0},cn=config
     47 changetype: modify
     48 add: olcModuleLoad
     49 olcModuleLoad: $LDAP_BUILD/servers/slapd/overlays/syncprov.la
     50 EOMOD
     51 
     52 	RC=$?
     53 	if test $RC != 0 ; then
     54 		echo "ldapmodify failed ($RC)!"
     55 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
     56 		exit $RC
     57 	fi
     58 fi
     59 
     60 echo "Configuring syncprov on the provider..."
     61 $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
     62 	> $TESTOUT 2>&1 <<EOMOD
     63 dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
     64 changetype: add
     65 objectclass: olcSyncProvConfig
     66 EOMOD
     67 RC=$?
     68 if test $RC != 0 ; then
     69 	echo "ldapmodify failed ($RC)!"
     70 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     71 	exit $RC
     72 fi
     73 
     74 mkdir $DBDIR4
     75 
     76 echo "Starting consumer slapd on TCP/IP port $PORT4..."
     77 . $CONFFILTER $BACKEND $MONITORDB < $P1SRCONSUMERCONF > $CONF4
     78 $SLAPD -f $CONF4 -h $URI4 -d $LVL > $LOG4 2>&1 &
     79 CONSUMERPID=$!
     80 if test $WAIT != 0 ; then
     81 	echo CONSUMERPID $CONSUMERPID
     82 	read foo
     83 fi
     84 KILLPIDS="$KILLPIDS $CONSUMERPID"
     85 
     86 sleep $SLEEP0
     87 
     88 for i in 0 1 2 3 4 5; do
     89 	$LDAPSEARCH -s base -b "$BASEDN" -H $URI4 \
     90 		'objectclass=*' > /dev/null 2>&1
     91 	RC=$?
     92 	if test $RC = 0 ; then
     93 		break
     94 	fi
     95 	echo "Waiting ${SLEEP1} seconds for consumer to start replication..."
     96 	sleep ${SLEEP1}
     97 done
     98 
     99 echo "Waiting ${SLEEP1} seconds for consumer to finish replicating..."
    100 sleep ${SLEEP1}
    101 
    102 echo "Testing searches against regular entries..."
    103 echo "# Testing searches against regular entries..." >> $SEARCHOUT
    104 $LDAPSEARCH -b "$BASEDN" -H $URI4 \
    105 	"(|(name=Elliot)(description=*hiker*))" \
    106 	>> $SEARCHOUT 2>&1
    107 RC=$?
    108 if test $RC != 0 ; then
    109 	echo "ldapsearch failed ($RC)!"
    110 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    111 	exit $RC
    112 fi
    113 
    114 echo "Testing searches listing replicated variants..."
    115 echo >> $SEARCHOUT
    116 echo "# Testing searches listing replicated variants..." >> $SEARCHOUT
    117 $LDAPSEARCH -b "$BASEDN" -s one -H $URI4 \
    118 	>> $SEARCHOUT 2>&1
    119 RC=$?
    120 if test $RC != 0 ; then
    121 	echo "ldapsearch failed ($RC)!"
    122 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    123 	exit $RC
    124 fi
    125 
    126 # regex variants do not replicate correctly and this is documented
    127 echo >> $SEARCHOUT
    128 $LDAPSEARCH -b "$BASEDN" -s base -H $URI1 \
    129 	>> $SEARCHOUT 2>&1
    130 RC=$?
    131 if test $RC != 0 ; then
    132 	echo "ldapsearch failed ($RC)!"
    133 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    134 	exit $RC
    135 fi
    136 
    137 # regex variants do not replicate correctly and this is documented
    138 echo >> $SEARCHOUT
    139 $LDAPSEARCH -s base -H $URI1 \
    140 	-b "cn=Bjorn Jensen,ou=Information Technology Division,ou=People,$BASEDN" \
    141 	'(ou=Information Technology Division)' \
    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 # regex variants do not replicate correctly and this is documented
    151 echo >> $SEARCHOUT
    152 $LDAPSEARCH -b "cn=ITD Staff,ou=Groups,$BASEDN" -s base -H $URI1 \
    153 	>> $SEARCHOUT 2>&1
    154 RC=$?
    155 if test $RC != 0 ; then
    156 	echo "ldapsearch failed ($RC)!"
    157 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    158 	exit $RC
    159 fi
    160 
    161 echo "Testing searches filtering on replicated variants..."
    162 echo >> $SEARCHOUT
    163 echo "# Testing searches filtering on replicated variants..." >> $SEARCHOUT
    164 $LDAPSEARCH -b "$BASEDN" -H $URI4 \
    165 	"(st=Alumni Association)" st \
    166 	>> $SEARCHOUT 2>&1
    167 RC=$?
    168 if test $RC != 0 ; then
    169 	echo "ldapsearch failed ($RC)!"
    170 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    171 	exit $RC
    172 fi
    173 
    174 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    175 
    176 LDIF=data/test003-out.ldif
    177 
    178 echo "Filtering ldapsearch results..."
    179 $LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
    180 echo "Filtering expected entries..."
    181 $LDIFFILTER -s e < $LDIF > $LDIFFLT
    182 echo "Comparing filter output..."
    183 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    184 
    185 if test $? != 0 ; then
    186 	echo "Comparison failed"
    187 	exit 1
    188 fi
    189 
    190 echo ">>>>> Test succeeded"
    191 
    192 test $KILLSERVERS != no && wait
    193 
    194 exit 0
    195