]> git.sur5r.net Git - openldap/blob - tests/scripts/test015-xsearch
5f101d61b30f55b7af228ec48bfeadf799c892c0
[openldap] / tests / scripts / test015-xsearch
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 echo "# Testing exact searching..." >> $SEARCHOUT
70 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
71         '(sn:=jensen)' >> $SEARCHOUT 2>&1
72 RC=$?
73 if test $RC != 0 ; then
74         echo "ldapsearch failed ($RC)!"
75         test $KILLSERVERS != no && kill -HUP $KILLPIDS
76         exit $RC
77 fi
78
79 echo "Testing approximate searching..."
80 echo "# Testing approximate searching..." >> $SEARCHOUT
81 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
82         '(sn~=jensen)' name >> $SEARCHOUT 2>&1
83 RC=$?
84 if test $RC != 0 ; then
85         echo "ldapsearch failed ($RC)!"
86         test $KILLSERVERS != no && kill -HUP $KILLPIDS
87         exit $RC
88 fi
89
90 echo "Testing OR searching..."
91 echo "# Testing OR searching..." >> $SEARCHOUT
92 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
93         '(|(givenName=XX*YY*Z)(cn=)(undef=*)(objectclass=groupofnames)(objectclass=groupofuniquenames)(sn:caseExactMatch:=Jones))' >> $SEARCHOUT 2>&1
94 RC=$?
95 if test $RC != 0 ; then
96         echo "ldapsearch failed ($RC)!"
97         test $KILLSERVERS != no && kill -HUP $KILLPIDS
98         exit $RC
99 fi
100
101 echo "Testing AND matching and ends-with searching..."
102 echo "# Testing AND matching and ends-with searching..." >> $SEARCHOUT
103 $LDAPSEARCH -S "" -b "ou=groups,$BASEDN" -s one -h $LOCALHOST -p $PORT1 \
104         '(&(|(objectclass=groupofnames)(objectclass=groupofuniquenames))(cn=A*))' >> $SEARCHOUT 2>&1
105 RC=$?
106 if test $RC != 0 ; then
107         echo "ldapsearch failed ($RC)!"
108         test $KILLSERVERS != no && kill -HUP $KILLPIDS
109         exit $RC
110 fi
111
112 echo "Testing NOT searching..."
113 echo "# Testing NOT searching..." >> $SEARCHOUT
114 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
115         '(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1
116 RC=$?
117 if test $RC != 0 ; then
118         echo "ldapsearch failed ($RC)!"
119         test $KILLSERVERS != no && kill -HUP $KILLPIDS
120         exit $RC
121 fi
122
123 echo "Testing objectClass/attributeType inheritance ..."
124 echo "# Testing objectClass/attributeType inheritance ..." >> $SEARCHOUT
125 $LDAPSEARCH -M -a never -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
126         '(&(objectClass=inetorgperson)(userid=uham))' \
127         "2.5.4.0" "userid" >> $SEARCHOUT 2>&1
128 RC=$?
129 if test $RC != 0 ; then
130         echo "ldapsearch failed ($RC)!"
131         test $KILLSERVERS != no && kill -HUP $KILLPIDS
132         exit $RC
133 fi
134
135 echo "Testing extended RFC2254 searching:"
136 echo "# Testing extended RFC2254 searching:" >> $SEARCHOUT
137
138 FILTER="(:dn:caseIgnoreIA5Match:=example)"
139 echo "        f=$FILTER ..."
140 echo "#         f=$FILTER ..." >> $SEARCHOUT
141 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
142         "$FILTER" >> $SEARCHOUT 2>&1
143
144 RC=$?
145 if test $RC != 0 ; then
146         echo "ldapsearch failed ($RC)!"
147         test $KILLSERVERS != no && kill -HUP $KILLPIDS
148         exit $RC
149 fi
150
151 FILTER="(:dn:caseExactMatch:=Information Technology Division)"
152 echo "        f=$FILTER ..."
153 echo "#         f=$FILTER ..." >> $SEARCHOUT
154 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
155         "$FILTER" >> $SEARCHOUT 2>&1
156
157 RC=$?
158 if test $RC != 0 ; then
159         echo "ldapsearch failed ($RC)!"
160         test $KILLSERVERS != no && kill -HUP $KILLPIDS
161         exit $RC
162 fi
163
164 #FILTER="(:rdnMatch:=cn=All Staff)"
165 #echo "        f=$FILTER ..."
166 #echo "#         f=$FILTER ..." >> $SEARCHOUT
167 #$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
168 #       "$FILTER" >> $SEARCHOUT 2>&1
169 #
170 #RC=$?
171 #if test $RC != 0 ; then
172 #       echo "ldapsearch failed ($RC)!"
173 #       test $KILLSERVERS != no && kill -HUP $KILLPIDS
174 #       exit $RC
175 #fi
176
177 echo "Testing values return filter searching:"
178 echo "# Testing values return filter searching:" >> $SEARCHOUT
179
180 FILTER="(o=Example, Inc.)"
181 echo "        f=$FILTER ..."
182 echo "#         f=$FILTER ..." >> $SEARCHOUT
183 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
184         -E '!mv='"$FILTER" "$FILTER" >> $SEARCHOUT 2>&1
185 RC=$?
186 if test $RC != 0 ; then
187         echo "ldapsearch failed ($RC)!"
188         test $KILLSERVERS != no && kill -HUP $KILLPIDS
189         exit $RC
190 fi
191
192 FILTER="(dc=example)"
193 VRFILTER="((o:caseExactMatch:=Example, Inc.)(dc=example))"
194 echo "        f=$FILTER mv=$VRFILTER ..."
195 echo "#         f=$FILTER mv=$VRFILTER ..." >> $SEARCHOUT
196 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
197         -E '!mv='"$VRFILTER" "$FILTER" >> $SEARCHOUT 2>&1
198 RC=$?
199 if test $RC != 0 ; then
200         echo "ldapsearch failed ($RC)!"
201         test $KILLSERVERS != no && kill -HUP $KILLPIDS
202         exit $RC
203 fi
204
205 FILTER="(attributeTypes=0.9.2342.19200300.100.1.25)"
206 echo "        f=$FILTER ..."
207 echo "#         f=$FILTER ..." >> $SEARCHOUT
208 $LDAPSEARCH -S "" -b "cn=Subschema" -s "base" -h $LOCALHOST -p $PORT1 \
209         -E '!mv='"$FILTER" "$FILTER" "attributeTypes" >> $SEARCHOUT 2>&1
210 RC=$?
211 if test $RC != 0 ; then
212         echo "ldapsearch failed ($RC)!"
213         test $KILLSERVERS != no && kill -HUP $KILLPIDS
214         exit $RC
215 fi
216
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
218
219 LDIF=$SEARCHOUTMASTER
220 LDIF2=$SEARCHOUTX
221
222 echo "Filtering ldapsearch results..."
223 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
224 echo "Filtering original ldif used to create database..."
225 . $LDIFFILTER < $LDIF > $LDIFFLT
226 . $LDIFFILTER < $LDIF2 >> $LDIFFLT
227 echo "Comparing filter output..."
228 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
229
230 if test $? != 0 ; then
231         echo "Comparison failed"
232         exit 1
233 fi
234
235 echo ">>>>> Test succeeded"
236 exit 0