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