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 if test $RWM = rwmno ; then 20 echo "rwm (Rewrite/remap) overlay not available, test skipped" 21 exit 0 22 fi 23 24 mkdir -p $TESTDIR 25 26 echo "" >>$TESTOUT 27 echo "# making a filter from a DN" > $TESTOUT 28 echo "Testing DN unescaping then escaping for use in a filter..." 29 for input in \ 30 "uid=test\\20\\2c\\31\\\\" \ 31 "uid=test,ou=People,dc=example,dc=com" \ 32 "cn=test\\00)(uid=test,dc=example,dc=com" \ 33 "cn=*" \ 34 "cn=*\\\\" \ 35 "cn=*\\" \ 36 ; do 37 38 $TESTWD/../libraries/librewrite/rewrite -f $DATADIR/rewrite.conf \ 39 -r testdn2filter "$input" >>$TESTOUT 2>/dev/null 40 if test $? != 0 ; then 41 echo "rewriting failed" 42 exit 1 43 fi 44 done 45 46 echo "" >>$TESTOUT 47 echo "# pasting a DN into a filter" >> $TESTOUT 48 echo "Testing filter escaping..." 49 for input in \ 50 "uid=test\\20\\31\\\\" \ 51 "cn=test)(uid=test,dc=example,dc=com" \ 52 "cn=*" \ 53 "cn=*\\\\" \ 54 "cn=*\\" \ 55 ; do 56 57 $TESTWD/../libraries/librewrite/rewrite -f $DATADIR/rewrite.conf \ 58 -r testdn2dnfilter "$input" >>$TESTOUT 2>/dev/null 59 if test $? != 0 ; then 60 echo "rewriting failed" 61 exit 1 62 fi 63 done 64 65 echo "" >>$TESTOUT 66 echo "# pasting a filter into a DN" >> $TESTOUT 67 echo "Testing filter unescaping then escaping the value into a DN..." 68 for input in \ 69 "(uid=test)" \ 70 "(cn=something ,\\29+\\28 \\2A=)" \ 71 "(description=test\\20\\31*)" \ 72 "(description=test\\20\\31)" \ 73 ; do 74 75 $TESTWD/../libraries/librewrite/rewrite -f $DATADIR/rewrite.conf \ 76 -r testfilter2dn "$input" >>$TESTOUT 2>/dev/null 77 if test $? != 0 ; then 78 echo "rewriting failed" 79 exit 1 80 fi 81 done 82 83 $CMP $DATADIR/rewrite.out $TESTOUT > $CMPOUT 84 85 if test $? != 0 ; then 86 echo "comparison failed - rewriting did not complete correctly" 87 exit 1 88 fi 89 90 echo ">>>>> Test succeeded" 91 exit 0 92