]> git.sur5r.net Git - openldap/blob - tests/scripts/test003-search
bd96230e9cdec41e8604d102a1e17ddc5d03726f
[openldap] / tests / scripts / test003-search
1 #!/bin/sh
2
3 if [ $# -eq 0 ]; then
4         SRCDIR="."
5 else
6         SRCDIR=$1; shift
7 fi
8 if [ $# -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 [ $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 -L -S "" -b "$BASEDN" -h localhost -p $PORT \
34                 'cn=Manager' > /dev/null 2>&1
35         RC=$?
36         if [ $RC = 1 ]; then
37                 echo "Waiting 5 seconds for slapd to start..."
38                 sleep 5
39         fi
40 done
41
42 if [ $RC != 0 ]; then
43         echo "ldapsearch failed!"
44         kill -HUP $PID
45         exit $RC
46 fi
47
48 cat /dev/null > $TESTOUT
49
50 echo "Testing exact searching..."
51 $LDAPSEARCH -L -S "" -b "$BASEDN" -h localhost -p $PORT \
52         'sn=jensen' >> $TESTOUT 2>&1
53 if [ $RC != 0 ]; then
54         echo "ldapsearch failed!"
55         kill -HUP $PID
56         exit $RC
57 fi
58
59 echo "Testing OR searching..."
60 $LDAPSEARCH -L -S "" -b "$BASEDN" -h localhost -p $PORT \
61         '(|(objectclass=rfc822mailgroup)(sn=jones))' >> $TESTOUT 2>&1
62 if [ $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 -L -S "" -b "$BASEDN" -h localhost -p $PORT \
70         '(&(objectclass=rfc822mailgroup)(cn=A*))' >> $TESTOUT 2>&1
71 if [ $RC != 0 ]; then
72         echo "ldapsearch failed!"
73         kill -HUP $PID
74         exit $RC
75 fi
76
77 echo "Testing NOT searching..."
78 $LDAPSEARCH -L -S "" -b "$BASEDN" -h localhost -p $PORT \
79         '(!(objectclass=person))' | grep -v "^modifytimestamp:" \
80         >> $TESTOUT 2>&1
81 if [ $RC != 0 ]; then
82         echo "ldapsearch failed!"
83         kill -HUP $PID
84         exit $RC
85 fi
86
87 kill -HUP $PID
88
89 echo "Comparing results"
90 cmp $TESTOUT $SEARCHOUTMASTER
91 if [ $? != 0 ]; then
92         echo "Comparison failed"
93         exit 1
94 fi
95
96 echo ">>>>> Test succeeded"
97
98
99 exit 0