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