]> git.sur5r.net Git - openldap/blob - tests/scripts/test031-component-filter
5698e02cd2ee42f182bb2bc97a7bebb130352730
[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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 \"toBeSigned.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 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.extensions.\2a.extnValue.content.\282.5.29.35\29.authorityCertSerialNumber\", rule integerMatch, value 0 })"
216 echo "        f=$FILTER ..."
217 echo "#         f=$FILTER ..." >> $SEARCHOUT
218 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
219         "$FILTER" >> $SEARCHOUT 2>&1
220
221 RC=$?
222 if test $RC != 0 ; then
223         echo "ldapsearch failed ($RC)!"
224         test $KILLSERVERS != no && kill -HUP $KILLPIDS
225         exit $RC
226 fi
227
228
229 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.subject.rdnSequence.\2a\", rule rdnMatch, value \"c=US\" })"
230 echo "        f=$FILTER ..."
231 echo "#         f=$FILTER ..." >> $SEARCHOUT
232 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
233         "$FILTER" >> $SEARCHOUT 2>&1
234
235 RC=$?
236 if test $RC != 0 ; then
237         echo "ldapsearch failed ($RC)!"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS
239         exit $RC
240 fi
241
242 FILTER="(userCertificate:componentFilterMatch:=item:{ component \"toBeSigned.subject.rdnSequence.\2a.\2a.value.\282.5.4.6\29\", rule caseExactMatch, value \"US\" })"
243 echo "        f=$FILTER ..."
244 echo "#         f=$FILTER ..." >> $SEARCHOUT
245 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
246         "$FILTER" >> $SEARCHOUT 2>&1
247
248 RC=$?
249 if test $RC != 0 ; then
250         echo "ldapsearch failed ($RC)!"
251         test $KILLSERVERS != no && kill -HUP $KILLPIDS
252         exit $RC
253 fi
254
255 FILTER="(x509CertificateIssuer:distinguishedNameMatch:=c=US)"
256 echo "        f=$FILTER ..."
257 echo "#         f=$FILTER ..." >> $SEARCHOUT
258 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
259         "$FILTER" >> $SEARCHOUT 2>&1
260
261 RC=$?
262 if test $RC != 0 ; then
263         echo "ldapsearch failed ($RC)!"
264         test $KILLSERVERS != no && kill -HUP $KILLPIDS
265         exit $RC
266 fi
267
268 FILTER="(x509CertificateSerial:integerMatch:=0)"
269 echo "        f=$FILTER ..."
270 echo "#         f=$FILTER ..." >> $SEARCHOUT
271 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
272         "$FILTER" >> $SEARCHOUT 2>&1
273
274 RC=$?
275 if test $RC != 0 ; then
276         echo "ldapsearch failed ($RC)!"
277         test $KILLSERVERS != no && kill -HUP $KILLPIDS
278         exit $RC
279 fi
280
281 FILTER="(x509CertificateSerialAndIssuer:certificateExactMatch:=0\$c=US)"
282 echo "        f=$FILTER ..."
283 echo "#         f=$FILTER ..." >> $SEARCHOUT
284 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
285         "$FILTER" >> $SEARCHOUT 2>&1
286
287 RC=$?
288 if test $RC != 0 ; then
289         echo "ldapsearch failed ($RC)!"
290         test $KILLSERVERS != no && kill -HUP $KILLPIDS
291         exit $RC
292 fi
293
294 test $KILLSERVERS != no && kill -HUP $KILLPIDS
295
296 echo "Filtering ldapsearch results..."
297 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
298 echo "Comparing filter output..."
299 $CMP $SEARCHFLT $COMPSEARCHOUT > $CMPOUT
300
301 if test $? != 0 ; then
302         echo "Comparison failed"
303         exit 1
304 fi
305
306 echo ">>>>> Test succeeded"
307 exit 0