]> git.sur5r.net Git - openldap/blob - tests/scripts/test003-search
bced8e1fbb5b7ed2204d4ca8a2c05a58a7cc458a
[openldap] / tests / scripts / test003-search
1 #! /bin/sh
2 # $OpenLDAP$
3
4 if test $# -eq 0 ; then
5         SRCDIR="."
6 else
7         SRCDIR=$1; shift
8 fi
9 if test $# -eq 1 ; then
10         BACKEND=$1; shift
11 fi
12
13 echo "running defines.sh $SRCDIR $BACKEND"
14 . $SRCDIR/scripts/defines.sh
15
16 echo "Cleaning up in $DBDIR..."
17
18 rm -f $DBDIR/[!C]*
19
20 echo "Running slapadd to build slapd database..."
21 $LDIF2LDBM -f $CONF -l $LDIF
22 RC=$?
23 if test $RC != 0 ; then
24         echo "slapadd failed ($RC)!"
25         exit $RC
26 fi
27
28 echo "Starting slapd on TCP/IP port $PORT..."
29 $SLAPD -f $CONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
30 PID=$!
31
32 echo "Testing slapd searching..."
33 for i in 0 1 2 3 4 5; do
34         $LDAPSEARCH -s base -b "$MONITOR" -h localhost -p $PORT \
35                 'objectclass=*' > /dev/null 2>&1
36         RC=$?
37         if test $RC = 1 ; then
38                 echo "Waiting 5 seconds for slapd to start..."
39                 sleep 5
40         fi
41 done
42
43 if test $RC != 0 ; then
44         echo "ldapsearch failed ($RC)!"
45         kill -HUP $PID
46         exit $RC
47 fi
48
49 cat /dev/null > $SEARCHOUT
50
51 echo "Testing exact searching..."
52 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
53         'sn=jensen' >> $SEARCHOUT 2>&1
54 if test $RC != 0 ; then
55         echo "ldapsearch failed ($RC)!"
56         kill -HUP $PID
57         exit $RC
58 fi
59
60 echo "Testing OR searching..."
61 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
62         '(|(objectclass=groupofnames)(sn=jones))' >> $SEARCHOUT 2>&1
63 if test $RC != 0 ; then
64         echo "ldapsearch failed ($RC)!"
65         kill -HUP $PID
66         exit $RC
67 fi
68
69 echo "Testing AND matching and ends-with searching..."
70 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
71         '(&(objectclass=groupofnames)(cn=A*))' >> $SEARCHOUT 2>&1
72 if test $RC != 0 ; then
73         echo "ldapsearch failed ($RC)!"
74         kill -HUP $PID
75         exit $RC
76 fi
77
78 echo "Testing NOT searching..."
79 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
80         '(!(objectclass=person))' >> $SEARCHOUT 2>&1
81 if test $RC != 0 ; then
82         echo "ldapsearch failed ($RC)!"
83         kill -HUP $PID
84         exit $RC
85 fi
86
87 kill -HUP $PID
88
89 LDIF=$SEARCHOUTMASTER
90
91 echo "Filtering ldapsearch results..."
92 . $SRCDIR/scripts/acfilter.sh < $SEARCHOUT > $SEARCHFLT
93 echo "Filtering original ldif used to create database..."
94 . $SRCDIR/scripts/acfilter.sh < $LDIF > $LDIFFLT
95 echo "Comparing filter output..."
96 $CMP $SEARCHFLT $LDIFFLT
97
98 if test $? != 0 ; then
99         echo "Comparison failed"
100         exit 1
101 fi
102
103 echo ">>>>> Test succeeded"
104
105
106 exit 0