]> git.sur5r.net Git - openldap/blob - tests/scripts/test003-search
Sync with HEAD
[openldap] / tests / scripts / test003-search
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2005 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
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $MCONF > $ADDCONF
23 $SLAPADD -f $ADDCONF -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Running slapindex to index slapd database..."
31 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
32 $SLAPINDEX -f $CONF1
33 RC=$?
34 if test $RC != 0 ; then
35         echo "warning: slapindex failed ($RC)"
36         echo "  assuming no indexing support"
37 fi
38
39 echo "Starting slapd on TCP/IP port $PORT1..."
40 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43     echo PID $PID
44     read foo
45 fi
46 KILLPIDS="$PID"
47
48 echo "Testing slapd searching..."
49 for i in 0 1 2 3 4 5; do
50         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
51                 '(objectclass=*)' > /dev/null 2>&1
52         RC=$?
53         if test $RC = 0 ; then
54                 break
55         fi
56         echo "Waiting 5 seconds for slapd to start..."
57         sleep 5
58 done
59
60 if test $RC != 0 ; then
61         echo "ldapsearch failed ($RC)!"
62         test $KILLSERVERS != no && kill -HUP $KILLPIDS
63         exit $RC
64 fi
65
66 cat /dev/null > $SEARCHOUT
67
68 echo "Testing exact searching..."
69 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
70         '(sn=jENSEN)' >> $SEARCHOUT 2>&1
71 RC=$?
72 if test $RC != 0 ; then
73         echo "ldapsearch failed ($RC)!"
74         test $KILLSERVERS != no && kill -HUP $KILLPIDS
75         exit $RC
76 fi
77
78 echo "Testing approximate searching..."
79 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
80         '(sn~=jENSEN)' name >> $SEARCHOUT 2>&1
81 RC=$?
82 if test $RC != 0 ; then
83         echo "ldapsearch failed ($RC)!"
84         test $KILLSERVERS != no && kill -HUP $KILLPIDS
85         exit $RC
86 fi
87
88 echo "Testing OR searching..."
89 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
90         '(|(givenname=Xx*yY*Z)(cn=)(undef=*)(objectclass=groupofnames)(sn=jones)(member=cn=Manager,dc=example,dc=com)(uniqueMember=cn=Manager,dc=example,dc=com))' >> $SEARCHOUT 2>&1
91 RC=$?
92 if test $RC != 0 ; then
93         echo "ldapsearch failed ($RC)!"
94         test $KILLSERVERS != no && kill -HUP $KILLPIDS
95         exit $RC
96 fi
97
98 echo "Testing AND matching and ends-with searching..."
99 $LDAPSEARCH -S "" -b "ou=groups,$BASEDN" -s one -h $LOCALHOST -p $PORT1 \
100         '(&(objectclass=groupofnames)(cn=A*)(member=cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com))' >> $SEARCHOUT 2>&1
101 RC=$?
102 if test $RC != 0 ; then
103         echo "ldapsearch failed ($RC)!"
104         test $KILLSERVERS != no && kill -HUP $KILLPIDS
105         exit $RC
106 fi
107
108 echo "Testing NOT searching..."
109 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
110         '(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1
111 RC=$?
112 if test $RC != 0 ; then
113         echo "ldapsearch failed ($RC)!"
114         test $KILLSERVERS != no && kill -HUP $KILLPIDS
115         exit $RC
116 fi
117
118 echo "Testing objectClass/attributeType inheritance ..."
119 $LDAPSEARCH -M -a never -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
120         '(&(objectClass=inetorgperson)(userid=uham))' \
121         "2.5.4.0" "userid" >> $SEARCHOUT 2>&1
122 RC=$?
123 if test $RC != 0 ; then
124         echo "ldapsearch failed ($RC)!"
125         test $KILLSERVERS != no && kill -HUP $KILLPIDS
126         exit $RC
127 fi
128
129 test $KILLSERVERS != no && kill -HUP $KILLPIDS
130
131 LDIF=$SEARCHOUTMASTER
132
133 echo "Filtering ldapsearch results..."
134 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
135 echo "Filtering original ldif used to create database..."
136 . $LDIFFILTER < $LDIF > $LDIFFLT
137 echo "Comparing filter output..."
138 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
139
140 if test $? != 0 ; then
141         echo "Comparison failed"
142         exit 1
143 fi
144
145 echo ">>>>> Test succeeded"
146 exit 0