Home | History | Annotate | Line # | Download | only in scripts
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-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 mkdir -p $TESTDIR $DBDIR1
     20 
     21 echo "Running slapadd to build slapd database..."
     22 . $CONFFILTER $BACKEND < $MCONF > $ADDCONF
     23 $SLAPADD -f $ADDCONF -l $LDIFORDERED
     24 RC=$?
     25 if test $RC != 0 ; then
     26 	echo "slapadd failed ($RC)!"
     27 	exit $RC
     28 fi
     29 
     30 echo "Running slapindex to index slapd database..."
     31 . $CONFFILTER $BACKEND < $CONF > $CONF1
     32 $SLAPINDEX -f $CONF1
     33 RC=$?
     34 if test $RC != 0 ; then
     35 	echo "warning: slapindex failed ($RC)"
     36 	echo "  assuming no indexing support"
     37 fi
     38 
     39 echo "Starting slapd on TCP/IP port $PORT1..."
     40 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
     41 PID=$!
     42 if test $WAIT != 0 ; then
     43     echo PID $PID
     44     read foo
     45 fi
     46 KILLPIDS="$PID"
     47 
     48 sleep 1
     49 
     50 echo "Testing slapd searching..."
     51 for i in 0 1 2 3 4 5; do
     52 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
     53 		'(objectclass=*)' > /dev/null 2>&1
     54 	RC=$?
     55 	if test $RC = 0 ; then
     56 		break
     57 	fi
     58 	echo "Waiting 5 seconds for slapd to start..."
     59 	sleep 5
     60 done
     61 
     62 if test $RC != 0 ; then
     63 	echo "ldapsearch failed ($RC)!"
     64 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     65 	exit $RC
     66 fi
     67 
     68 echo "Testing exact searching..."
     69 echo "# Testing exact searching..." > $SEARCHOUT
     70 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
     71 	'(sn=jENSEN)' >> $SEARCHOUT 2>&1
     72 RC=$?
     73 if test $RC != 0 ; then
     74 	echo "ldapsearch failed ($RC)!"
     75 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     76 	exit $RC
     77 fi
     78 
     79 echo "Testing approximate searching..."
     80 echo "# Testing approximate searching..." >> $SEARCHOUT
     81 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
     82 	'(sn~=jENSEN)' name >> $SEARCHOUT 2>&1
     83 RC=$?
     84 if test $RC != 0 ; then
     85 	echo "ldapsearch failed ($RC)!"
     86 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     87 	exit $RC
     88 fi
     89 
     90 echo "Testing OR searching..."
     91 echo "# Testing OR searching..." >> $SEARCHOUT
     92 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
     93 	'(|(givenname=Xx*yY*Z)(cn=)(undef=*)(objectclass=groupofnames)(sn=jones)(member=cn=Manager,dc=example,dc=com)(uniqueMember=cn=Manager,dc=example,dc=com))' >> $SEARCHOUT 2>&1
     94 RC=$?
     95 if test $RC != 0 ; then
     96 	echo "ldapsearch failed ($RC)!"
     97 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     98 	exit $RC
     99 fi
    100 
    101 echo "Testing AND matching and ends-with searching..."
    102 echo "# Testing AND matching and ends-with searching..." >> $SEARCHOUT
    103 $LDAPSEARCH -S "" -b "ou=groups,$BASEDN" -s one -H $URI1 \
    104 	'(&(objectclass=groupofnames)(cn=A*)(member=cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com))' >> $SEARCHOUT 2>&1
    105 RC=$?
    106 if test $RC != 0 ; then
    107 	echo "ldapsearch failed ($RC)!"
    108 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    109 	exit $RC
    110 fi
    111 
    112 echo "Testing NOT searching..."
    113 echo "# Testing NOT searching..." >> $SEARCHOUT
    114 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    115 	'(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1
    116 RC=$?
    117 if test $RC != 0 ; then
    118 	echo "ldapsearch failed ($RC)!"
    119 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    120 	exit $RC
    121 fi
    122 
    123 echo "Testing objectClass/attributeType inheritance ..."
    124 echo "# Testing objectClass/attributeType inheritance ..." >> $SEARCHOUT
    125 $LDAPSEARCH -M -a never -S "" -b "$BASEDN" -H $URI1 \
    126 	'(&(objectClass=inetorgperson)(userid=uham))' \
    127 	"2.5.4.0" "userid" >> $SEARCHOUT 2>&1
    128 RC=$?
    129 if test $RC != 0 ; then
    130 	echo "ldapsearch failed ($RC)!"
    131 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    132 	exit $RC
    133 fi
    134 
    135 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    136 
    137 LDIF=$SEARCHOUTPROVIDER
    138 
    139 echo "Filtering ldapsearch results..."
    140 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
    141 echo "Filtering original ldif used to create database..."
    142 $LDIFFILTER < $LDIF > $LDIFFLT
    143 echo "Comparing filter output..."
    144 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    145 
    146 if test $? != 0 ; then
    147 	echo "Comparison failed"
    148 	exit 1
    149 fi
    150 
    151 echo ">>>>> Test succeeded"
    152 
    153 test $KILLSERVERS != no && wait
    154 
    155 exit 0
    156