Home | History | Annotate | Line # | Download | only in scripts
      1  1.1  christos #! /bin/sh
      2  1.1  christos # $OpenLDAP$
      3  1.1  christos ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4  1.1  christos ##
      5  1.1  christos ## Copyright 1998-2024 The OpenLDAP Foundation.
      6  1.1  christos ## All rights reserved.
      7  1.1  christos ##
      8  1.1  christos ## Redistribution and use in source and binary forms, with or without
      9  1.1  christos ## modification, are permitted only as authorized by the OpenLDAP
     10  1.1  christos ## Public License.
     11  1.1  christos ##
     12  1.1  christos ## A copy of this license is available in the file LICENSE in the
     13  1.1  christos ## top-level directory of the distribution or, alternatively, at
     14  1.1  christos ## <http://www.OpenLDAP.org/license.html>.
     15  1.1  christos 
     16  1.1  christos echo "running defines.sh"
     17  1.1  christos . $SRCDIR/scripts/defines.sh
     18  1.1  christos 
     19  1.1  christos if test $RWM = rwmno ; then
     20  1.1  christos 	echo "rwm (Rewrite/remap) overlay not available, test skipped"
     21  1.1  christos 	exit 0
     22  1.1  christos fi
     23  1.1  christos 
     24  1.1  christos mkdir -p $TESTDIR
     25  1.1  christos 
     26  1.1  christos echo "" >>$TESTOUT
     27  1.1  christos echo "# making a filter from a DN" > $TESTOUT
     28  1.1  christos echo "Testing DN unescaping then escaping for use in a filter..."
     29  1.1  christos for input in \
     30  1.1  christos 	"uid=test\\20\\2c\\31\\\\" \
     31  1.1  christos 	"uid=test,ou=People,dc=example,dc=com" \
     32  1.1  christos 	"cn=test\\00)(uid=test,dc=example,dc=com" \
     33  1.1  christos 	"cn=*" \
     34  1.1  christos 	"cn=*\\\\" \
     35  1.1  christos 	"cn=*\\" \
     36  1.1  christos 	; do
     37  1.1  christos 
     38  1.1  christos 	$TESTWD/../libraries/librewrite/rewrite -f $DATADIR/rewrite.conf \
     39  1.1  christos 		-r testdn2filter "$input" >>$TESTOUT 2>/dev/null
     40  1.1  christos 	if test $? != 0 ; then
     41  1.1  christos 		echo "rewriting failed"
     42  1.1  christos 		exit 1
     43  1.1  christos 	fi
     44  1.1  christos done
     45  1.1  christos 
     46  1.1  christos echo "" >>$TESTOUT
     47  1.1  christos echo "# pasting a DN into a filter" >> $TESTOUT
     48  1.1  christos echo "Testing filter escaping..."
     49  1.1  christos for input in \
     50  1.1  christos 	"uid=test\\20\\31\\\\" \
     51  1.1  christos 	"cn=test)(uid=test,dc=example,dc=com" \
     52  1.1  christos 	"cn=*" \
     53  1.1  christos 	"cn=*\\\\" \
     54  1.1  christos 	"cn=*\\" \
     55  1.1  christos 	; do
     56  1.1  christos 
     57  1.1  christos 	$TESTWD/../libraries/librewrite/rewrite -f $DATADIR/rewrite.conf \
     58  1.1  christos 		-r testdn2dnfilter "$input" >>$TESTOUT 2>/dev/null
     59  1.1  christos 	if test $? != 0 ; then
     60  1.1  christos 		echo "rewriting failed"
     61  1.1  christos 		exit 1
     62  1.1  christos 	fi
     63  1.1  christos done
     64  1.1  christos 
     65  1.1  christos echo "" >>$TESTOUT
     66  1.1  christos echo "# pasting a filter into a DN" >> $TESTOUT
     67  1.1  christos echo "Testing filter unescaping then escaping the value into a DN..."
     68  1.1  christos for input in \
     69  1.1  christos 	"(uid=test)" \
     70  1.1  christos 	"(cn=something ,\\29+\\28 \\2A=)" \
     71  1.1  christos 	"(description=test\\20\\31*)" \
     72  1.1  christos 	"(description=test\\20\\31)" \
     73  1.1  christos 	; do
     74  1.1  christos 
     75  1.1  christos 	$TESTWD/../libraries/librewrite/rewrite -f $DATADIR/rewrite.conf \
     76  1.1  christos 		-r testfilter2dn "$input" >>$TESTOUT 2>/dev/null
     77  1.1  christos 	if test $? != 0 ; then
     78  1.1  christos 		echo "rewriting failed"
     79  1.1  christos 		exit 1
     80  1.1  christos 	fi
     81  1.1  christos done
     82  1.1  christos 
     83  1.1  christos $CMP $DATADIR/rewrite.out $TESTOUT > $CMPOUT
     84  1.1  christos 
     85  1.1  christos if test $? != 0 ; then
     86  1.1  christos 	echo "comparison failed - rewriting did not complete correctly"
     87  1.1  christos 	exit 1
     88  1.1  christos fi
     89  1.1  christos 
     90  1.1  christos echo ">>>>> Test succeeded"
     91  1.1  christos exit 0
     92