Home | History | Annotate | Line # | Download | only in scripts
test009-referral revision 1.1.1.4
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2014 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 #
     20 # Test default referral
     21 #
     22 
     23 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
     24 
     25 echo "Running slapadd to build slapd database..."
     26 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
     27 $SLAPADD -f $CONF1 -l $LDIFORDERED
     28 RC=$?
     29 if test $RC != 0 ; then
     30 	echo "slapadd failed ($RC)!"
     31 	exit $RC
     32 fi
     33 
     34 echo "Starting master slapd on TCP/IP port $PORT1..."
     35 $SLAPD -n master -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
     36 PID=$!
     37 if test $WAIT != 0 ; then
     38     echo PID $PID
     39     read foo
     40 fi
     41 
     42 echo "Starting slave slapd on TCP/IP port $PORT2..."
     43 . $CONFFILTER $BACKEND $MONITORDB < $REFSLAVECONF > $CONF2
     44 $SLAPD -n slave -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
     45 SLAVEPID=$!
     46 if test $WAIT != 0 ; then
     47     echo SLAVEPID $SLAVEPID
     48     read foo
     49 fi
     50 
     51 KILLPIDS="$PID $SLAVEPID"
     52 
     53 sleep 1
     54 
     55 echo "Testing for master slapd..."
     56 for i in 0 1 2 3 4 5; do
     57 	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
     58 		'objectclass=*' > /dev/null 2>&1
     59 	RC=$?
     60 	if test $RC = 0 ; then
     61 		break
     62 	fi
     63 	echo "Waiting 5 seconds for master slapd to start..."
     64 	sleep 5
     65 done
     66 
     67 if test $RC != 0 ; then
     68 	echo "ldapsearch failed ($RC)!"
     69 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     70 	exit $RC
     71 fi
     72 
     73 echo "Testing for slave slapd..."
     74 for i in 0 1 2 3 4 5; do
     75 	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
     76 		'objectclass=*' > /dev/null 2>&1
     77 	RC=$?
     78 	if test $RC = 0 ; then
     79 		break
     80 	fi
     81 	echo "Waiting 5 seconds for slave slapd to start..."
     82 	sleep 5
     83 done
     84 
     85 cat /dev/null > $SEARCHOUT
     86 
     87 echo "Testing exact searching..."
     88 $LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
     89 	'sn=jensen' >> $SEARCHOUT 2>&1
     90 RC=$?
     91 if test $RC != 0 ; then
     92 	echo "ldapsearch failed ($RC)!"
     93 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     94 	exit $RC
     95 fi
     96 
     97 echo "Testing approximate searching..."
     98 $LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
     99 	'(sn=jENSEN)' name >> $SEARCHOUT 2>&1
    100 RC=$?
    101 if test $RC != 0 ; then
    102 	echo "ldapsearch failed ($RC)!"
    103 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    104 	exit $RC
    105 fi
    106 
    107 echo "Testing OR searching..."
    108 $LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
    109 	'(|(objectclass=groupofnames)(objectClass=groupofuniquenames)(sn=jones))' >> $SEARCHOUT 2>&1
    110 RC=$?
    111 if test $RC != 0 ; then
    112 	echo "ldapsearch failed ($RC)!"
    113 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    114 	exit $RC
    115 fi
    116 
    117 echo "Testing AND matching and ends-with searching..."
    118 $LDAPSEARCH -C -S "" -b "ou=groups,$BASEDN" -s one -h $LOCALHOST -p $PORT2 \
    119 	'(&(objectclass=groupofnames)(cn=A*))' >> $SEARCHOUT 2>&1
    120 RC=$?
    121 if test $RC != 0 ; then
    122 	echo "ldapsearch failed ($RC)!"
    123 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    124 	exit $RC
    125 fi
    126 
    127 echo "Testing NOT searching..."
    128 $LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
    129 	'(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1
    130 RC=$?
    131 if test $RC != 0 ; then
    132 	echo "ldapsearch failed ($RC)!"
    133 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    134 	exit $RC
    135 fi
    136 
    137 echo "Testing objectClass/attributeType inheritance ..."
    138 $LDAPSEARCH -M -a never -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
    139 	'(&(objectClass=inetorgperson)(userid=uham))' \
    140 	"2.5.4.0" "userid" >> $SEARCHOUT 2>&1
    141 RC=$?
    142 if test $RC != 0 ; then
    143 	echo "ldapsearch failed ($RC)!"
    144 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    145 	exit $RC
    146 fi
    147 
    148 echo "Testing dontUseCopy control..."
    149 $LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
    150 	-E \!dontUseCopy \
    151 	'sn=jensen' >> $SEARCHOUT
    152 RC=$?
    153 if test $RC = 10 ; then
    154 	echo "ldapsearch failed as expected ($RC)"
    155 else
    156 	echo "ldapsearch did not error as expected ($RC)!"
    157 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    158 	exit $RC
    159 fi
    160 
    161 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    162 
    163 LDIF=$SEARCHOUTMASTER
    164 
    165 echo "Filtering ldapsearch results..."
    166 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
    167 echo "Filtering original ldif used to create database..."
    168 $LDIFFILTER < $LDIF > $LDIFFLT
    169 echo "Comparing filter output..."
    170 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    171 
    172 if test $? != 0 ; then
    173 	echo "Comparison failed"
    174 	exit 1
    175 fi
    176 
    177 echo ">>>>> Test succeeded"
    178 
    179 test $KILLSERVERS != no && wait
    180 
    181 exit 0
    182