1*e670fd5cSchristos#! /bin/sh
2*e670fd5cSchristos## $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 2016-2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos##
16*e670fd5cSchristos## ACKNOWLEDGEMENTS:
17*e670fd5cSchristos## This module was written in 2016 by Ondřej Kuzník for Symas Corp.
18*e670fd5cSchristos
19*e670fd5cSchristosecho "running defines.sh"
20*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
21*e670fd5cSchristos
22*e670fd5cSchristosif test "$SYNCPROV" = syncprovno; then
23*e670fd5cSchristos	echo "Syncrepl provider overlay not available, test skipped"
24*e670fd5cSchristos	exit 0
25*e670fd5cSchristosfi
26*e670fd5cSchristos
27*e670fd5cSchristos. ${SCRIPTDIR}/common.sh
28*e670fd5cSchristos
29*e670fd5cSchristos$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
30*e670fd5cSchristos	> $TESTOUT 2>&1 <<EOMOD
31*e670fd5cSchristosdn: olcOverlay={0}variant,olcDatabase={1}$BACKEND,cn=config
32*e670fd5cSchristoschangetype: modify
33*e670fd5cSchristosreplace: olcVariantPassReplication
34*e670fd5cSchristosolcVariantPassReplication: FALSE
35*e670fd5cSchristosEOMOD
36*e670fd5cSchristosRC=$?
37*e670fd5cSchristosif test $RC != 0 ; then
38*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
39*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
40*e670fd5cSchristos	exit $RC
41*e670fd5cSchristosfi
42*e670fd5cSchristos
43*e670fd5cSchristosif test "$SYNCPROV" = syncprovmod; then
44*e670fd5cSchristos	$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
45*e670fd5cSchristos	> $TESTOUT 2>&1 <<EOMOD
46*e670fd5cSchristosdn: cn=module{0},cn=config
47*e670fd5cSchristoschangetype: modify
48*e670fd5cSchristosadd: olcModuleLoad
49*e670fd5cSchristosolcModuleLoad: $LDAP_BUILD/servers/slapd/overlays/syncprov.la
50*e670fd5cSchristosEOMOD
51*e670fd5cSchristos
52*e670fd5cSchristos	RC=$?
53*e670fd5cSchristos	if test $RC != 0 ; then
54*e670fd5cSchristos		echo "ldapmodify failed ($RC)!"
55*e670fd5cSchristos		test $KILLSERVERS != no && kill -HUP $KILLPIDS
56*e670fd5cSchristos		exit $RC
57*e670fd5cSchristos	fi
58*e670fd5cSchristosfi
59*e670fd5cSchristos
60*e670fd5cSchristosecho "Configuring syncprov on the provider..."
61*e670fd5cSchristos$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
62*e670fd5cSchristos	> $TESTOUT 2>&1 <<EOMOD
63*e670fd5cSchristosdn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
64*e670fd5cSchristoschangetype: add
65*e670fd5cSchristosobjectclass: olcSyncProvConfig
66*e670fd5cSchristosEOMOD
67*e670fd5cSchristosRC=$?
68*e670fd5cSchristosif test $RC != 0 ; then
69*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
70*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
71*e670fd5cSchristos	exit $RC
72*e670fd5cSchristosfi
73*e670fd5cSchristos
74*e670fd5cSchristosmkdir $DBDIR4
75*e670fd5cSchristos
76*e670fd5cSchristosecho "Starting consumer slapd on TCP/IP port $PORT4..."
77*e670fd5cSchristos. $CONFFILTER $BACKEND $MONITORDB < $P1SRCONSUMERCONF > $CONF4
78*e670fd5cSchristos$SLAPD -f $CONF4 -h $URI4 -d $LVL > $LOG4 2>&1 &
79*e670fd5cSchristosCONSUMERPID=$!
80*e670fd5cSchristosif test $WAIT != 0 ; then
81*e670fd5cSchristos	echo CONSUMERPID $CONSUMERPID
82*e670fd5cSchristos	read foo
83*e670fd5cSchristosfi
84*e670fd5cSchristosKILLPIDS="$KILLPIDS $CONSUMERPID"
85*e670fd5cSchristos
86*e670fd5cSchristossleep $SLEEP0
87*e670fd5cSchristos
88*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
89*e670fd5cSchristos	$LDAPSEARCH -s base -b "$BASEDN" -H $URI4 \
90*e670fd5cSchristos		'objectclass=*' > /dev/null 2>&1
91*e670fd5cSchristos	RC=$?
92*e670fd5cSchristos	if test $RC = 0 ; then
93*e670fd5cSchristos		break
94*e670fd5cSchristos	fi
95*e670fd5cSchristos	echo "Waiting ${SLEEP1} seconds for consumer to start replication..."
96*e670fd5cSchristos	sleep ${SLEEP1}
97*e670fd5cSchristosdone
98*e670fd5cSchristos
99*e670fd5cSchristosecho "Waiting ${SLEEP1} seconds for consumer to finish replicating..."
100*e670fd5cSchristossleep ${SLEEP1}
101*e670fd5cSchristos
102*e670fd5cSchristosecho "Testing searches against regular entries..."
103*e670fd5cSchristosecho "# Testing searches against regular entries..." >> $SEARCHOUT
104*e670fd5cSchristos$LDAPSEARCH -b "$BASEDN" -H $URI4 \
105*e670fd5cSchristos	"(|(name=Elliot)(description=*hiker*))" \
106*e670fd5cSchristos	>> $SEARCHOUT 2>&1
107*e670fd5cSchristosRC=$?
108*e670fd5cSchristosif test $RC != 0 ; then
109*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
110*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
111*e670fd5cSchristos	exit $RC
112*e670fd5cSchristosfi
113*e670fd5cSchristos
114*e670fd5cSchristosecho "Testing searches listing replicated variants..."
115*e670fd5cSchristosecho >> $SEARCHOUT
116*e670fd5cSchristosecho "# Testing searches listing replicated variants..." >> $SEARCHOUT
117*e670fd5cSchristos$LDAPSEARCH -b "$BASEDN" -s one -H $URI4 \
118*e670fd5cSchristos	>> $SEARCHOUT 2>&1
119*e670fd5cSchristosRC=$?
120*e670fd5cSchristosif test $RC != 0 ; then
121*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
122*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
123*e670fd5cSchristos	exit $RC
124*e670fd5cSchristosfi
125*e670fd5cSchristos
126*e670fd5cSchristos# regex variants do not replicate correctly and this is documented
127*e670fd5cSchristosecho >> $SEARCHOUT
128*e670fd5cSchristos$LDAPSEARCH -b "$BASEDN" -s base -H $URI1 \
129*e670fd5cSchristos	>> $SEARCHOUT 2>&1
130*e670fd5cSchristosRC=$?
131*e670fd5cSchristosif test $RC != 0 ; then
132*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
133*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
134*e670fd5cSchristos	exit $RC
135*e670fd5cSchristosfi
136*e670fd5cSchristos
137*e670fd5cSchristos# regex variants do not replicate correctly and this is documented
138*e670fd5cSchristosecho >> $SEARCHOUT
139*e670fd5cSchristos$LDAPSEARCH -s base -H $URI1 \
140*e670fd5cSchristos	-b "cn=Bjorn Jensen,ou=Information Technology Division,ou=People,$BASEDN" \
141*e670fd5cSchristos	'(ou=Information Technology Division)' \
142*e670fd5cSchristos	>> $SEARCHOUT 2>&1
143*e670fd5cSchristosRC=$?
144*e670fd5cSchristosif test $RC != 0 ; then
145*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
146*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
147*e670fd5cSchristos	exit $RC
148*e670fd5cSchristosfi
149*e670fd5cSchristos
150*e670fd5cSchristos# regex variants do not replicate correctly and this is documented
151*e670fd5cSchristosecho >> $SEARCHOUT
152*e670fd5cSchristos$LDAPSEARCH -b "cn=ITD Staff,ou=Groups,$BASEDN" -s base -H $URI1 \
153*e670fd5cSchristos	>> $SEARCHOUT 2>&1
154*e670fd5cSchristosRC=$?
155*e670fd5cSchristosif test $RC != 0 ; then
156*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
157*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
158*e670fd5cSchristos	exit $RC
159*e670fd5cSchristosfi
160*e670fd5cSchristos
161*e670fd5cSchristosecho "Testing searches filtering on replicated variants..."
162*e670fd5cSchristosecho >> $SEARCHOUT
163*e670fd5cSchristosecho "# Testing searches filtering on replicated variants..." >> $SEARCHOUT
164*e670fd5cSchristos$LDAPSEARCH -b "$BASEDN" -H $URI4 \
165*e670fd5cSchristos	"(st=Alumni Association)" st \
166*e670fd5cSchristos	>> $SEARCHOUT 2>&1
167*e670fd5cSchristosRC=$?
168*e670fd5cSchristosif test $RC != 0 ; then
169*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
170*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
171*e670fd5cSchristos	exit $RC
172*e670fd5cSchristosfi
173*e670fd5cSchristos
174*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
175*e670fd5cSchristos
176*e670fd5cSchristosLDIF=data/test003-out.ldif
177*e670fd5cSchristos
178*e670fd5cSchristosecho "Filtering ldapsearch results..."
179*e670fd5cSchristos$LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
180*e670fd5cSchristosecho "Filtering expected entries..."
181*e670fd5cSchristos$LDIFFILTER -s e < $LDIF > $LDIFFLT
182*e670fd5cSchristosecho "Comparing filter output..."
183*e670fd5cSchristos$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
184*e670fd5cSchristos
185*e670fd5cSchristosif test $? != 0 ; then
186*e670fd5cSchristos	echo "Comparison failed"
187*e670fd5cSchristos	exit 1
188*e670fd5cSchristosfi
189*e670fd5cSchristos
190*e670fd5cSchristosecho ">>>>> Test succeeded"
191*e670fd5cSchristos
192*e670fd5cSchristostest $KILLSERVERS != no && wait
193*e670fd5cSchristos
194*e670fd5cSchristosexit 0
195