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