]> git.sur5r.net Git - openldap/blob - tests/scripts/test031-component-filter
1) existing matching rules support in component filter
[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 ## and --enable-modules  is configured yes
22 if test "$AC_WITH_MODULES_ENABLED" != "yes" ; then
23         echo "dynamic module disabled "
24         exit
25 fi
26
27 mkdir -p $TESTDIR $DBDIR1
28
29 ## Make sure that you set a proper path to component matching 
30 ## module directory in $COMPCONF
31 ## moduleload path/to/component/library/compmatch.la
32 ## otherwise it fails to execute slapd
33 echo "Running slapadd to build slapd database..."
34 . $CONFFILTER $BACKEND $MONITORDB < $COMPCONF > $ADDCONF
35 $SLAPADD -f $ADDCONF -l $LDIFCOMPMATCH
36 RC=$?
37 if test $RC != 0 ; then
38         echo "slapadd failed ($RC)!"
39         echo "Be sure to have a certificate module in tests/data/comp_libs "
40         echo "The module is in openldap/contrib/slapd-modules/comp_match"
41         exit 
42 fi
43
44 echo "Running slapindex to index slapd database..."
45 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
46 $SLAPINDEX -f $CONF1
47 RC=$?
48 if test $RC != 0 ; then
49         echo "warning: slapindex failed ($RC)"
50         echo "  assuming no indexing support"
51 fi
52
53 echo "Starting slapd on TCP/IP port $PORT1..."
54 $SLAPD -f $ADDCONF -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
55 PID=$!
56 if test $WAIT != 0 ; then
57     echo PID $PID
58     read foo
59 fi
60 KILLPIDS="$PID"
61
62 echo "Testing slapd searching..."
63 for i in 0 1 2 3 4 5; do
64         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
65                 'objectclass=*' > /dev/null 2>&1
66         RC=$?
67         if test $RC = 0 ; then
68                 break
69         fi
70         echo "Waiting 5 seconds for slapd to start..."
71         sleep 5
72 done
73
74 if test $RC != 0 ; then
75         echo "ldapsearch failed ($RC)!"
76         test $KILLSERVERS != no && kill -HUP $KILLPIDS
77         exit $RC
78 fi
79
80 cat /dev/null > $SEARCHOUT
81
82 echo "Testing Component Filter Match RFC3687 Certificate searching:"
83 echo "# Testing Component Filter Match RFC3687 Certificate searching:" >> $SEARCHOUT
84
85 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.serialNumber\", rule allComponentsMatch, value 0 })"
86 echo "        f=$FILTER ..."
87 echo "#         f=$FILTER ..." >> $SEARCHOUT
88 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
89         "$FILTER" >> $SEARCHOUT 2>&1
90
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 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.version\", rule allComponentsMatch, value 2 })"
99 echo "        f=$FILTER ..."
100 echo "#         f=$FILTER ..." >> $SEARCHOUT
101 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
102         "$FILTER" >> $SEARCHOUT 2>&1
103
104 RC=$?
105 if test $RC != 0 ; then
106         echo "ldapsearch failed ($RC)!"
107         test $KILLSERVERS != no && kill -HUP $KILLPIDS
108         exit $RC
109 fi
110
111 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence.1.1.value\", rule caseExactMatch, value \"US\" })"
112 echo "        f=$FILTER ..."
113 echo "#         f=$FILTER ..." >> $SEARCHOUT
114 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
115         "$FILTER" >> $SEARCHOUT 2>&1
116
117 RC=$?
118 if test $RC != 0 ; then
119         echo "ldapsearch failed ($RC)!"
120         test $KILLSERVERS != no && kill -HUP $KILLPIDS
121         exit $RC
122 fi
123
124 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence.1.1.value\", rule allComponentsMatch, value \"US\" })"
125 echo "        f=$FILTER ..."
126 echo "#         f=$FILTER ..." >> $SEARCHOUT
127 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
128         "$FILTER" >> $SEARCHOUT 2>&1
129
130 RC=$?
131 if test $RC != 0 ; then
132         echo "ldapsearch failed ($RC)!"
133         test $KILLSERVERS != no && kill -HUP $KILLPIDS
134         exit $RC
135 fi
136
137 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence\", rule allComponentsMatch, value { { { type 2.5.4.6 , value \"US\" } } } })"
138 echo "        f=$FILTER ..."
139 echo "#         f=$FILTER ..." >> $SEARCHOUT
140 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
141         "$FILTER" >> $SEARCHOUT 2>&1
142
143 RC=$?
144 if test $RC != 0 ; then
145         echo "ldapsearch failed ($RC)!"
146         test $KILLSERVERS != no && kill -HUP $KILLPIDS
147         exit $RC
148 fi
149
150 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.extensions.0\", rule integerMatch, value 3 })"
151 echo "        f=$FILTER ..."
152 echo "#         f=$FILTER ..." >> $SEARCHOUT
153 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
154         "$FILTER" >> $SEARCHOUT 2>&1
155
156 RC=$?
157 if test $RC != 0 ; then
158         echo "ldapsearch failed ($RC)!"
159         test $KILLSERVERS != no && kill -HUP $KILLPIDS
160         exit $RC
161 fi
162
163 FILTER="(userCertificate:componentFilterMatch:=item:{component \"tbsCertificate.extensions.\2a.extnID\",rule allComponentsMatch, value 2.5.29.14 })"
164 echo "        f=$FILTER ..."
165 echo "#         f=$FILTER ..." >> $SEARCHOUT
166 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
167         "$FILTER" >> $SEARCHOUT 2>&1
168
169 RC=$?
170 if test $RC != 0 ; then
171         echo "ldapsearch failed ($RC)!"
172         test $KILLSERVERS != no && kill -HUP $KILLPIDS
173         exit $RC
174 fi
175
176 FILTER="(userCertificate:componentFilterMatch:=not:item:{component \"tbsCertificate.extensions.\2a\",rule allComponentsMatch, value { extnID 2.5.29.19 , extnValue '30030101FF'H })"
177 echo "        f=$FILTER ..."
178 echo "#         f=$FILTER ..." >> $SEARCHOUT
179 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
180         "$FILTER" >> $SEARCHOUT 2>&1
181
182 RC=$?
183 if test $RC != 0 ; then
184         echo "ldapsearch failed ($RC)!"
185         test $KILLSERVERS != no && kill -HUP $KILLPIDS
186         exit $RC
187 fi
188
189 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence\", rule distinguishedNameMatch, value \"c=US\" })"
190 echo "        f=$FILTER ..."
191 echo "#         f=$FILTER ..." >> $SEARCHOUT
192 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
193         "$FILTER" >> $SEARCHOUT 2>&1
194
195 RC=$?
196 if test $RC != 0 ; then
197         echo "ldapsearch failed ($RC)!"
198         test $KILLSERVERS != no && kill -HUP $KILLPIDS
199         exit $RC
200 fi
201
202 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"tbsCertificate.issuer.rdnSequence.1\", rule rdnMatch, value \"c=US\" })"
203 echo "        f=$FILTER ..."
204 echo "#         f=$FILTER ..." >> $SEARCHOUT
205 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
206         "$FILTER" >> $SEARCHOUT 2>&1
207
208 RC=$?
209 if test $RC != 0 ; then
210         echo "ldapsearch failed ($RC)!"
211         test $KILLSERVERS != no && kill -HUP $KILLPIDS
212         exit $RC
213 fi
214
215
216
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
218
219 echo "Filtering ldapsearch results..."
220 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
221 echo "Comparing filter output..."
222 $CMP $SEARCHFLT $COMPSEARCHOUT > $CMPOUT
223
224 if test $? != 0 ; then
225         echo "Comparison failed"
226         exit 1
227 fi
228
229 echo ">>>>> Test succeeded"
230 exit 0