1 #! /bin/sh 2 # $OpenLDAP$ 3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4 ## 5 ## Copyright 2004-2024 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 < $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 > $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 $URI1 \ 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 $URI1 \ 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 "Filtering expected ldif..." 83 $LDIFFILTER < $VALSORTOUT1 > $LDIFFLT 84 echo "Comparing filter output..." 85 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 86 87 if test $? != 0 ; then 88 echo "Comparison failed" 89 test $KILLSERVERS != no && kill -HUP $KILLPIDS 90 exit 1 91 fi 92 93 echo "Reconfiguring slapd to test valsort descending" 94 95 $LDAPMODIFY -x -D cn=config -H $URI1 -y $CONFIGPWF > \ 96 $TESTOUT 2>&1 << EOMODS 97 version: 1 98 dn: olcOverlay={0}valsort,olcDatabase={1}$BACKEND,cn=config 99 changetype: modify 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 106 107 EOMODS 108 109 RC=$? 110 if test $RC != 0 ; then 111 echo "ldapmodify failed ($RC)!" 112 test $KILLSERVERS != no && kill -HUP $KILLPIDS 113 exit $RC 114 fi 115 116 echo "Testing descending and weighted sort" 117 118 $LDAPSEARCH -b "$VALSORTBASEDN" -H $URI1 \ 119 "$FILTER" > $SEARCHOUT 2>&1 120 121 RC=$? 122 if test $RC != 0 ; then 123 echo "ldapsearch failed ($RC)!" 124 test $KILLSERVERS != no && kill -HUP $KILLPIDS 125 exit $RC 126 fi 127 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 134 135 if test $? != 0 ; then 136 echo "Comparison failed" 137 test $KILLSERVERS != no && kill -HUP $KILLPIDS 138 exit 1 139 fi 140 141 echo "Adding a valsort record with weighted ou..." 142 143 $LDAPADD -D "$VALSORTDN" -H $URI1 -w $PASSWD \ 144 > /dev/null << EOTVALSORT1 145 dn: uid=dave,ou=users,o=valsort 146 objectClass: OpenLDAPperson 147 uid: dave 148 sn: nothere 149 cn: dave 150 businessCategory: otest 151 carLicense: TEST 152 departmentNumber: 42 153 displayName: Dave 154 employeeNumber: 69 155 employeeType: {1}contractor 156 givenName: Dave 157 ou: {1}Test 158 ou: {3}Okay 159 ou: {2}Is 160 EOTVALSORT1 161 162 RC=$? 163 if test $RC != 0 ; then 164 echo "ldapadd failed ($RC)!" 165 test $KILLSERVERS != no && kill -HUP $KILLPIDS 166 exit $RC 167 fi 168 169 #echo ---------------------- 170 #$LDAPSEARCH -b "o=valsort" -H $URI1 171 172 echo "Adding a non-weighted valsort record with ou..." 173 174 $LDAPADD -D "$VALSORTDN" -H $URI1 -w $PASSWD > \ 175 $TESTOUT 2>&1 << EOTVALSORT2 176 dn: uid=bill,ou=users,o=valsort 177 objectClass: OpenLDAPperson 178 uid: bill 179 sn: johnson 180 cn: bill 181 businessCategory: rtest 182 carLicense: ABC123 183 departmentNumber: 42 184 displayName: Bill 185 employeeNumber: 5150 186 employeeType: {1}contractor 187 givenName: Bill 188 ou: Test 189 ou: Okay 190 ou: Is 191 EOTVALSORT2 192 193 RC=$? 194 if test $RC != 19 ; then 195 echo "valsort check failed ($RC)!" 196 test $KILLSERVERS != no && kill -HUP $KILLPIDS 197 exit 1 198 fi 199 200 $LDAPSEARCH -b "$VALSORTBASEDN" -H $URI1 \ 201 "$FILTER" > $SEARCHOUT 2>&1 202 203 RC=$? 204 if test $RC != 0 ; then 205 echo "ldapsearch failed ($RC)!" 206 test $KILLSERVERS != no && kill -HUP $KILLPIDS 207 exit $RC 208 fi 209 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 216 217 if test $? != 0 ; then 218 echo "Comparison failed" 219 test $KILLSERVERS != no && kill -HUP $KILLPIDS 220 exit 1 221 fi 222 223 test $KILLSERVERS != no && kill -HUP $KILLPIDS 224 225 test $KILLSERVERS != no && wait 226 227 echo ">>>>> Test succeeded" 228 229 exit 0 230