1#! /bin/sh 2## $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 2016-2021 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 Ondřej Kuzník for Symas Corp. 18 19echo "running defines.sh" 20. $SRCDIR/scripts/defines.sh 21 22if test "$SYNCPROV" = syncprovno; then 23 echo "Syncrepl provider overlay not available, test skipped" 24 exit 0 25fi 26 27. ${SCRIPTDIR}/common.sh 28 29if test "$SYNCPROV" = syncprovmod; then 30 $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \ 31 > $TESTOUT 2>&1 <<EOMOD 32dn: cn=module,cn=config 33changetype: add 34objectClass: olcModuleList 35olcModuleLoad: $LDAP_BUILD/servers/slapd/overlays/syncprov.la 36EOMOD 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 44fi 45 46mkdir $DBDIR4 $TESTDIR/confdir-consumer 47 48echo "Starting consumer slapd on TCP/IP port $PORT4..." 49. $CONFFILTER $BACKEND $MONITORDB < $P1SRCONSUMERCONF > $CONF4 50 51echo "database config" >>$CONF4 52echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF4 53 54$SLAPD -f $CONF4 -F $TESTDIR/confdir-consumer -h $URI4 -d $LVL > $LOG4 2>&1 & 55CONSUMERPID=$! 56if test $WAIT != 0 ; then 57 echo CONSUMERPID $CONSUMERPID 58 read foo 59fi 60KILLPIDS="$KILLPIDS $CONSUMERPID" 61 62sleep $SLEEP0 63 64echo "Setting up overlay on consumer..." 65$LDAPMODIFY -v -D cn=config -H $URI4 -y $CONFIGPWF \ 66 > $TESTOUT 2>&1 <<EOMOD 67dn: cn=module,cn=config 68changetype: add 69objectClass: olcModuleList 70olcModuleLoad: `pwd`/../datamorph.la 71EOMOD 72RC=$? 73if test $RC != 0 ; then 74 echo "ldapmodify failed ($RC)!" 75 test $KILLSERVERS != no && kill -HUP $KILLPIDS 76 exit $RC 77fi 78 79echo "Configuring syncprov on provider..." 80$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \ 81 > $TESTOUT 2>&1 <<EOMOD 82dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config 83changetype: add 84objectclass: olcSyncProvConfig 85EOMOD 86RC=$? 87if test $RC != 0 ; then 88 echo "ldapmodify failed ($RC)!" 89 test $KILLSERVERS != no && kill -HUP $KILLPIDS 90 exit $RC 91fi 92 93. $CONFFILTER $BACKEND $MONITORDB < $OVERLAY_CONFIG | \ 94$LDAPMODIFY -v -D cn=config -H $URI4 -y $CONFIGPWF \ 95 > $TESTOUT 2>&1 96RC=$? 97if test $RC != 0 ; then 98 echo "ldapmodify failed ($RC)!" 99 test $KILLSERVERS != no && kill -HUP $KILLPIDS 100 exit $RC 101fi 102 103for i in 0 1 2 3 4 5; do 104 $LDAPSEARCH -s base -b "$BASEDN" -H $URI4 \ 105 'objectclass=*' > /dev/null 2>&1 106 RC=$? 107 if test $RC = 0 ; then 108 break 109 fi 110 echo "Waiting ${SLEEP1} seconds for consumer to start replication..." 111 sleep ${SLEEP1} 112done 113 114echo "Waiting ${SLEEP1} seconds for consumer to finish replicating..." 115sleep ${SLEEP1} 116 117echo "Testing searches against regular replicated entries..." 118echo "# Testing searches against regular replicated entries..." >> $SEARCHOUT 119$LDAPSEARCH -b "$BASEDN" -H $URI4 "(|(ou=Groups)(st=*))" \ 120 >> $SEARCHOUT 2>&1 121RC=$? 122if test $RC != 0 ; then 123 echo "ldapsearch failed ($RC)!" 124 test $KILLSERVERS != no && kill -HUP $KILLPIDS 125 exit $RC 126fi 127 128echo "Testing searches listing replicated transformed attributes..." 129echo >> $SEARCHOUT 130echo "# Testing searches listing replicated transformed attributes..." >> $SEARCHOUT 131$LDAPSEARCH -b "ou=Information Technology Division,ou=People,$BASEDN" -s one \ 132 -H $URI4 \ 133 >> $SEARCHOUT 2>&1 134RC=$? 135if test $RC != 0 ; then 136 echo "ldapsearch failed ($RC)!" 137 test $KILLSERVERS != no && kill -HUP $KILLPIDS 138 exit $RC 139fi 140 141echo "Testing searches filtering on replicated transformed attributes..." 142echo >> $SEARCHOUT 143echo "# Testing searches filtering on replicated transformed attributes..." >> $SEARCHOUT 144$LDAPSEARCH -b "$BASEDN" -H $URI4 \ 145 "(|(enumerated=bjensen)(&(signed=-19858)(signed<=0)(signed>=-20000)))" \ 146 enumerated signed \ 147 >> $SEARCHOUT 2>&1 148RC=$? 149if test $RC != 0 ; then 150 echo "ldapsearch failed ($RC)!" 151 test $KILLSERVERS != no && kill -HUP $KILLPIDS 152 exit $RC 153fi 154 155echo "Reconfiguring transformation definition..." 156. $CONFFILTER $BACKEND $MONITORDB < data/test003-config.ldif | \ 157sed 's/{0}datamorph/{1}datamorph/' | \ 158$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \ 159 >> $TESTOUT 2>&1 160RC=$? 161if test $RC != 0 ; then 162 echo "ldapmodify failed ($RC)!" 163 test $KILLSERVERS != no && kill -HUP $KILLPIDS 164 exit $RC 165fi 166 167. $CONFFILTER $BACKEND $MONITORDB < data/test003-config.ldif | \ 168$LDAPMODIFY -v -D cn=config -H $URI4 -y $CONFIGPWF \ 169 >> $TESTOUT 2>&1 170RC=$? 171if test $RC != 0 ; then 172 echo "ldapmodify failed ($RC)!" 173 test $KILLSERVERS != no && kill -HUP $KILLPIDS 174 exit $RC 175fi 176 177echo "Testing searches filtering on the new replicated values..." 178echo >> $SEARCHOUT 179echo "# Testing searches filtering on the new replicated values..." >> $SEARCHOUT 180$LDAPSEARCH -b "$BASEDN" -H $URI4 \ 181 "(|(enumerated=not a value)(enumerated=jaj)(&(signed=45678)(!(signed>=50000))(signed>=44444)))" \ 182 enumerated signed \ 183 >> $SEARCHOUT 2>&1 184RC=$? 185if test $RC != 0 ; then 186 echo "ldapsearch failed ($RC)!" 187 test $KILLSERVERS != no && kill -HUP $KILLPIDS 188 exit $RC 189fi 190 191LDIF=data/test003-out.ldif 192 193echo "Filtering ldapsearch results..." 194$LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT 195echo "Filtering expected entries..." 196$LDIFFILTER -s e < $LDIF > $LDIFFLT 197echo "Comparing filter output..." 198$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 199 200if test $? != 0 ; then 201 echo "Comparison failed" 202 test $KILLSERVERS != no && kill -HUP $KILLPIDS 203 exit 1 204fi 205 206rm $SEARCHOUT 207 208echo "Reverting part of the above configuration for remainder of the test..." 209. $CONFFILTER $BACKEND $MONITORDB < data/test007-config.ldif | \ 210sed 's/{0}datamorph/{1}datamorph/' | \ 211$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \ 212 >> $TESTOUT 2>&1 213RC=$? 214if test $RC != 0 ; then 215 echo "ldapmodify failed ($RC)!" 216 test $KILLSERVERS != no && kill -HUP $KILLPIDS 217 exit $RC 218fi 219 220. $CONFFILTER $BACKEND $MONITORDB < data/test007-config.ldif | \ 221$LDAPMODIFY -v -D cn=config -H $URI4 -y $CONFIGPWF \ 222 >> $TESTOUT 2>&1 223RC=$? 224if test $RC != 0 ; then 225 echo "ldapmodify failed ($RC)!" 226 test $KILLSERVERS != no && kill -HUP $KILLPIDS 227 exit $RC 228fi 229 230echo "Modifying entry..." 231$LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \ 232 -f data/test005-changes.ldif >> $TESTOUT 2>&1 233RC=$? 234if test $RC != 0 ; then 235 echo "ldapmodify failed ($RC)!" 236 test $KILLSERVERS != no && kill -HUP $KILLPIDS 237 exit $RC 238fi 239 240echo "Applying invalid changes (should fail)..." 241for CHANGE in data/test005-*fail.ldif; do 242 echo "... $CHANGE" 243 $LDAPMODIFY -D $MANAGERDN -H $URI1 -w $PASSWD \ 244 -f $CHANGE >> $TESTOUT 2>&1 245 RC=$? 246 case $RC in 247 0) 248 echo "ldapmodify should have failed ($RC)!" 249 test $KILLSERVERS != no && kill -HUP $KILLPIDS 250 exit 1 251 ;; 252 16|19) 253 echo "ldapmodify failed ($RC)" 254 ;; 255 *) 256 echo "ldapmodify failed ($RC)!" 257 test $KILLSERVERS != no && kill -HUP $KILLPIDS 258 exit $RC 259 ;; 260 esac 261done 262 263echo "Waiting ${SLEEP1} seconds for consumer to finish replicating..." 264sleep ${SLEEP1} 265 266echo "Reading affected entries back..." 267echo "# Reading affected entries back..." >> $SEARCHOUT 268$LDAPSEARCH -b "$BASEDN" -H $URI1 \ 269 '(|(objectClass=OpenLDAPperson)(ou=people))' \ 270 >> $SEARCHOUT 2>&1 271RC=$? 272if test $RC != 0 ; then 273 echo "ldapsearch failed ($RC)!" 274 test $KILLSERVERS != no && kill -HUP $KILLPIDS 275 exit $RC 276fi 277 278test $KILLSERVERS != no && kill -HUP $KILLPIDS 279 280LDIF=data/test005-out.ldif 281 282echo "Filtering ldapsearch results..." 283$LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT 284echo "Filtering expected entries..." 285$LDIFFILTER -s e < $LDIF > $LDIFFLT 286echo "Comparing filter output..." 287$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 288 289 290if test $? != 0 ; then 291 echo "Comparison failed" 292 exit 1 293fi 294 295echo ">>>>> Test succeeded" 296 297test $KILLSERVERS != no && wait 298 299exit 0 300