]> git.sur5r.net Git - openldap/blob - tests/scripts/test042-valsort
sync with head
[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 sleep 1
45
46 echo "Testing slapd sorted values operations..."
47 for i in 0 1 2 3 4 5; do
48         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
49                 'objectclass=*' > /dev/null 2>&1
50         RC=$?
51         if test $RC = 0 ; then
52                 break
53         fi
54         echo "Waiting 5 seconds for slapd to start..."
55         sleep 5
56 done
57
58 if test $RC != 0 ; then
59         echo "ldapsearch failed ($RC)!"
60         test $KILLSERVERS != no && kill -HUP $KILLPIDS
61         exit $RC
62 fi
63
64 echo "Testing ascending and weighted sort"
65
66 FILTER="objectClass=*"
67 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
68         "$FILTER" > $SEARCHOUT 2>&1
69
70 RC=$?
71 if test $RC != 0 ; then
72         echo "ldapsearch failed ($RC)!"
73         test $KILLSERVERS != no && kill -HUP $KILLPIDS
74         exit $RC
75 fi
76
77 echo "Filtering ldapsearch results..."
78 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
79 echo "Comparing filter output..."
80 $CMP $SEARCHFLT $VALSORTOUT1 > $CMPOUT
81
82 if test $? != 0 ; then
83         echo "Comparison failed"
84         test $KILLSERVERS != no && kill -HUP $KILLPIDS
85         exit 1
86 fi
87
88 echo ">>>>> Test succeeded"
89
90 echo "Reconfiguring slapd to test valsort descending"
91
92 $LDAPMODIFY -x -D cn=config -h $LOCALHOST -p $PORT1 -w $PASSWD > \
93         $TESTOUT 2>&1 << EOMODS
94 version: 1
95 dn: olcOverlay={0}valsort,olcDatabase={1}$BACKEND,cn=config
96 changetype: modify
97 replace: olcValSortAttr
98 olcValSortAttr: employeeType "ou=users,o=valsort" weighted alpha-descend
99 olcValSortAttr: ou "ou=users,o=valsort" weighted
100 olcValSortAttr: mailPreferenceOption "ou=users,o=valsort" numeric-descend
101 olcValSortAttr: departmentNumber "ou=users,o=valsort" alpha-descend
102 olcValSortAttr: sn "ou=users,o=valsort" alpha-descend
103
104 EOMODS
105
106 RC=$?
107 if test $RC != 0 ; then
108     echo "ldapmodify failed ($RC)!"
109     test $KILLSERVERS != no && kill -HUP $KILLPIDS
110     exit $RC
111 fi
112
113 echo "Testing descending and weighted sort"
114
115 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
116         "$FILTER" > $SEARCHOUT 2>&1
117
118 RC=$?
119 if test $RC != 0 ; then
120         echo "ldapsearch failed ($RC)!"
121         test $KILLSERVERS != no && kill -HUP $KILLPIDS
122         exit $RC
123 fi
124
125 echo "Filtering ldapsearch results..."
126 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
127 echo "Comparing filter output..."
128 $CMP $SEARCHFLT $VALSORTOUT2 > $CMPOUT
129
130 if test $? != 0 ; then
131         echo "Comparison failed"
132         test $KILLSERVERS != no && kill -HUP $KILLPIDS
133         exit 1
134 fi
135
136 echo ">>>>> Test succeeded"
137
138 echo "Adding a valsort record with weighted ou..."
139
140 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
141         > /dev/null << EOTVALSORT1
142 dn: uid=dave,ou=users,o=valsort
143 objectClass: OpenLDAPperson
144 uid: dave
145 sn: nothere
146 cn: dave
147 businessCategory: otest
148 carLicense: TEST
149 departmentNumber: 42
150 displayName: Dave
151 employeeNumber: 69
152 employeeType: {1}contractor
153 givenName: Dave
154 ou: {1}Test
155 ou: {3}Okay
156 ou: {2}Is
157 EOTVALSORT1
158
159 RC=$?
160 if test $RC != 0 ; then
161         echo "ldapadd failed ($RC)!"
162         test $KILLSERVERS != no && kill -HUP $KILLPIDS
163         exit $RC
164 fi
165
166 #echo ----------------------
167 #$LDAPSEARCH -b "o=valsort" -h $LOCALHOST -p $PORT1
168
169 echo "Adding a non-weighted valsort record with ou..."
170
171 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
172          $TESTOUT 2>&1 << EOTVALSORT2
173 dn: uid=bill,ou=users,o=valsort
174 objectClass: OpenLDAPperson
175 uid: bill
176 sn: johnson
177 cn: bill
178 businessCategory: rtest
179 carLicense: ABC123
180 departmentNumber: 42
181 displayName: Bill
182 employeeNumber: 5150
183 employeeType: {1}contractor
184 givenName: Bill
185 ou: Test
186 ou: Okay
187 ou: Is
188 EOTVALSORT2
189
190 RC=$?
191 if test $RC != 19 ; then
192         echo "valsort check failed ($RC)!"
193         test $KILLSERVERS != no && kill -HUP $KILLPIDS
194         exit -1
195 fi
196
197 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
198         "$FILTER" > $SEARCHOUT 2>&1
199
200 RC=$?
201 if test $RC != 0 ; then
202         echo "ldapsearch failed ($RC)!"
203         test $KILLSERVERS != no && kill -HUP $KILLPIDS
204         exit $RC
205 fi
206
207 echo "Filtering ldapsearch results..."
208 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
209 echo "Comparing filter output..."
210 $CMP $SEARCHFLT $VALSORTOUT3 > $CMPOUT
211
212 if test $? != 0 ; then
213         echo "Comparison failed"
214         test $KILLSERVERS != no && kill -HUP $KILLPIDS
215         exit 1
216 fi
217
218 test $KILLSERVERS != no && kill -HUP $KILLPIDS
219
220 echo ">>>>> Test succeeded"
221 exit 0