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 2016-2022 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 ## ACKNOWLEDGEMENTS:
     17 ## This module was written in 2016 by Ondej Kuznk for Symas Corp.
     18 
     19 echo "running defines.sh"
     20 . $SRCDIR/scripts/defines.sh
     21 
     22 . ${SCRIPTDIR}/common.sh
     23 
     24 echo "Comparing aliased attribute..."
     25 $LDAPCOMPARE -H $URI1 \
     26 	"cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN" \
     27 	"mobile:+1 313 555 7671" >> $TESTOUT 2>&1
     28 RC=$?
     29 if test $RC != 6 && test $RC,$BACKEND != 5,null ; then
     30 	echo "ldapcompare failed ($RC)!"
     31 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     32 	exit 1
     33 fi
     34 
     35 $LDAPCOMPARE -H $URI1 \
     36 	"cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN" \
     37 	"mobile:+1 313 555 4177" >> $TESTOUT 2>&1
     38 RC=$?
     39 if test $RC != 5 ; then
     40 	echo "ldapcompare should have failed ($RC)!"
     41 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     42 	exit 1
     43 fi
     44 
     45 echo "Listing alias attribute specifically..."
     46 echo "# Listing aliased attribute..." >> $SEARCHOUT
     47 $LDAPSEARCH -b "$BASEDN" -H $URI1 "uid=bjensen" mobile \
     48 	>> $SEARCHOUT 2>&1
     49 RC=$?
     50 if test $RC != 0 ; then
     51 	echo "ldapsearch failed ($RC)!"
     52 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     53 	exit $RC
     54 fi
     55 
     56 echo "Not asking for alias attribute..."
     57 echo >> $SEARCHOUT
     58 echo "# A search when aliased attribute is not requested..." >> $SEARCHOUT
     59 $LDAPSEARCH -b "$BASEDN" -H $URI1 "uid=bjensen" pager \
     60 	>> $SEARCHOUT 2>&1
     61 RC=$?
     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 "Retrieving both the aliased attribute and the source..."
     69 echo >> $SEARCHOUT
     70 echo "# A search when both are requested (explicitly)..." >> $SEARCHOUT
     71 $LDAPSEARCH -b "$BASEDN" -H $URI1 "uid=bjensen" mobile pager \
     72 	>> $SEARCHOUT 2>&1
     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 "Retrieving both the aliased attribute and the source..."
     81 echo >> $SEARCHOUT
     82 echo "# A search when both are requested (implicitly)..." >> $SEARCHOUT
     83 $LDAPSEARCH -b "$BASEDN" -H $URI1 "uid=bjensen" \
     84 	>> $SEARCHOUT 2>&1
     85 RC=$?
     86 if test $RC != 0 ; then
     87 	echo "ldapsearch failed ($RC)!"
     88 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     89 	exit $RC
     90 fi
     91 
     92 echo "Testing searches filtering on aliased attributes..."
     93 echo >> $SEARCHOUT
     94 echo "# Testing searches filtering on aliased attributes..." >> $SEARCHOUT
     95 $LDAPSEARCH -b "$BASEDN" -H $URI1 \
     96 	"(|(mobile=+1 313 555 3233)(mobile=*4474)(&(mobile=*)(uid=jdoe)))" \
     97 	mobile \
     98 	>> $SEARCHOUT 2>&1
     99 RC=$?
    100 if test $RC != 0 ; then
    101 	echo "ldapsearch failed ($RC)!"
    102 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    103 	exit $RC
    104 fi
    105 
    106 echo "Reconfiguring alias definition..."
    107 . $CONFFILTER $BACKEND $MONITORDB < data/test003-config.ldif | \
    108 $LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
    109 	>> $TESTOUT 2>&1
    110 RC=$?
    111 if test $RC != 0 ; then
    112 	echo "ldapmodify failed ($RC)!"
    113 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    114 	exit $RC
    115 fi
    116 
    117 echo "Testing searches with new attributes..."
    118 echo >> $SEARCHOUT
    119 echo "# Testing search with new attributes..." >> $SEARCHOUT
    120 $LDAPSEARCH -b "$BASEDN" -H $URI1 \
    121 	"employeetype=*director*" \
    122 	employeetype mobile \
    123 	>> $SEARCHOUT 2>&1
    124 RC=$?
    125 if test $RC != 0 ; then
    126 	echo "ldapsearch failed ($RC)!"
    127 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    128 	exit $RC
    129 fi
    130 
    131 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    132 
    133 LDIF=data/test003-out.ldif
    134 
    135 echo "Filtering ldapsearch results..."
    136 $LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
    137 echo "Filtering expected entries..."
    138 $LDIFFILTER -s e < $LDIF > $LDIFFLT
    139 echo "Comparing filter output..."
    140 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    141 
    142 if test $? != 0 ; then
    143 	echo "Comparison failed"
    144 	exit 1
    145 fi
    146 
    147 echo ">>>>> Test succeeded"
    148 
    149 test $KILLSERVERS != no && wait
    150 
    151 exit 0
    152