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