]> git.sur5r.net Git - openldap/blob - tests/scripts/test015-xsearch
ef20cbbde5385cccd2812b4344afd55c99b12fac
[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-2004 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 OR searching..."
79 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
80         '(|(givenName=XX*YY*Z)(cn=)(undef=*)(objectclass=groupofnames)(objectclass=groupofuniquenames)(sn:caseExactMatch:=Jones))' >> $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 AND matching and ends-with searching..."
89 $LDAPSEARCH -S "" -b "ou=groups,$BASEDN" -s one -h $LOCALHOST -p $PORT1 \
90         '(&(|(objectclass=groupofnames)(objectclass=groupofuniquenames))(cn=A*))' >> $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 NOT searching..."
99 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
100         '(!(objectclass=pilotPerson))' >> $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 objectClass/attributeType inheritance ..."
109 $LDAPSEARCH -M -a never -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
110         '(&(objectClass=inetorgperson)(userid=uham))' \
111         "2.5.4.0" "userid" >> $SEARCHOUT 2>&1
112 RC=$?
113 if test $RC != 0 ; then
114         echo "ldapsearch failed ($RC)!"
115         test $KILLSERVERS != no && kill -HUP $KILLPIDS
116         exit $RC
117 fi
118
119 echo "Testing extended RFC2254 searching..."
120 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
121         '(:dn:caseExactMatch:=University of Michigan)' >> $SEARCHOUT 2>&1
122
123 RC=$?
124 if test $RC != 0 ; then
125         echo "ldapsearch failed ($RC)!"
126         test $KILLSERVERS != no && kill -HUP $KILLPIDS
127         exit $RC
128 fi
129
130 echo "Testing values return filter searching..."
131 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
132         -E '!mv=(o=University of Michigan)' \
133         '(o=University of Michigan)' >> $SEARCHOUT 2>&1
134 RC=$?
135 if test $RC != 0 ; then
136         echo "ldapsearch failed ($RC)!"
137         test $KILLSERVERS != no && kill -HUP $KILLPIDS
138         exit $RC
139 fi
140
141 test $KILLSERVERS != no && kill -HUP $KILLPIDS
142
143 LDIF=$SEARCHOUTMASTER
144 LDIF2=$SEARCHOUTX
145
146 echo "Filtering ldapsearch results..."
147 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
148 echo "Filtering original ldif used to create database..."
149 . $LDIFFILTER < $LDIF > $LDIFFLT
150 . $LDIFFILTER < $LDIF2 >> $LDIFFLT
151 echo "Comparing filter output..."
152 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
153
154 if test $? != 0 ; then
155         echo "Comparison failed"
156         exit 1
157 fi
158
159 echo ">>>>> Test succeeded"
160 exit 0