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