xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapd-modules/variant/tests/scripts/test001-config (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
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
22. ${SCRIPTDIR}/common.sh
23
24echo "Applying invalid changes to config (should fail)..."
25for CHANGE in data/test001-*.ldif; do
26	echo "... $CHANGE"
27	. $CONFFILTER $BACKEND $MONITORDB < $CHANGE | \
28	$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
29		>> $TESTOUT 2>&1
30	RC=$?
31	case $RC in
32	0)
33		echo "ldapmodify should have failed ($RC)!"
34		test $KILLSERVERS != no && kill -HUP $KILLPIDS
35		exit 1
36		;;
37	80)
38		echo "ldapmodify failed ($RC)"
39		;;
40	*)
41		echo "ldapmodify failed ($RC)!"
42		test $KILLSERVERS != no && kill -HUP $KILLPIDS
43		exit $RC
44		;;
45	esac
46done
47
48# We run this search after the changes above and before restart so we can also
49# check the reconfiguration attempts actually had no side effects
50echo "Saving search output before server restart..."
51echo "# search output from dynamically configured server..." >> $SERVER3OUT
52$LDAPSEARCH -b "$BASEDN" -H $URI1 \
53	>> $SERVER3OUT 2>&1
54RC=$?
55if test $RC != 0 ; then
56	echo "ldapsearch failed ($RC)!"
57	test $KILLSERVERS != no && kill -HUP $KILLPIDS
58	exit $RC
59fi
60
61echo "Stopping slapd on TCP/IP port $PORT1..."
62kill -HUP $KILLPIDS
63KILLPIDS=""
64sleep $SLEEP0
65echo "Starting slapd on TCP/IP port $PORT1..."
66$SLAPD -F $TESTDIR/confdir -h $URI1 -d $LVL >> $LOG1 2>&1 &
67PID=$!
68if test $WAIT != 0 ; then
69	echo PID $PID
70	read foo
71fi
72KILLPIDS="$PID"
73
74sleep $SLEEP0
75
76for i in 0 1 2 3 4 5; do
77	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
78		'objectclass=*' > /dev/null 2>&1
79	RC=$?
80	if test $RC = 0 ; then
81		break
82	fi
83	echo "Waiting ${SLEEP1} seconds for slapd to start..."
84	sleep ${SLEEP1}
85done
86
87echo "Testing slapd.conf support..."
88mkdir $TESTDIR/conftest $DBDIR2
89. $CONFFILTER $BACKEND $MONITORDB < $CONFTWO \
90	| sed -e '/^argsfile.*/a\
91moduleload ../variant.la' \
92		  -e '/database.*monitor/i\
93include data/variant.conf' \
94	> $CONF2
95echo "database config" >>$CONF2
96echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF2
97
98$SLAPADD -f $CONF2 -l $LDIFORDERED
99$SLAPD -Tt -f $CONF2 -F $TESTDIR/conftest -d $LVL >> $LOG2 2>&1
100RC=$?
101if test $RC != 0 ; then
102	echo "slaptest failed ($RC)!"
103	test $KILLSERVERS != no && kill -HUP $KILLPIDS
104	exit $RC
105fi
106
107echo "Starting slapd on TCP/IP port $PORT2..."
108$SLAPD -F $TESTDIR/conftest -h $URI2 -d $LVL >> $LOG2 2>&1 &
109PID=$!
110if test $WAIT != 0 ; then
111	echo PID $PID
112	read foo
113fi
114KILLPIDS="$KILLPIDS $PID"
115
116sleep $SLEEP0
117
118for i in 0 1 2 3 4 5; do
119	$LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
120		'objectclass=*' > /dev/null 2>&1
121	RC=$?
122	if test $RC = 0 ; then
123		break
124	fi
125	echo "Waiting ${SLEEP1} seconds for slapd to start..."
126	sleep ${SLEEP1}
127done
128
129echo "Gathering overlay configuration from both servers..."
130echo "# overlay configuration from dynamically configured server..." >> $SERVER1OUT
131$LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF \
132	-b "olcOverlay={0}variant,olcDatabase={1}$BACKEND,cn=config" \
133	>> $SERVER1OUT 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 "# overlay configuration from server configured from slapd.conf..." >> $SERVER2OUT
142$LDAPSEARCH -D cn=config -H $URI2 -y $CONFIGPWF \
143	-b "olcOverlay={0}variant,olcDatabase={1}$BACKEND,cn=config" \
144	>> $SERVER2OUT 2>&1
145RC=$?
146if test $RC != 0 ; then
147	echo "ldapsearch failed ($RC)!"
148	test $KILLSERVERS != no && kill -HUP $KILLPIDS
149	exit $RC
150fi
151
152# We've already filtered out the ordering markers, now sort the entries
153echo "Filtering ldapsearch results..."
154$LDIFFILTER -s a < $SERVER2OUT > $SERVER2FLT
155echo "Filtering expected entries..."
156$LDIFFILTER -s a < $SERVER1OUT > $SERVER1FLT
157echo "Comparing filter output..."
158$CMP $SERVER2FLT $SERVER1FLT > $CMPOUT
159
160if test $? != 0 ; then
161	echo "Comparison failed"
162	test $KILLSERVERS != no && kill -HUP $KILLPIDS
163	exit 1
164fi
165
166rm $SERVER1OUT $SERVER2OUT
167
168echo "Comparing search output on both servers..."
169echo "# search output from dynamically configured server..." >> $SERVER1OUT
170$LDAPSEARCH -b "$BASEDN" -H $URI1 \
171	>> $SERVER1OUT 2>&1
172RC=$?
173if test $RC != 0 ; then
174	echo "ldapsearch failed ($RC)!"
175	test $KILLSERVERS != no && kill -HUP $KILLPIDS
176	exit $RC
177fi
178
179echo "# search output from server configured from slapd.conf..." >> $SERVER2OUT
180$LDAPSEARCH -b "$BASEDN" -H $URI2 \
181	>> $SERVER2OUT 2>&1
182RC=$?
183if test $RC != 0 ; then
184	echo "ldapsearch failed ($RC)!"
185	test $KILLSERVERS != no && kill -HUP $KILLPIDS
186	exit $RC
187fi
188
189test $KILLSERVERS != no && kill -HUP $KILLPIDS
190
191echo "Filtering ldapsearch results..."
192$LDIFFILTER -s e < $SERVER1OUT > $SERVER1FLT
193$LDIFFILTER -s e < $SERVER2OUT > $SERVER2FLT
194echo "Filtering expected entries..."
195$LDIFFILTER -s e < $SERVER3OUT > $SERVER3FLT
196echo "Comparing filter output..."
197$CMP $SERVER3FLT $SERVER1FLT > $CMPOUT && \
198$CMP $SERVER3FLT $SERVER2FLT > $CMPOUT
199
200if test $? != 0 ; then
201	echo "Comparison failed"
202	exit 1
203fi
204
205echo ">>>>> Test succeeded"
206
207test $KILLSERVERS != no && wait
208
209exit 0
210