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
16if test $# -eq 0 ; then
17	test -z "$SRCDIR" && SRCDIR="."
18else
19	SRCDIR=$1; shift
20fi
21if test $# -eq 1 ; then
22	BACKEND=$1; shift
23fi
24
25echo "running defines.sh $SRCDIR $BACKEND"
26. $SRCDIR/scripts/defines.sh
27
28if test -d "$TESTDIR"; then
29	echo "Cleaning up in $TESTDIR..."
30	/bin/rm -rf $TESTDIR/db.*
31fi
32mkdir -p $TESTDIR
33
34echo "Starting slapd on TCP/IP port $PORT1..."
35. $CONFFILTER $BACKEND < $PASSWDCONF > $CONF1
36$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
37PID=$!
38if test ${WAIT-0} != 0 ; then
39    echo PID $PID
40    read foo
41fi
42KILLPIDS="$PID"
43
44echo "Testing slapd searching..."
45for i in 0 1 2 3 4 5; do
46	$LDAPSEARCH -L -b "$BASEDN" -H $URI1 \
47		'objectclass=*' > /dev/null 2>&1
48	RC=$?
49	if test $RC = 1 ; then
50		echo "Waiting 5 seconds for slapd to start..."
51		sleep 5
52	fi
53done
54
55if test $RC != 0 ; then
56	echo "ldapsearch failed!"
57	test "$KILLSERVERS" != no && kill -HUP $KILLPIDS
58	exit $RC
59fi
60
61cat /dev/null > $TESTOUT
62
63echo "Testing base suffix searching..."
64$LDAPSEARCH -L -S "" -b "$BASEDN" -s base -H $URI1 \
65	'(objectclass=*)' >> $TESTOUT 2>&1
66RC=$?
67if test $RC != 0 ; then
68	echo "ldapsearch failed!"
69	test "$KILLSERVERS" != no && kill -HUP $KILLPIDS
70	exit $RC
71fi
72
73echo " ------------ " >> $TESTOUT
74
75echo "Testing user searching..."
76$LDAPSEARCH -L -S "" -b "uid=root,$BASEDN" -s base -H $URI1 \
77	'(objectclass=*)' >> $TESTOUT 2>&1
78RC=$?
79if test $RC != 0 ; then
80	echo "ldapsearch failed!"
81	test "$KILLSERVERS" != no && kill -HUP $KILLPIDS
82	exit $RC
83fi
84
85echo " ------------ " >> $TESTOUT
86
87echo "Testing exact searching..."
88$LDAPSEARCH -L -S "" -b "$BASEDN" -H $URI1 \
89	'(uid=root)' >> $TESTOUT 2>&1
90RC=$?
91if test $RC != 0 ; then
92	echo "ldapsearch failed!"
93	test "$KILLSERVERS" != no && kill -HUP $KILLPIDS
94	exit $RC
95fi
96
97echo " ------------ " >> $TESTOUT
98
99echo "Testing OR searching..."
100$LDAPSEARCH -L -S "" -b "$BASEDN" -H $URI1 \
101	'(|(objectclass=person)(cn=root))' >> $TESTOUT 2>&1
102RC=$?
103if test $RC != 0 ; then
104	echo "ldapsearch failed!"
105	test "$KILLSERVERS" != no && kill -HUP $KILLPIDS
106	exit $RC
107fi
108
109echo " ------------ " >> $TESTOUT
110
111echo "Testing AND searching..."
112$LDAPSEARCH -L -S "" -b "$BASEDN" -H $URI1 \
113	'(&(objectclass=person)(cn=root))' >> $TESTOUT 2>&1
114RC=$?
115if test $RC != 0 ; then
116	echo "ldapsearch failed!"
117	test "$KILLSERVERS" != no && kill -HUP $KILLPIDS
118	exit $RC
119fi
120
121test "$KILLSERVERS" != no && kill -HUP $KILLPIDS
122
123echo "Assuming everything is fine."
124#echo "Comparing results"
125#$CMP $TESTOUT $SEARCHOUTPROVIDER
126#if test $? != 0 ; then
127#	echo "Comparison failed"
128#	exit 1
129#fi
130
131echo ">>>>> Test succeeded"
132
133exit 0
134