| 1 | #! /bin/sh |
| 2 | # |
| 3 | # Test for namazu.cgi. |
| 4 | # Check whether `<', `>', and/or `"' in a query are escaped correctly. |
| 5 | # They should be escaped not printed in unescaped. |
| 6 | # |
| 7 | LOG=`pwd`/test-log |
| 8 | pwd=`pwd` |
| 9 | echo ' *** starting ' $0 >>$LOG |
| 10 | . ${srcdir}/commonfuncs |
| 11 | |
| 12 | tmprc="$pwd/../src/.namazurc" |
| 13 | echo "Index $pwd" > $tmprc |
| 14 | echo "Template $pwd/idx1" >> $tmprc |
| 15 | duprcs |
| 16 | |
| 17 | cd ../src |
| 18 | SCRIPT_NAME='namazu.cgi' |
| 19 | |
| 20 | for query in '%3C' '%3E' '%3C%3E' '%3E%3C' '%26' '%22' '%3C%22%26%3E' \ |
| 21 | '<' '>' '<>' '><' # '&' '"' '<"&>' \ |
| 22 | do |
| 23 | QUERY_STRING="query=$query&idxname=idx1" |
| 24 | export SCRIPT_NAME QUERY_STRING |
| 25 | echo query: $query >> $LOG |
| 26 | output=`./namazu.cgi | \ |
| 27 | perl -nle 'print $1 if /<title>.+?<(.+?)><\/title>/i; \ |
| 28 | print $1 if /<input type="text" name="query" size="40" value="(.+?)">/i'|\ |
| 29 | uniq -d` # two output should be same. |
| 30 | echo output: $output >> $LOG |
| 31 | |
| 32 | # Error if output contains [<>"]. |
| 33 | echo $output | perl -ne 'exit 1 if /[<>"]/' || exit 1 |
| 34 | |
| 35 | # Normalize. |
| 36 | query=`echo $query | perl -ple 's/%(..)/pack("c",hex($1))/eg'` |
| 37 | output=`echo $output | perl -ple 's/"/"/g; \ |
| 38 | s/&/&/g; \ |
| 39 | s/</</g; \ |
| 40 | s/>/>/g;'` |
| 41 | |
| 42 | echo $query, $output >> $LOG |
| 43 | test "$query" != "$output" && exit 1 # error if not equal |
| 44 | done |
| 45 | |
| 46 | exit 0 |