1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-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
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19mkdir -p $TESTDIR $DBDIR1 $DBDIR2
20
21$SLAPPASSWD -g -n >$CONFIGPWF
22echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
23
24if test $AC_lloadd = lloaddyes ; then
25    echo "Load balancer module not available, skipping..."
26    exit 0
27fi
28
29echo "Starting the first slapd on TCP/IP port $PORT2..."
30. $CONFFILTER $BACKEND < $CONF > $CONF2
31$SLAPADD -f $CONF2 -l $LDIFORDERED
32RC=$?
33if test $RC != 0 ; then
34    echo "slapadd failed ($RC)!"
35    exit $RC
36fi
37
38echo "Running slapindex to index slapd database..."
39$SLAPINDEX -f $CONF2
40RC=$?
41if test $RC != 0 ; then
42    echo "warning: slapindex failed ($RC)"
43    echo "  assuming no indexing support"
44fi
45
46$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
47PID=$!
48if test $WAIT != 0 ; then
49    echo PID $PID
50    read foo
51fi
52PID2="$PID"
53KILLPIDS="$PID"
54
55echo "Testing slapd searching..."
56for i in 0 1 2 3 4 5; do
57    $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
58        '(objectclass=*)' > /dev/null 2>&1
59    RC=$?
60    if test $RC = 0 ; then
61        break
62    fi
63    echo "Waiting $SLEEP1 seconds for slapd to start..."
64    sleep $SLEEP1
65done
66if test $RC != 0 ; then
67    echo "ldapsearch failed ($RC)!"
68    test $KILLSERVERS != no && kill -HUP $KILLPIDS
69    exit $RC
70fi
71
72echo "Running slapadd to build slapd database..."
73. $CONFFILTER $BACKEND < $CONFTWO > $CONF3
74$SLAPADD -f $CONF3 -l $LDIFORDERED
75RC=$?
76if test $RC != 0 ; then
77    echo "slapadd failed ($RC)!"
78    exit $RC
79fi
80
81echo "Running slapindex to index slapd database..."
82$SLAPINDEX -f $CONF3
83RC=$?
84if test $RC != 0 ; then
85    echo "warning: slapindex failed ($RC)"
86    echo "  assuming no indexing support"
87fi
88
89echo "Starting second slapd on TCP/IP port $PORT3..."
90$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
91PID=$!
92if test $WAIT != 0 ; then
93    echo PID $PID
94    read foo
95fi
96PID3="$PID"
97KILLPIDS="$KILLPIDS $PID"
98
99sleep $SLEEP0
100
101echo "Testing slapd searching..."
102for i in 0 1 2 3 4 5; do
103    $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
104        '(objectclass=*)' > /dev/null 2>&1
105    RC=$?
106    if test $RC = 0 ; then
107        break
108    fi
109    echo "Waiting $SLEEP1 seconds for slapd to start..."
110    sleep $SLEEP1
111done
112if test $RC != 0 ; then
113    echo "ldapsearch failed ($RC)!"
114    test $KILLSERVERS != no && kill -HUP $KILLPIDS
115    exit $RC
116fi
117
118echo "Starting lloadd on TCP/IP port $PORT1..."
119. $CONFFILTER $BACKEND < $LLOADDUNREACHABLECONF > $CONF1.lloadd
120. $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd
121$SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 &
122PID=$!
123if test $WAIT != 0 ; then
124    echo PID $PID
125    read foo
126fi
127KILLPIDS="$KILLPIDS $PID"
128
129echo "Testing lloadd searching..."
130for i in 0 1 2 3 4 5; do
131    $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
132        '(objectclass=*)' > /dev/null 2>&1
133    RC=$?
134    if test $RC = 0 ; then
135        break
136    fi
137    echo "Waiting $SLEEP1 seconds for lloadd to start..."
138    sleep $SLEEP1
139done
140
141if test $RC != 0 ; then
142    echo "ldapsearch failed ($RC)!"
143    test $KILLSERVERS != no && kill -HUP $KILLPIDS
144    exit $RC
145fi
146
147
148echo "Testing cn=config searching..."
149$LDAPSEARCH -H $URI6 -D cn=config -y $CONFIGPWF \
150        -s sub -b "olcBackend={0}lload,cn=config" '(objectclass=*)'  > /dev/null 2>&1
151RC=$?
152if test $RC != 0 ; then
153    echo "ldapsearch failed ($RC)!"
154    test $KILLSERVERS != no && kill -HUP $KILLPIDS
155    exit $RC
156fi
157
158echo "Deleting backends"
159
160for i in 1 2 3 4 ; do
161    echo "cn={0}server "$i",olcBackend={0}lload,cn=config"
162    $LDAPDELETE -H $URI6 -D cn=config -y $CONFIGPWF \
163    "cn={0}server "$i",olcBackend={0}lload,cn=config" > /dev/null 2>&1
164    RC=$?
165    if test $RC != 0 ; then
166           echo "deleting server failed ($RC)!"
167           test $KILLSERVERS != no && kill -HUP $KILLPIDS
168           exit $RC
169    fi
170done
171
172echo "Testing cn=config searching..."
173$LDAPSEARCH -H $URI6 -D cn=config -y $CONFIGPWF \
174        -s sub -b "olcBackend={0}lload,cn=config" '(objectclass=*)' > /dev/null 2>&1
175
176
177echo "# Testing exact searching..."
178
179$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
180    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
181RC=$?
182if test $RC != 52 ; then
183    echo "ldapsearch failed ($RC)!"
184    test $KILLSERVERS != no && kill -HUP $KILLPIDS
185    exit $RC
186fi
187
188echo "Testing adding Server "
189$LDAPADD -D cn=config -H $URI6 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
190dn: cn=server 7,olcBackend={0}lload,cn=config
191objectClass: olcBkLloadBackendConfig
192cn: server 7
193olcBkLloadBackendUri: $URI3
194olcBkLloadBindconns: 2
195olcBkLloadMaxPendingConns: 3
196olcBkLloadMaxPendingOps: 5
197olcBkLloadNumconns: 3
198olcBkLloadRetry: 5000
199EOF
200RC=$?
201if test $RC != 0 ; then
202    echo "ldapadd failed for cn=server 7 ($RC)!"
203    test $KILLSERVERS != no && kill -HUP $KILLPIDS
204    exit $RC
205fi
206
207echo "Verifying balancer operation..."
208for i in 0 1 2 3 4 5; do
209    $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
210    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
211    RC=$?
212    if test $RC = 0 ; then
213        break
214    fi
215    echo "Waiting $SLEEP1 seconds for backend to start..."
216    sleep $SLEEP1
217done
218
219echo "Testing bindconf modify"
220$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
221dn: olcBackend={0}lload,cn=config
222changetype: modify
223replace: olcBkLloadBindconf
224olcBkLloadBindconf: bindmethod=simple timeout=0 network-timeout=0 binddn="cn=wrongmanager,dc=example,dc=com" credentials="secret"
225EOF
226
227RC=$?
228if test $RC != 0 ; then
229    echo "modify failed for bindconf ($RC)!"
230    test $KILLSERVERS != no && kill -HUP $KILLPIDS
231    exit $RC
232fi
233
234echo "# Sending a search request..."
235
236$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
237    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
238RC=$?
239if test $RC != 52 ; then
240    echo "ldapsearch failed ($RC)!"
241    test $KILLSERVERS != no && kill -HUP $KILLPIDS
242    exit $RC
243fi
244
245echo "Restoring bindconf value"
246$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
247dn: olcBackend={0}lload,cn=config
248changetype: modify
249replace: olcBkLloadBindconf
250olcBkLloadBindconf: bindmethod=simple timeout=0 network-timeout=0 binddn="cn=Manager,dc=example,dc=com" credentials="secret"
251EOF
252
253RC=$?
254if test $RC != 0 ; then
255    echo "modify failed for bindconf ($RC)!"
256    test $KILLSERVERS != no && kill -HUP $KILLPIDS
257    exit $RC
258fi
259
260
261echo "Verifying balancer operation..."
262for i in 0 1 2 3 4 5; do
263    $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
264    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
265    RC=$?
266    if test $RC = 0 ; then
267        break
268    fi
269    echo "Waiting $SLEEP1 seconds for backend to start..."
270    sleep $SLEEP1
271done
272
273echo "Testing global attributes"
274echo "Testing olcBkLloadMaxPDUPerCycle modify"
275$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
276dn: olcBackend={0}lload,cn=config
277changetype: modify
278replace: olcBkLloadMaxPDUPerCycle
279olcBkLloadMaxPDUPerCycle: 2000
280EOF
281
282RC=$?
283if test $RC != 0 ; then
284    echo "modify failed for olcBkLloadMaxPDUPerCycle($RC)!"
285    test $KILLSERVERS != no && kill -HUP $KILLPIDS
286    exit $RC
287fi
288
289echo "Sending a search request..."
290$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
291    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
292RC=$?
293if test $RC != 0 ; then
294    echo "ldapsearch failed ($RC)!"
295    test $KILLSERVERS != no && kill -HUP $KILLPIDS
296    exit $RC
297fi
298
299echo "Testing olcBkLloadSockbufMaxClient modify"
300$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
301dn: olcBackend={0}lload,cn=config
302changetype: modify
303replace: olcBkLloadSockbufMaxClient
304olcBkLloadSockbufMaxClient: 20000
305EOF
306
307RC=$?
308if test $RC != 0 ; then
309    echo "modify failed for olcBkLloadSockbufMaxClient($RC)!"
310    test $KILLSERVERS != no && kill -HUP $KILLPIDS
311    exit $RC
312fi
313
314echo "Sending a search request..."
315$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
316    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
317RC=$?
318if test $RC != 0 ; then
319    echo "ldapsearch failed ($RC)!"
320    test $KILLSERVERS != no && kill -HUP $KILLPIDS
321    exit $RC
322fi
323
324echo "Testing olcBkLloadSockbufMaxUpstream modify"
325$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
326dn: olcBackend={0}lload,cn=config
327changetype: modify
328replace: olcBkLloadSockbufMaxUpstream
329olcBkLloadSockbufMaxUpstream: 200000
330EOF
331
332RC=$?
333if test $RC != 0 ; then
334    echo "modify failed for olcBkLloadSockbufMaxUpstream($RC)!"
335    test $KILLSERVERS != no && kill -HUP $KILLPIDS
336    exit $RC
337fi
338
339echo "Sending a search request..."
340$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
341    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
342RC=$?
343if test $RC != 0 ; then
344    echo "ldapsearch failed ($RC)!"
345    test $KILLSERVERS != no && kill -HUP $KILLPIDS
346    exit $RC
347fi
348
349echo "Testing olcBkLloadIOTimeout modify"
350$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
351dn: olcBackend={0}lload,cn=config
352changetype: modify
353replace: olcBkLloadIOTimeout
354olcBkLloadIOTimeout: 20000
355EOF
356
357RC=$?
358if test $RC != 0 ; then
359    echo "modify failed for olcBkLloadWriteTimeout($RC)!"
360    test $KILLSERVERS != no && kill -HUP $KILLPIDS
361    exit $RC
362fi
363
364echo "Sending a search request..."
365$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
366    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
367RC=$?
368if test $RC != 0 ; then
369    echo "ldapsearch failed ($RC)!"
370    test $KILLSERVERS != no && kill -HUP $KILLPIDS
371    exit $RC
372fi
373
374echo "Testing backend attributes"
375echo "Testing olcBkLloadBindconns modify"
376$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
377dn: cn={0}server 7,olcBackend={0}lload,cn=config
378changetype: modify
379replace: olcBkLloadBindconns
380olcBkLloadBindconns: 20
381EOF
382
383RC=$?
384if test $RC != 0 ; then
385    echo "modify failed for olcBkLloadBindconns($RC)!"
386    test $KILLSERVERS != no && kill -HUP $KILLPIDS
387    exit $RC
388fi
389
390echo "Testing exact searching..."
391$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
392    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
393RC=$?
394if test $RC != 0 ; then
395    echo "ldapsearch failed ($RC)!"
396    test $KILLSERVERS != no && kill -HUP $KILLPIDS
397    exit $RC
398fi
399
400
401echo "Testing olcBkLloadMaxPendingConns modify"
402$LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
403dn: cn={0}server 7,olcBackend={0}lload,cn=config
404changetype: modify
405replace: olcBkLloadMaxPendingConns
406olcBkLloadMaxPendingConns: 30
407EOF
408
409RC=$?
410if test $RC != 0 ; then
411    echo "modify failed for olcBkLloadMaxPendingConns($RC)!"
412    test $KILLSERVERS != no && kill -HUP $KILLPIDS
413    exit $RC
414fi
415
416echo "Testing exact searching..."
417$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
418    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
419RC=$?
420if test $RC != 0 ; then
421    echo "ldapsearch failed ($RC)!"
422    test $KILLSERVERS != no && kill -HUP $KILLPIDS
423    exit $RC
424fi
425
426test $KILLSERVERS != no && kill -HUP $KILLPIDS
427
428
429echo ">>>>> Test succeeded"
430
431test $KILLSERVERS != no && wait
432
433exit 0
434