]> git.sur5r.net Git - openldap/blob - tests/scripts/test042-valsort
fix slapi_sdn_isempty() logic
[openldap] / tests / scripts / test042-valsort
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2004-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 if test $VALSORT = valsortno; then 
20         echo "Valsort overlay not available, test skipped"
21         exit 0
22 fi 
23
24 mkdir -p $TESTDIR $DBDIR1
25
26 echo "Running slapadd to build slapd database..."
27 . $CONFFILTER $BACKEND $MONITORDB < $VALSORTCONF > $CONF1
28 $SLAPADD -f $CONF1 -l $LDIFVALSORT
29 RC=$?
30 if test $RC != 0 ; then
31         echo "slapadd failed ($RC)!"
32         exit $RC
33 fi
34
35 echo "Starting slapd on TCP/IP port $PORT1..."
36 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
37 PID=$!
38 if test $WAIT != 0 ; then
39     echo PID $PID
40     read foo
41 fi
42 KILLPIDS="$PID"
43
44 echo "Testing slapd sorted values operations..."
45 for i in 0 1 2 3 4 5; do
46         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
47                 'objectclass=*' > /dev/null 2>&1
48         RC=$?
49         if test $RC = 0 ; then
50                 break
51         fi
52         echo "Waiting 5 seconds for slapd to start..."
53         sleep 5
54 done
55
56 if test $RC != 0 ; then
57         echo "ldapsearch failed ($RC)!"
58         test $KILLSERVERS != no && kill -HUP $KILLPIDS
59         exit $RC
60 fi
61
62 echo "Testing ascending and weighted sort"
63
64 FILTER="objectClass=*"
65 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
66         "$FILTER" > $SEARCHOUT 2>&1
67
68 RC=$?
69 if test $RC != 0 ; then
70         echo "ldapsearch failed ($RC)!"
71         test $KILLSERVERS != no && kill -HUP $KILLPIDS
72         exit $RC
73 fi
74
75 echo "Filtering ldapsearch results..."
76 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
77 echo "Comparing filter output..."
78 $CMP $SEARCHFLT $VALSORTOUT1 > $CMPOUT
79
80 if test $? != 0 ; then
81         echo "Comparison failed"
82         test $KILLSERVERS != no && kill -HUP $KILLPIDS
83         exit 1
84 fi
85
86 echo ">>>>> Test succeeded"
87
88 echo "Reconfiguring slapd to test valsort descending"
89
90 $LDAPMODIFY -x -D cn=config -h $LOCALHOST -p $PORT1 -w $PASSWD > \
91         $TESTOUT 2>&1 << EOMODS
92 version: 1
93 dn: olcOverlay={0}valsort,olcDatabase={1}$BACKEND,cn=config
94 changetype: modify
95 replace: olcValSortAttr
96 olcValSortAttr: employeeType "ou=users,o=valsort" weighted alpha-descend
97 olcValSortAttr: ou "ou=users,o=valsort" weighted
98 olcValSortAttr: mailPreferenceOption "ou=users,o=valsort" numeric-descend
99 olcValSortAttr: departmentNumber "ou=users,o=valsort" alpha-descend
100 olcValSortAttr: sn "ou=users,o=valsort" alpha-descend
101
102 EOMODS
103
104 RC=$?
105 if test $RC != 0 ; then
106     echo "ldapmodify failed ($RC)!"
107     test $KILLSERVERS != no && kill -HUP $KILLPIDS
108     exit $RC
109 fi
110
111 echo "Testing descending and weighted sort"
112
113 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
114         "$FILTER" > $SEARCHOUT 2>&1
115
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 "Filtering ldapsearch results..."
124 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
125 echo "Comparing filter output..."
126 $CMP $SEARCHFLT $VALSORTOUT2 > $CMPOUT
127
128 if test $? != 0 ; then
129         echo "Comparison failed"
130         test $KILLSERVERS != no && kill -HUP $KILLPIDS
131         exit 1
132 fi
133
134 echo ">>>>> Test succeeded"
135
136 echo "Adding a valsort record with weighted ou..."
137
138 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
139         > /dev/null << EOTVALSORT1
140 dn: uid=dave,ou=users,o=valsort
141 objectClass: OpenLDAPperson
142 uid: dave
143 sn: nothere
144 cn: dave
145 businessCategory: otest
146 carLicense: TEST
147 departmentNumber: 42
148 displayName: Dave
149 employeeNumber: 69
150 employeeType: {1}contractor
151 givenName: Dave
152 ou: {1}Test
153 ou: {3}Okay
154 ou: {2}Is
155 EOTVALSORT1
156
157 RC=$?
158 if test $RC != 0 ; then
159         echo "ldapadd failed ($RC)!"
160         test $KILLSERVERS != no && kill -HUP $KILLPIDS
161         exit $RC
162 fi
163
164 #echo ----------------------
165 #$LDAPSEARCH -b "o=valsort" -h $LOCALHOST -p $PORT1
166
167 echo "Adding a non-weighted valsort record with ou..."
168
169 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
170          $TESTOUT 2>&1 << EOTVALSORT2
171 dn: uid=bill,ou=users,o=valsort
172 objectClass: OpenLDAPperson
173 uid: bill
174 sn: johnson
175 cn: bill
176 businessCategory: rtest
177 carLicense: ABC123
178 departmentNumber: 42
179 displayName: Bill
180 employeeNumber: 5150
181 employeeType: {1}contractor
182 givenName: Bill
183 ou: Test
184 ou: Okay
185 ou: Is
186 EOTVALSORT2
187
188 RC=$?
189 if test $RC != 19 ; then
190         echo "valsort check failed ($RC)!"
191         test $KILLSERVERS != no && kill -HUP $KILLPIDS
192         exit -1
193 fi
194
195 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
196         "$FILTER" > $SEARCHOUT 2>&1
197
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 echo "Filtering ldapsearch results..."
206 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
207 echo "Comparing filter output..."
208 $CMP $SEARCHFLT $VALSORTOUT3 > $CMPOUT
209
210 if test $? != 0 ; then
211         echo "Comparison failed"
212         test $KILLSERVERS != no && kill -HUP $KILLPIDS
213         exit 1
214 fi
215
216 test $KILLSERVERS != no && kill -HUP $KILLPIDS
217
218 echo ">>>>> Test succeeded"
219 exit 0