3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 2004-2016 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
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>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $VALSORT = valsortno; then
20 echo "Valsort overlay not available, test skipped"
24 mkdir -p $TESTDIR $DBDIR1
26 $SLAPPASSWD -g -n >$CONFIGPWF
27 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
29 echo "Running slapadd to build slapd database..."
30 . $CONFFILTER $BACKEND $MONITORDB < $VALSORTCONF > $CONF1
31 $SLAPADD -f $CONF1 -l $LDIFVALSORT
33 if test $RC != 0 ; then
34 echo "slapadd failed ($RC)!"
38 echo "Starting slapd on TCP/IP port $PORT1..."
39 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 if test $WAIT != 0 ; then
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
54 if test $RC = 0 ; then
57 echo "Waiting 5 seconds for slapd to start..."
61 if test $RC != 0 ; then
62 echo "ldapsearch failed ($RC)!"
63 test $KILLSERVERS != no && kill -HUP $KILLPIDS
67 echo "Testing ascending and weighted sort"
69 FILTER="objectClass=*"
70 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
71 "$FILTER" > $SEARCHOUT 2>&1
74 if test $RC != 0 ; then
75 echo "ldapsearch failed ($RC)!"
76 test $KILLSERVERS != no && kill -HUP $KILLPIDS
80 echo "Filtering ldapsearch results..."
81 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
82 echo "Filtering expected ldif..."
83 $LDIFFILTER < $VALSORTOUT1 > $LDIFFLT
84 echo "Comparing filter output..."
85 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
87 if test $? != 0 ; then
88 echo "Comparison failed"
89 test $KILLSERVERS != no && kill -HUP $KILLPIDS
93 echo "Reconfiguring slapd to test valsort descending"
95 $LDAPMODIFY -x -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF > \
96 $TESTOUT 2>&1 << EOMODS
98 dn: olcOverlay={0}valsort,olcDatabase={1}$BACKEND,cn=config
100 replace: olcValSortAttr
101 olcValSortAttr: employeeType "ou=users,o=valsort" weighted alpha-descend
102 olcValSortAttr: ou "ou=users,o=valsort" weighted
103 olcValSortAttr: mailPreferenceOption "ou=users,o=valsort" numeric-descend
104 olcValSortAttr: departmentNumber "ou=users,o=valsort" alpha-descend
105 olcValSortAttr: sn "ou=users,o=valsort" alpha-descend
110 if test $RC != 0 ; then
111 echo "ldapmodify failed ($RC)!"
112 test $KILLSERVERS != no && kill -HUP $KILLPIDS
116 echo "Testing descending and weighted sort"
118 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
119 "$FILTER" > $SEARCHOUT 2>&1
122 if test $RC != 0 ; then
123 echo "ldapsearch failed ($RC)!"
124 test $KILLSERVERS != no && kill -HUP $KILLPIDS
128 echo "Filtering ldapsearch results..."
129 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
130 echo "Filtering expected ldif..."
131 $LDIFFILTER < $VALSORTOUT2 > $LDIFFLT
132 echo "Comparing filter output..."
133 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
135 if test $? != 0 ; then
136 echo "Comparison failed"
137 test $KILLSERVERS != no && kill -HUP $KILLPIDS
141 echo "Adding a valsort record with weighted ou..."
143 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
144 > /dev/null << EOTVALSORT1
145 dn: uid=dave,ou=users,o=valsort
146 objectClass: OpenLDAPperson
150 businessCategory: otest
155 employeeType: {1}contractor
163 if test $RC != 0 ; then
164 echo "ldapadd failed ($RC)!"
165 test $KILLSERVERS != no && kill -HUP $KILLPIDS
169 #echo ----------------------
170 #$LDAPSEARCH -b "o=valsort" -h $LOCALHOST -p $PORT1
172 echo "Adding a non-weighted valsort record with ou..."
174 $LDAPADD -D "$VALSORTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
175 $TESTOUT 2>&1 << EOTVALSORT2
176 dn: uid=bill,ou=users,o=valsort
177 objectClass: OpenLDAPperson
181 businessCategory: rtest
186 employeeType: {1}contractor
194 if test $RC != 19 ; then
195 echo "valsort check failed ($RC)!"
196 test $KILLSERVERS != no && kill -HUP $KILLPIDS
200 $LDAPSEARCH -b "$VALSORTBASEDN" -h $LOCALHOST -p $PORT1 \
201 "$FILTER" > $SEARCHOUT 2>&1
204 if test $RC != 0 ; then
205 echo "ldapsearch failed ($RC)!"
206 test $KILLSERVERS != no && kill -HUP $KILLPIDS
210 echo "Filtering ldapsearch results..."
211 $LDIFFILTER -s ldif=e < $SEARCHOUT > $SEARCHFLT
212 echo "Filtering expected ldif..."
213 $LDIFFILTER -s ldif=e < $VALSORTOUT3 > $LDIFFLT
214 echo "Comparing filter output..."
215 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
217 if test $? != 0 ; then
218 echo "Comparison failed"
219 test $KILLSERVERS != no && kill -HUP $KILLPIDS
223 test $KILLSERVERS != no && kill -HUP $KILLPIDS
225 test $KILLSERVERS != no && wait
227 echo ">>>>> Test succeeded"