xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test033-glue-syncrepl (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test033-glue-syncrepl,v 1.17.2.6 2009/03/05 22:19:39 quanah Exp */
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2009 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
16case $BACKEND in bdb | hdb | ldif) : ;; *)
17	echo "Test does not support $BACKEND backend, test skipped"
18	exit 0
19esac
20
21echo "running defines.sh"
22. $SRCDIR/scripts/defines.sh
23
24if test $SYNCPROV = syncprovno; then
25	echo "Syncrepl provider overlay not available, test skipped"
26	exit 0
27fi
28
29mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR1C $DBDIR2A $DBDIR2B
30
31echo "Running slapadd to build glued slapd databases..."
32. $CONFFILTER $BACKEND $MONITORDB < $GLUECONF > $CONF1
33$SLAPADD -d $LVL -f $CONF1 -l $LDIFORDERED > $SLAPADDLOG1 2>&1
34RC=$?
35if test $RC != 0 ; then
36	echo "slapadd failed ($RC)!"
37	exit $RC
38fi
39
40rm -rf $DBDIR1A/* $DBDIR1B/*
41cp -pr $DBDIR1C $DBDIR2C
42
43echo "Starting slapd 1 on TCP/IP port $PORT1..."
44. $CONFFILTER $BACKEND $MONITORDB < $GLUESYNCCONF1 > $CONF1
45$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
46PID=$!
47if test $WAIT != 0 ; then
48    echo PID $PID
49    read foo
50fi
51KILLPIDS="$PID"
52
53sleep 1
54
55echo "Using ldapsearch to check that slapd 1 is running..."
56for i in 0 1 2 3 4 5; do
57	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
58		'(objectclass=*)' > /dev/null 2>&1
59	RC=$?
60	if test $RC = 0 ; then
61		break
62	fi
63	echo "Waiting 5 seconds for slapd to start..."
64	sleep 5
65done
66
67echo "Starting slapd 2 on TCP/IP port $PORT2..."
68. $CONFFILTER $BACKEND $MONITORDB < $GLUESYNCCONF2 > $CONF2
69$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
70PID=$!
71if test $WAIT != 0 ; then
72    echo PID $PID
73    read foo
74fi
75KILLPIDS="$KILLPIDS $PID"
76
77sleep 1
78
79echo "Using ldapsearch to check that slapd 2 is running..."
80for i in 0 1 2 3 4 5; do
81	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
82		'(objectclass=*)' > /dev/null 2>&1
83	RC=$?
84	if test $RC = 0 ; then
85		break
86	fi
87	echo "Waiting 5 seconds for slapd to start..."
88	sleep 5
89done
90
91SUBTREE1="ou=Information Technology Division,ou=People,dc=example,dc=com"
92SUBTREE2="ou=Groups,dc=example,dc=com"
93
94echo "Using ldapadd to populate subtree=\"${SUBTREE1}\" on port $PORT1..."
95$LDAPADD -D "cn=Manager 1,$BASEDN" -w $PASSWD -h $LOCALHOST -p $PORT1 \
96	-f $LDIFORDERED -c \
97	> /dev/null 2>&1
98RC=$?
99case $RC in
1000)
101	echo "ldapadd should have failed ($RC)!"
102	test $KILLSERVERS != no && kill -HUP $KILLPIDS
103	exit -1
104	;;
10510|68)
106	# Fine if we get alreadyExists or referrals
107	;;
108*)
109	echo "ldapadd failed ($RC)!"
110	test $KILLSERVERS != no && kill -HUP $KILLPIDS
111	exit $RC
112	;;
113esac
114
115echo "Using ldapadd to populate subtree=\"${SUBTREE2}\" on port $PORT2..."
116$LDAPADD -D "cn=Manager 2,$BASEDN" -w $PASSWD -h $LOCALHOST -p $PORT2 \
117	-f $LDIFORDERED -c \
118	> /dev/null 2>&1
119RC=$?
120case $RC in
1210)
122	echo "ldapadd should have failed ($RC)!"
123	test $KILLSERVERS != no && kill -HUP $KILLPIDS
124	exit -1
125	;;
12610|68)
127	# Fine if we get alreadyExists or referrals
128	;;
129*)
130	echo "ldapadd failed ($RC)!"
131	test $KILLSERVERS != no && kill -HUP $KILLPIDS
132	exit $RC
133	;;
134esac
135
136echo "Waiting $SLEEP1 seconds for shadow subtrees to sync..."
137sleep $SLEEP1
138
139echo "Filtering original ldif used to create database..."
140. $LDIFFILTER < $GLUESYNCOUT > $LDIFFLT
141
142for P in $PORT1 $PORT2 ; do
143	echo "Using ldapsearch to read all the entries from port $P..."
144	$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $P \
145		-S "" '(objectclass=*)' > "${SEARCHOUT}.${P}" 2>&1
146	RC=$?
147
148	if test $RC != 0 ; then
149		echo "ldapsearch failed ($RC)!"
150		test $KILLSERVERS != no && kill -HUP $KILLPIDS
151		exit $RC
152	fi
153
154	echo "Filtering ldapsearch results..."
155	. $LDIFFILTER < "${SEARCHOUT}.${P}" > $SEARCHFLT
156	echo "Comparing filter output..."
157	$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
158
159	if test $? != 0 ; then
160		echo "comparison failed - database was not created correctly"
161		test $KILLSERVERS != no && kill -HUP $KILLPIDS
162		exit 1
163	fi
164done
165
166echo "Testing ldapdelete propagation..."
167$LDAPDELETE -D "cn=Manager 1,$BASEDN" -w $PASSWD -H $URI1 "$BABSDN" \
168	> $TESTOUT 2>&1
169RC=$?
170if test $RC != 0 ; then
171	echo "ldapdelete failed ($RC)!"
172	test $KILLSERVERS != no && kill -HUP $KILLPIDS
173	exit $RC
174fi
175
176# This usually propagates immediately
177sleep 1
178
179$LDAPSEARCH -H $URI2 -b "$BABSDN" > $TESTOUT 2>&1
180RC=$?
181if test $RC = 0 ; then
182	echo "ldapsearch should have failed ($RC)!"
183	test $KILLSERVERS != no && kill -HUP $KILLPIDS
184	exit -1
185fi
186
187test $KILLSERVERS != no && kill -HUP $KILLPIDS
188
189echo ">>>>> Test succeeded"
190
191test $KILLSERVERS != no && wait
192
193exit 0
194