]> git.sur5r.net Git - openldap/blob - tests/scripts/test031-component-filter
42d7747226be839c40180d8335e1360511bc7953
[openldap] / tests / scripts / test031-component-filter
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 ## If you use this script then
20 ## Make sure that you turn on LDAP_COMP_MATCH in slapd source codes
21 ## To disable, set "WITH_COMP_MATHC=no" in source_root/openldap/tests/run.in
22 if test "$AC_WITH_COMP_MATCH" != "yes" ; then
23         echo "test disabled "
24         exit
25 fi
26
27 mkdir -p $TESTDIR $DBDIR1
28
29 echo "Running slapadd to build slapd database..."
30 . $CONFFILTER $BACKEND $MONITORDB < $MCONF > $ADDCONF
31 $SLAPADD -f $ADDCONF -l $LDIFCOMPMATCH
32 RC=$?
33 if test $RC != 0 ; then
34         echo "slapadd failed ($RC)!"
35         exit $RC
36 fi
37
38 echo "Running slapindex to index slapd database..."
39 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
40 $SLAPINDEX -f $CONF1
41 RC=$?
42 if test $RC != 0 ; then
43         echo "warning: slapindex failed ($RC)"
44         echo "  assuming no indexing support"
45 fi
46
47 echo "Starting slapd on TCP/IP port $PORT1..."
48 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
49 PID=$!
50 if test $WAIT != 0 ; then
51     echo PID $PID
52     read foo
53 fi
54 KILLPIDS="$PID"
55
56 echo "Testing slapd searching..."
57 for i in 0 1 2 3 4 5; do
58         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
59                 'objectclass=*' > /dev/null 2>&1
60         RC=$?
61         if test $RC = 0 ; then
62                 break
63         fi
64         echo "Waiting 5 seconds for slapd to start..."
65         sleep 5
66 done
67
68 if test $RC != 0 ; then
69         echo "ldapsearch failed ($RC)!"
70         test $KILLSERVERS != no && kill -HUP $KILLPIDS
71         exit $RC
72 fi
73
74 cat /dev/null > $SEARCHOUT
75
76 echo "Testing Component Filter Match RFC3687 searching:"
77 echo "# Testing Component Filter Match RFC3687 searching:" >> $SEARCHOUT
78
79 FILTER="(componentTest:componentFilterMatch:=item:{ component \"id\", rule caseExactMatch, value \"worldcup\" )"
80 echo "        f=$FILTER ..."
81 echo "#         f=$FILTER ..." >> $SEARCHOUT
82 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
83         "$FILTER" >> $SEARCHOUT 2>&1
84
85 RC=$?
86 if test $RC != 0 ; then
87         echo "ldapsearch failed ($RC)!"
88         test $KILLSERVERS != no && kill -HUP $KILLPIDS
89         exit $RC
90 fi
91
92 FILTER="(componentTest:componentFilterMatch:=not:item:{ component \"id2\", rule caseExactMatch, value \"worldcup\" )"
93 echo "        f=$FILTER ..."
94 echo "#         f=$FILTER ..." >> $SEARCHOUT
95 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
96         "$FILTER" >> $SEARCHOUT 2>&1
97
98 RC=$?
99 if test $RC != 0 ; then
100         echo "ldapsearch failed ($RC)!"
101         test $KILLSERVERS != no && kill -HUP $KILLPIDS
102         exit $RC
103 fi
104
105 FILTER="(componentTest:componentFilterMatch:=not:item:{ component \"id2\", rule componentFilterMatch, value not:item:{ component \"id.0\", rule integerMatch, value 5 }})"
106 echo "        f=$FILTER ..."
107 echo "#         f=$FILTER ..." >> $SEARCHOUT
108 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
109         "$FILTER" >> $SEARCHOUT 2>&1
110
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 FILTER="(componentTest:componentFilterMatch:=and:{item:{ component \"100\", rule caseIgnoreMatch, value "foobar" },item:{ component \"id2.rr.kk\", rule componentFilterMatch, value item:{ component \"id3\", rule integerMatch, value 1 }}})"
119 echo "        f=$FILTER ..."
120 echo "#         f=$FILTER ..." >> $SEARCHOUT
121 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
122         "$FILTER" >> $SEARCHOUT 2>&1
123
124 RC=$?
125 if test $RC != 0 ; then
126         echo "ldapsearch failed ($RC)!"
127         test $KILLSERVERS != no && kill -HUP $KILLPIDS
128         exit $RC
129 fi
130
131 FILTER="(componentTest:componentFilterMatch:=and:{not:item:{ component \"100\", rule caseIgnoreMatch, value "foobar" },not:item:{ component \"id2.rr.kk\", rule componentFilterMatch, value item:{ component \"id3\", rule integerMatch, value 1 }}})"
132 echo "        f=$FILTER ..."
133 echo "#         f=$FILTER ..." >> $SEARCHOUT
134 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
135         "$FILTER" >> $SEARCHOUT 2>&1
136
137 RC=$?
138 if test $RC != 0 ; then
139         echo "ldapsearch failed ($RC)!"
140         test $KILLSERVERS != no && kill -HUP $KILLPIDS
141         exit $RC
142 fi
143
144 FILTER="(componentTest:componentFilterMatch:=or:{not:item:{ component \"100\", rule caseIgnoreMatch, value "foobar" },not:item:{ component \"id2.rr.kk\", rule componentFilterMatch, value item:{ component \"id3\", rule integerMatch, value 1 }}})"
145 echo "        f=$FILTER ..."
146 echo "#         f=$FILTER ..." >> $SEARCHOUT
147 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
148         "$FILTER" >> $SEARCHOUT 2>&1
149
150 RC=$?
151 if test $RC != 0 ; then
152         echo "ldapsearch failed ($RC)!"
153         test $KILLSERVERS != no && kill -HUP $KILLPIDS
154         exit $RC
155 fi
156 test $KILLSERVERS != no && kill -HUP $KILLPIDS
157
158 echo "Filtering ldapsearch results..."
159 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
160 echo "Comparing filter output..."
161 $CMP $SEARCHFLT $COMPSEARCHOUT > $CMPOUT
162
163 if test $? != 0 ; then
164         echo "Comparison failed"
165         exit 1
166 fi
167
168 echo ">>>>> Test succeeded"
169 exit 0