From 780b4028fe26632f55ea0e05ddcd082cc38c5f34 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Wed, 23 Jul 2008 20:56:48 +0200 Subject: [PATCH] improved test.sh script --- CHANGES | 2 + test.sh | 321 ++++++++++++++++++++++++++++++-------------------------- 2 files changed, 173 insertions(+), 150 deletions(-) diff --git a/CHANGES b/CHANGES index 4dcb9c8..93b8802 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ corrections: additional empty arguments (thanks to Olivier Hervieu for reporting this bug) + improved test.sh script + ####################### V 1.6.0.1: new features: diff --git a/test.sh b/test.sh index 29d5359..5846503 100755 --- a/test.sh +++ b/test.sh @@ -207,6 +207,7 @@ $SOCAT -? |sed '1,/address-head:/ d' |egrep 'groups=' |while IFS="$IFS:" read x if [ -s "$TF-diff" ]; then $ECHO "\n*** address array is not sorted. Wrong entries:" >&2 cat "$TD/socat-q-diff" >&2 + exit 1 else echo " ok" fi @@ -219,11 +220,12 @@ case "$TESTS" in # test if address options array ("optionnames") is sorted alphabetically: $ECHO "testing if address options are sorted...\c" TF="$TD/socat-qq" -$SOCAT -??? |sed '1,/opt:/ d' |egrep 'groups=' |awk '{print($1);}' >"$TF" -$SOCAT -??? |sed '1,/opt:/ d' |egrep 'groups=' |awk '{print($1);}' |LC_ALL=C sort |diff "$TF" - >"$TF-diff" +$SOCAT -??? |sed '1,/opt:/ d' |awk '{print($1);}' >"$TF" +LC_ALL=C sort "$TF" |diff "$TF" - >"$TF-diff" if [ -s "$TF-diff" ]; then $ECHO "\n*** option array is not sorted. Wrong entries:" >&2 cat "$TD/socat-qq-diff" >&2 + exit 1 else echo " ok" fi @@ -457,7 +459,7 @@ N=1 #TEST="$METHOD on file accepts all its options" # echo "### $TEST" #TF=$TD/file$N -#DA="$(date)" +#DA="test$N $(date) $RANDOM" #OPTGROUPS=$($SOCAT -? |fgrep " $method:" |sed 's/.*=//') #for g in $(echo $OPTGROUPS |tr ',' ' '); do # eval "OPTG=\$OPTS_$(echo $g |tr a-z- A-Z_)"; @@ -1420,7 +1422,7 @@ numCANT=0 # test if selected socat features work ("FUNCTIONS") testecho () { - local num="$1" + local N="$1" local title="$2" local arg1="$3"; [ -z "$arg1" ] && arg1="-" local arg2="$4"; [ -z "$arg2" ] && arg2="echo" @@ -1429,10 +1431,10 @@ testecho () { local tf="$td/test$N.stdout" local te="$td/test$N.stderr" local tdiff="$td/test$N.diff" - local da="$(date)" + local da="test$N $(date) $RANDOM" #local cmd="$SOCAT $opts $arg1 $arg2" - #$ECHO "testing $title (test $num)... \c" - $PRINTF "test $F_n %s... " $num "$title" + #$ECHO "testing $title (test $N)... \c" + $PRINTF "test $F_n %s... " $N "$title" #echo "$da" |$cmd >"$tf" 2>"$te" (echo "$da"; sleep $T) |($SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te"; echo $? >"$td/test$N.rc") & export rc1=$! @@ -1471,7 +1473,7 @@ testod () { local tf="$td/test$N.stdout" local te="$td/test$N.stderr" local tdiff="$td/test$N.diff" - local dain="$(date)" + local dain="$(date) $RANDOM" local daout="$(echo "$dain" |$OD_C)" $PRINTF "test $F_n %s... " $num "$title" (echo "$dain"; sleep $T) |$SOCAT $opts "$arg1" "$arg2" >"$tf" 2>"$te" @@ -1643,7 +1645,7 @@ waitip4proto () { while [ $timeout -gt 0 ]; do case "$UNAME" in Linux) l=$(netstat -n -w -l |grep '^raw .* .*[0-9*]:'$proto' [ ]*0\.0\.0\.0:\*') ;; -# FreeBSD) l=$(netstat -an |grep '^raw4[6 ] .*[0-9*]\.'$proto' .* \*\.\*') ;; +# FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;; # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;; # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;; # Darwin) case "$(uname -r)" in @@ -1683,8 +1685,8 @@ waitip6proto () { [ "$timeout" ] || timeout=5 while [ $timeout -gt 0 ]; do case "$UNAME" in - Linux) l=$(netstat -n -w -l |grep '^raw .* .*:[0-9*]*:'$proto' [ ]*:::\*') ;; -# FreeBSD) l=$(netstat -an |grep '^raw4[6 ] .*[0-9*]\.'$proto' .* \*\.\*') ;; + Linux) l=$(netstat -n -w -l |grep '^raw[6 ] .* .*:[0-9*]*:'$proto' [ ]*:::\*') ;; +# FreeBSD) l=$(netstat -an |egrep '^raw46? .*[0-9*]\.'$proto' .* \*\.\*') ;; # NetBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;; # OpenBSD) l=$(netstat -an |grep '^raw .*[0-9*]\.'$proto' [ ]* \*\.\*') ;; # Darwin) case "$(uname -r)" in @@ -1696,7 +1698,7 @@ waitip6proto () { # SunOS) l=$(netstat -an -f inet -P raw |grep '.*[1-9*]\.'$proto' [ ]*Idle') ;; # HP-UX) l=$(netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' .* \*\.\* ') ;; # OSF1) l=$(/usr/sbin/netstat -an |grep '^raw 0 0 .*[0-9*]\.'$proto' [ ]*\*\.\*') ;; - *) #l=$(netstat -an |grep -i 'raw .*[0-9*][:.]'$proto' ') ;; + *) #l=$(netstat -an |egrep -i 'raw6? .*[0-9*][:.]'$proto' ') ;; sleep 1; return 0 ;; esac [ \( \( $logic -ne 0 \) -a -n "$l" \) -o \ @@ -1714,6 +1716,30 @@ waitip6port () { waitip6proto "$1" "$2" "$3" } +# check if a TCP4 port is in use +# exits with 0 when it is not used +checktcp4port () { + local port="$1" + local l + case "$UNAME" in + Linux) l=$(netstat -n -t |grep '^tcp .* .*[0-9*]:'$port' .* LISTEN') ;; + FreeBSD) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;; + NetBSD) l=$(netstat -an |grep '^tcp .* .*[0-9*]\.'$port' [ ]* \*\.\* [ ]* LISTEN.*') ;; + Darwin) case "$(uname -r)" in + [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;; + *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;; + esac ;; + AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;; + SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;; + HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;; + OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;; + CYGWIN*) l=$(netstat -an -p TCP |grep '^ TCP [0-9.]*:'$port' .* LISTENING') ;; + *) l=$(netstat -an |grep -i 'tcp .*[0-9*][:.]'$port' .* listen') ;; + esac + [ -z "$l" ] && return 0 + return 1 +} + # wait until a TCP4 listen port is ready waittcp4port () { local port="$1" @@ -1731,7 +1757,7 @@ waittcp4port () { [1-5]*) l=$(netstat -an |grep '^tcp.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;; *) l=$(netstat -an |grep '^tcp4.* .*[0-9*]\.'$port' .* \*\.\* .* LISTEN') ;; esac ;; - AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;; + AIX) l=$(netstat -an |grep '^tcp[^6] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;; SunOS) l=$(netstat -an -f inet -P tcp |grep '.*[1-9*]\.'$port' .*\* 0 .* LISTEN') ;; HP-UX) l=$(netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' .* LISTEN$') ;; OSF1) l=$(/usr/sbin/netstat -an |grep '^tcp 0 0 .*[0-9*]\.'$port' [ ]*\*\.\* [ ]*LISTEN') ;; @@ -1759,7 +1785,7 @@ waitudp4port () { while [ $timeout -gt 0 ]; do case "$UNAME" in Linux) l=$(netstat -n -u -l |grep '^udp .* .*[0-9*]:'$port' [ ]*0\.0\.0\.0:\*') ;; - FreeBSD) l=$(netstat -an |grep '^udp4[6 ] .*[0-9*]\.'$port' .* \*\.\*') ;; + FreeBSD) l=$(netstat -an |egrep '^udp46? .*[0-9*]\.'$port' .* \*\.\*') ;; NetBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;; OpenBSD) l=$(netstat -an |grep '^udp .*[0-9*]\.'$port' [ ]* \*\.\*') ;; Darwin) case "$(uname -r)" in @@ -1792,8 +1818,8 @@ waittcp6port () { [ "$timeout" ] || timeout=5 while [ $timeout -gt 0 ]; do case "$UNAME" in - Linux) l=$(netstat -an |grep '^tcp[6 ] .* [0-9a-f:]*:'$port' .* LISTEN') ;; - FreeBSD) l=$(netstat -an |grep -i 'tcp[46][6 ] .*[0-9*][:.]'$port' .* listen') ;; + Linux) l=$(netstat -an |grep -E '^tcp6? .* [0-9a-f:]*:'$port' .* LISTEN') ;; + FreeBSD) l=$(netstat -an |egrep -i 'tcp(6|46) .*[0-9*][:.]'$port' .* listen') ;; NetBSD) l=$(netstat -an |grep '^tcp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;; OpenBSD) l=$(netstat -an |grep -i 'tcp6 .*[0-9*][:.]'$port' .* listen') ;; AIX) l=$(netstat -an |grep '^tcp[6 ] 0 0 .*[*0-9]\.'$port' .* LISTEN$') ;; @@ -1821,7 +1847,7 @@ waitudp6port () { [ "$timeout" ] || timeout=5 while [ $timeout -gt 0 ]; do case "$UNAME" in - Linux) l=$(netstat -an |grep '^udp[6 ] .* .*[0-9*:]:'$port' [ ]*:::\*') ;; + Linux) l=$(netstat -an |grep -E '^udp6? .* .*[0-9*:]:'$port' [ ]*:::\*') ;; FreeBSD) l=$(netstat -an |egrep '^udp(6|46) .*[0-9*]\.'$port' .* \*\.\*') ;; NetBSD) l=$(netstat -an |grep '^udp6 .* \*\.'$port' [ ]* \*\.\*') ;; OpenBSD) l=$(netstat -an |grep '^udp6 .*[0-9*]\.'$port' [ ]* \*\.\*') ;; @@ -2303,7 +2329,7 @@ tf="$td/test$N.stdout" te="$td/test$N.stderr" ts="$td/test$N.socket" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UNIX-LISTEN:$ts PIPE" CMD2="$SOCAT $opts -!!- UNIX:$ts" printf "test $F_n $TEST... " $N @@ -2340,7 +2366,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -2384,7 +2410,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="[::1]:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP6-listen:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP6:$ts" printf "test $F_n $TEST... " $N @@ -2430,7 +2456,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP-listen:$tsl,pf=ip4,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP:$ts" printf "test $F_n $TEST... " $N @@ -2476,7 +2502,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="[::1]:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP-listen:$tsl,pf=ip6,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP:$ts" printf "test $F_n $TEST... " $N @@ -2524,7 +2550,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=0,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -2572,7 +2598,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP6-listen:$tsl,ipv6-v6only=1,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -2617,7 +2643,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP-listen:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -2662,7 +2688,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="[::1]:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP-listen:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP6:$ts" printf "test $F_n $TEST... " $N @@ -2710,7 +2736,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -4 TCP-listen:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -2755,7 +2781,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="[::1]:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -6 TCP-listen:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP6:$ts" printf "test $F_n $TEST... " $N @@ -2804,7 +2830,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -6 TCP-listen:$tsl,pf=ip4,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -2849,7 +2875,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="[::1]:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -4 TCP-listen:$tsl,pf=ip6,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP6:$ts" printf "test $F_n $TEST... " $N @@ -2888,7 +2914,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="$LOCALHOST:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UDP4-LISTEN:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts - UDP4:$ts" printf "test $F_n $TEST... " $N @@ -2935,7 +2961,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="$LOCALHOST6:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UDP6-LISTEN:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts - UDP6:$ts" printf "test $F_n $TEST... " $N @@ -2974,7 +3000,7 @@ tf1="$td/test$N.1.stdout" tf2="$td/test$N.2.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" echo "$da" >$tf1 CMD="$SOCAT $opts $tf1!!/dev/null /dev/null,ignoreeof!!-" printf "test $F_n $TEST... " $N @@ -3005,7 +3031,7 @@ tp="$td/pipe$N" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD="$SOCAT $opts $tp!!/dev/null /dev/null,ignoreeof!!$tf" printf "test $F_n $TEST... " $N #mknod $tp p # no mknod p on FreeBSD @@ -3145,7 +3171,7 @@ ti="$td/test$N.file" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" CMD="$SOCAT $opts -u file:\"$ti\",ignoreeof -" printf "test $F_n $TEST... " $N touch "$ti" @@ -3211,7 +3237,7 @@ tt="$td/pty$N" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts pty,link=$tt pipe" CMD2="$SOCAT $opts - $tt,$PTYOPTS2" printf "test $F_n $TEST... " $N @@ -3252,7 +3278,7 @@ ff="$td/test$N.file" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD="$SOCAT -u $opts - open:$ff,append,o-trunc" printf "test $F_n $TEST... " $N rm -f $ff; $ECHO "prefix-\c" >$ff @@ -3280,7 +3306,7 @@ ff="$td/test$N.file" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD="$SOCAT -u $opts - open:$ff,append,ftruncate=0" printf "test $F_n $TEST... " $N rm -f $ff; $ECHO "prefix-\c" >$ff @@ -3416,13 +3442,14 @@ gentestcert testsrv tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts exec:'openssl s_server -accept "$PORT" -quiet -cert testsrv.pem' pipe" #! CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT" CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD" printf "test $F_n $TEST... " $N eval "$CMD2 2>\"${te}1\" &" pid=$! # background process id +# this might timeout when openssl opens tcp46 port like " :::$PORT" waittcp4port $PORT echo "$da" |$CMD >$tf 2>"${te}2" if ! echo "$da" |diff - "$tf" >"$tdiff"; then @@ -3461,7 +3488,7 @@ gentestcert testsrv tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe" CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD" printf "test $F_n $TEST... " $N @@ -3504,7 +3531,7 @@ gentestcert testsrv tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip6,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe" CMD="$SOCAT $opts - openssl:$LOCALHOST6:$PORT,verify=0,$SOCAT_EGD" printf "test $F_n $TEST... " $N @@ -3550,7 +3577,7 @@ gentestcert testsrv tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 exec:'$OD_C'" CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,$SOCAT_EGD" printf "test $F_n $TEST... " $N @@ -3595,7 +3622,7 @@ gentestcert testcli tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,$SOCAT_EGD,cert=testsrv.crt,key=testsrv.key,verify=0 pipe" CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=1,cafile=testsrv.crt,$SOCAT_EGD" printf "test $F_n $TEST... " $N @@ -3639,7 +3666,7 @@ gentestcert testcli tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,verify=1,cert=testsrv.crt,key=testsrv.key,cafile=testcli.crt,$SOCAT_EGD pipe" CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT,verify=0,cert=testcli.crt,key=testcli.key,$SOCAT_EGD" printf "test $F_n $TEST... " $N @@ -3686,7 +3713,7 @@ OPENSSL_FIPS=1 gentestcert testclifips tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts OPENSSL-LISTEN:$PORT,reuseaddr,fips,$SOCAT_EGD,cert=testsrvfips.crt,key=testsrvfips.key,cafile=testclifips.crt pipe" CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT,fips,verify=1,cert=testclifips.crt,key=testclifips.key,cafile=testsrvfips.crt,$SOCAT_EGD" printf "test $F_n $TEST... " $N @@ -3729,7 +3756,7 @@ else tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" # we have a normal tcp echo listening - so the socks header must appear in answer CMD2="$SOCAT tcp4-l:$PORT,reuseaddr exec:\"./socks4echo.sh\"" CMD="$SOCAT $opts - socks4:$LOCALHOST:32.98.76.54:32109,pf=ip4,socksport=$PORT",socksuser="nobody" @@ -3772,7 +3799,7 @@ else tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" # we have a normal tcp echo listening - so the socks header must appear in answer CMD2="$SOCAT tcp6-l:$PORT,reuseaddr exec:\"./socks4echo.sh\"" CMD="$SOCAT $opts - socks4:$LOCALHOST6:32.98.76.54:32109,socksport=$PORT",socksuser="nobody" @@ -3816,7 +3843,7 @@ else tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" # we have a normal tcp echo listening - so the socks header must appear in answer CMD2="$SOCAT tcp4-l:$PORT,reuseaddr exec:\"./socks4a-echo.sh\"" CMD="$SOCAT $opts - socks4a:$LOCALHOST:localhost:32109,pf=ip4,socksport=$PORT",socksuser="nobody" @@ -3859,7 +3886,7 @@ else tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" # we have a normal tcp echo listening - so the socks header must appear in answer CMD2="$SOCAT tcp6-l:$PORT,reuseaddr exec:\"./socks4a-echo.sh\"" CMD="$SOCAT $opts - socks4a:$LOCALHOST6:localhost:32109,socksport=$PORT",socksuser="nobody" @@ -3904,7 +3931,7 @@ ts="$td/test$N.sh" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" #CMD2="$SOCAT tcp4-l:$PORT,crlf system:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\"" CMD2="$SOCAT tcp4-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh\"" CMD="$SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT" @@ -3948,7 +3975,7 @@ ts="$td/test$N.sh" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" #CMD2="$SOCAT tcp6-l:$PORT,crlf system:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\"" CMD2="$SOCAT tcp6-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh\"" CMD="$SOCAT $opts - proxy:$LOCALHOST6:127.0.0.1:1000,proxyport=$PORT" @@ -3987,7 +4014,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr exec:$CAT,nofork" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -4048,7 +4075,7 @@ N=$((N+1)) #tf="$td/file$N" #tsl=65534 #ts="127.0.0.1:$tsl" -#da=$(date) +#da="test$N $(date) $RANDOM" #$SOCAT UDP-listen:$tsl PIPE & #sleep 2 #echo "$da" |$SOCAT stdin!!stdout UDP:$ts >"$tf" @@ -4065,7 +4092,7 @@ N=$((N+1)) #N=4 #tf="$td/file$N" #tp="$td/pipe$N" -#da=$(date) +#da="test$N $(date) $RANDOM" #rm -f "$tf.tmp" #echo "$da" |$SOCAT - FILE:$tf.tmp,ignoreeof >"$tf" #if [ $? -eq 0 ] && echo "$da" |diff "$tf" -; then @@ -4089,7 +4116,7 @@ else tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" CMD2="$SOCAT $opts -T 1 tcp4-listen:$PORT,reuseaddr pipe" CMD="$SOCAT $opts - tcp4-connect:$LOCALHOST:$PORT" printf "test $F_n $TEST... " $N @@ -4131,7 +4158,7 @@ ti="$td/test$N.file" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" CMD="$SOCAT $opts -T 2 -u file:\"$ti\",ignoreeof -" printf "test $F_n $TEST... " $N touch "$ti" @@ -4172,7 +4199,7 @@ ts="$td/test$N.sh" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" #CMD2="$SOCAT tcp-l:$PORT,crlf system:\"read; read; $ECHO \\\"HTTP/1.0 200 OK\n\\\"; cat\"" CMD2="$SOCAT tcp4-l:$PORT,reuseaddr,crlf exec:\"/bin/bash proxyecho.sh -w 2\"" CMD="$SOCAT $opts - proxy:$LOCALHOST:127.0.0.1:1000,pf=ip4,proxyport=$PORT" @@ -4313,6 +4340,7 @@ if ! feat=$(testaddrs readline pty); then $PRINTF "test $F_n $TEST... ${YELLOW}$(echo $feat| tr 'a-z' 'A-Z') not available${NORMAL}\n" $N numCANT=$((numCANT+1)) else +SAVETERM="$TERM"; TERM= # 'cause konsole might print controls even in raw SAVEMICS=$MICROS #MICROS=2000000 ts="$td/test$N.sh" @@ -4322,7 +4350,7 @@ tpo="$td/test$N.outpipe" te="$td/test$N.stderr" tr="$td/test$N.ref" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" # the feature that we really want to test is in the readline.sh script: CMD="$SOCAT $opts open:$tpi,nonblock!!open:$tpo exec:\"./readline.sh -nh ./readline-test.sh\",pty,ctty,setsid,raw,echo=0,isig" #echo "$CMD" >"$ts" @@ -4397,6 +4425,7 @@ else fi #kill $pid 2>/dev/null MICROS=$SAVEMICS +TERM="$SAVETERM" fi esac PORT=$((PORT+1)) @@ -4410,7 +4439,7 @@ TEST="$NAME: TCP4 \"gender changer\"" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" # this is the server in the protected network that we want to reach CMD1="$SOCAT -lpserver $opts tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo" # this is the double client in the protected network @@ -4467,7 +4496,7 @@ gentestcert testcli tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" # this is the server in the protected network that we want to reach CMD1="$SOCAT $opts -lpserver tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST echo" # this is the proxy in the protected network that provides a way out @@ -4529,7 +4558,13 @@ PORT=$((PORT+5)) N=$((N+1)) -#! +# test the TCP gender changer with almost production requirements: a double +# client repeatedly tries to connect to a double server via SSL through an HTTP +# proxy. the double servers SSL port becomes active for one connection only +# after a (real) client has connected to its TCP port. when the double client +# succeeded to establish an SSL connection, it connects with its second client +# side to the specified (protected) server. all three consecutive connections +# must function for full success of this test. PORT=$((RANDOM+16184)) #! NAME=INTRANETRIPPER @@ -4551,15 +4586,17 @@ da3="test$N.3 $(date) $RANDOM" # this is the server in the protected network that we want to reach CMD1="$SOCAT $opts -lpserver -t1 tcp4-l:$PORT,reuseaddr,bind=$LOCALHOST,fork echo" # this is the proxy in the protected network that provides a way out +# note: the proxy.sh script starts one or two more socat processes without +# setting the program name CMD2="$SOCAT $opts -lpproxy -t1 tcp4-l:$((PORT+1)),reuseaddr,bind=$LOCALHOST,fork exec:./proxy.sh" # this is our proxy connect wrapper in the protected network CMD3="$SOCAT $opts -lpwrapper -t3 tcp4-l:$((PORT+2)),reuseaddr,bind=$LOCALHOST,fork proxy:$LOCALHOST:$LOCALHOST:$((PORT+3)),pf=ip4,proxyport=$((PORT+1)),resolve" # this is our double client in the protected network using SSL -CMD4="$SOCAT $opts -lp2client -t3 ssl:$LOCALHOST:$((PORT+2)),retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,verify,fork,$SOCAT_EGD tcp4:$LOCALHOST:$PORT" +CMD4="$SOCAT $opts -lp2client -t3 ssl:$LOCALHOST:$((PORT+2)),retry=10,interval=1,cert=testcli.pem,cafile=testsrv.crt,verify,fork,$SOCAT_EGD tcp4:$LOCALHOST:$PORT,forever,intervall=0.1" # this is the double server in the outside network -CMD5="$SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,fork ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt,retry=10" +CMD5="$SOCAT $opts -lp2server -t4 tcp4-l:$((PORT+4)),reuseaddr,bind=$LOCALHOST,backlog=3,fork ssl-l:$((PORT+3)),pf=ip4,reuseaddr,bind=$LOCALHOST,$SOCAT_EGD,cert=testsrv.pem,cafile=testcli.crt,retry=20,intervall=0.5" # this is the outside client that wants to use the protected server -CMD6="$SOCAT $opts -lpclient -t5 - tcp4:$LOCALHOST:$((PORT+4)),retry=3" +CMD6="$SOCAT $opts -lpclient -t6 - tcp4:$LOCALHOST:$((PORT+4)),retry=3" printf "test $F_n $TEST... " $N # start the intranet infrastructure eval "$CMD1 2>\"${te}1\" &" @@ -4591,6 +4628,8 @@ wait $pid6_1 $pid6_2 $pid6_3 (echo "$da2"; sleep 2) |diff - "${tf}_2" >"${tdiff}2" (echo "$da3"; sleep 2) |diff - "${tf}_3" >"${tdiff}3" if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then + # FAILED only when none of the three transfers succeeded + if test -s "${tdiff}1" -a -s "${tdiff}2" -a -s "${tdiff}3"; then $PRINTF "$FAILED: $SOCAT:\n" echo "$CMD1 &" cat "${te}1" @@ -4612,6 +4651,11 @@ if test -s "${tdiff}1" -o -s "${tdiff}2" -o -s "${tdiff}3"; then cat "${te}6_3" cat "${tdiff}3" numFAIL=$((numFAIL+1)) + else + $PRINTF "$OK ${YELLOW}(partial failure)${NORMAL}\n" + if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi + numOK=$((numOK+1)) + fi else $PRINTF "$OK\n" if [ -n "$debug" ]; then cat "${te}1" "${te}2" "${te}3" "${te}4" "${te}5" ${te}6*; fi @@ -4631,7 +4675,7 @@ N=$((N+1)) # test the security features of a server address testserversec () { - local num="$1" + local N="$1" local title="$2" local opts="$3" local arg1="$4" # the server address @@ -4647,10 +4691,10 @@ testserversec () { local te="$td/test$N.stderr" local tdiff1="$td/test$N.diff1" local tdiff2="$td/test$N.diff2" - local da="$(date)" + local da="test$N.1 $(date) $RANDOM" local stat result - $PRINTF "test $F_n %s... " $num "$title" + $PRINTF "test $F_n %s... " $N "$title" #set -vx # first: without security # start server @@ -4718,6 +4762,7 @@ testserversec () { return fi # now use client + da="test$N.2 $(date) $RANDOM" (echo "$da"; sleep $T) |$SOCAT $opts - "$arg2" >"$tf" 2>"${te}4" stat=$? kill $spid 2>/dev/null @@ -5289,15 +5334,15 @@ testptywaitslave () { local PTYTYPE="$3" # ptmx or openpty local opts="$4" -tp="$td/test$N.pty" -ts="$td/test$N.socket" -tf="$td/test$N.file" -tdiff="$td/test$N.diff" -te1="$td/test$N.stderr1" -te2="$td/test$N.stderr2" -te3="$td/test$N.stderr3" -te4="$td/test$N.stderr4" -da="test$N.1 $(date) $RANDOM" + local tp="$td/test$N.pty" + local ts="$td/test$N.socket" + local tf="$td/test$N.file" + local tdiff="$td/test$N.diff" + local te1="$td/test$N.stderr1" + local te2="$td/test$N.stderr2" + local te3="$td/test$N.stderr3" + local te4="$td/test$N.stderr4" + local da="test$N $(date) $RANDOM" printf "test $F_n $TEST... " $N # first generate a pty, then a socket ($SOCAT $opts -lpsocat1 pty,$PTYTYPE,pty-wait-slave,link="$tp" unix-listen:"$ts" 2>"$te1"; rm -f "$tp") 2>/dev/null & @@ -5429,7 +5474,7 @@ gentestdsacert $SRVCERT tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" CMD2="$SOCAT $opts OPENSSL-LISTEN:$PORT,pf=ip4,reuseaddr,$SOCAT_EGD,cert=$SRVCERT.pem,key=$SRVCERT.key,verify=0 pipe" CMD="$SOCAT $opts - openssl:$LOCALHOST:$PORT,pf=ip4,verify=0,$SOCAT_EGD" $PRINTF "test $F_n $TEST... " $N @@ -5533,7 +5578,7 @@ ti="$td/test$N.in" to="$td/test$N.out" te="$td/test$N.err" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" # the feature that we really want to test is in the readline.sh script: CMD="$SOCAT $opts -u open:$ti,readbytes=100 -" printf "test $F_n $TEST... " $N @@ -5718,7 +5763,11 @@ NAME=EXECPIPESSTDERR case "$TESTS" in *%functions%*|*%$NAME%*) TEST="$NAME: simple echo via exec of cat with pipes,stderr" +# this test is known to fail when logging is enabled with OPTS/opts env var. +SAVE_opts="$opts" +opts="$(echo "$opts" |sed 's/-d//g')" testecho "$N" "$TEST" "" "exec:$CAT,pipes,stderr" "$opts" +opts="$SAVE_opts" esac N=$((N+1)) @@ -5813,7 +5862,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="127.0.0.1:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP6-listen:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP6:$ts" printf "test $F_n $TEST... " $N @@ -5856,7 +5905,7 @@ ts1a="127.0.0.1" ts1="$ts1a:$ts1p" ts2p=$PORT; PORT=$((PORT+1)) ts2="127.0.0.1:$ts2p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE" CMD2="$SOCAT $opts - UDP4-SENDTO:$ts1,bind=$ts2" printf "test $F_n $TEST... " $N @@ -5907,7 +5956,7 @@ tsa="[::1]" ts1="$tsa:$ts1p" ts2p=$PORT; PORT=$((PORT+1)) ts2="$tsa:$ts2p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UDP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE" CMD2="$SOCAT $opts - UDP6-SENDTO:$ts1,bind=$ts2" printf "test $F_n $TEST... " $N @@ -5952,7 +6001,7 @@ ts1a="127.0.0.1" ts1="$ts1a:$ts1p" ts2a="$SECONDADDR" ts2="$ts2a:$ts2p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,bind=$ts1a PIPE" CMD2="$SOCAT $opts - IP4-SENDTO:$ts1,bind=$ts2a" printf "test $F_n $TEST... " $N @@ -5980,7 +6029,6 @@ else fi fi # must be root;; esac -PORT=$((PORT+1)) N=$((N+1)) @@ -6003,7 +6051,7 @@ ts1p=$PROTO; PROTO=$((PROTO+1)) tsa="[::1]" ts1="$tsa:$ts1p" ts2="$tsa" -da=$(date) +da="test$N $(date) $RANDOM" #CMD1="$SOCAT $opts IP6-RECVFROM:$ts1p,reuseaddr,bind=$tsa PIPE" CMD2="$SOCAT $opts - IP6-SENDTO:$ts1,bind=$ts2" printf "test $F_n $TEST... " $N @@ -6028,7 +6076,6 @@ else fi fi # must be root ;; esac -PORT=$((PORT+1)) N=$((N+1)) fi #false @@ -6042,7 +6089,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" ts1="$td/test$N.socket1" ts2="$td/test$N.socket2" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UNIX-RECVFROM:$ts1,reuseaddr PIPE" CMD2="$SOCAT $opts - UNIX-SENDTO:$ts1,bind=$ts2" printf "test $F_n $TEST... " $N @@ -6069,7 +6116,6 @@ else numOK=$((numOK+1)) fi ;; esac -PORT=$((PORT+1)) N=$((N+1)) @@ -6083,7 +6129,7 @@ tdiff="$td/test$N.diff" ts1p=$PORT; PORT=$((PORT+1)) ts1a="127.0.0.1" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -u UDP4-RECV:$ts1p,reuseaddr -" CMD2="$SOCAT $opts -u - UDP4-SENDTO:$ts1" printf "test $F_n $TEST... " $N @@ -6116,7 +6162,6 @@ else numOK=$((numOK+1)) fi ;; esac -PORT=$((PORT+1)) N=$((N+1)) @@ -6134,7 +6179,7 @@ tdiff="$td/test$N.diff" ts1p=$PORT; PORT=$((PORT+1)) ts1a="[::1]" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -u UDP6-RECV:$ts1p,reuseaddr -" CMD2="$SOCAT $opts -u - UDP6-SENDTO:$ts1" printf "test $F_n $TEST... " $N @@ -6164,7 +6209,6 @@ else fi fi ;; # ! feat esac -PORT=$((PORT+1)) N=$((N+1)) @@ -6182,7 +6226,7 @@ tdiff="$td/test$N.diff" ts1p=$PROTO; PROTO=$((PROTO+1)) ts1a="127.0.0.1" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -u IP4-RECV:$ts1p,reuseaddr -" CMD2="$SOCAT $opts -u - IP4-SENDTO:$ts1" printf "test $F_n $TEST... " $N @@ -6212,7 +6256,6 @@ else fi fi # must be root ;; esac -PORT=$((PORT+1)) N=$((N+1)) @@ -6233,7 +6276,7 @@ tdiff="$td/test$N.diff" ts1p=$PROTO; PROTO=$((PROTO+1)) ts1a="[::1]" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -u IP6-RECV:$ts1p,reuseaddr -" CMD2="$SOCAT $opts -u - IP6-SENDTO:$ts1" printf "test $F_n $TEST... " $N @@ -6262,7 +6305,6 @@ else fi fi # must be root ;; esac -PORT=$((PORT+1)) N=$((N+1)) @@ -6275,7 +6317,7 @@ tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" ts1="$ts" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -u UNIX-RECV:$ts1,reuseaddr -" CMD2="$SOCAT $opts -u - UNIX-SENDTO:$ts1" printf "test $F_n $TEST... " $N @@ -6303,7 +6345,6 @@ else numOK=$((numOK+1)) fi ;; esac -PORT=$((PORT+1)) N=$((N+1)) @@ -6780,7 +6821,7 @@ else tf="$td/test$N.file" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" $PRINTF "test $F_n $TEST... " $N CMD="$SOCAT $opts -u open:\"${tf}1\",o-noatime /dev/null" # generate a file @@ -6829,7 +6870,7 @@ else tf="$td/test$N.file" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da=$(date) +da="test$N $(date) $RANDOM" $PRINTF "test $F_n $TEST... " $N touch ${tf}1 CMD="$SOCAT $opts -u -,o-noatime /dev/null <${tf}1" @@ -6881,7 +6922,7 @@ tf="$td/test$N.file" te="$td/test$N.stderr" tdiff="$td/test$N.diff" ts1="$ts" -da=$(date) +da="test$N $(date) $RANDOM" $PRINTF "test $F_n $TEST... " $N CMD0="$SOCAT $opts -u /dev/null create:\"${tf}1\"" CMD="$SOCAT $opts -u /dev/null create:\"${tf}1\",ext2-noatime" @@ -6938,7 +6979,7 @@ ti="$td/test$N.pipe" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" # a reader that will terminate after 1 byte CMD1="$SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null" CMD="$SOCAT $opts -u - file:\"$ti\",cool-write" @@ -6985,7 +7026,7 @@ ti="$td/test$N.pipe" tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" # a reader that will terminate after 1 byte CMD1="$SOCAT $opts -u pipe:\"$ti\",readbytes=1 /dev/null" CMD="$SOCAT $opts -,cool-write pipe >\"$ti\"" @@ -7097,28 +7138,12 @@ else numOK=$((numOK+1)) fi ;; esac -PORT=$((PORT+1)) -N=$((N+1)) - - -NAME=TCP4RANGEMASK -case "$TESTS" in -*%functions%*|*%security%*|*%tcp%*|*%tcp4%*|*%ip4%*|*%range%*|*%$NAME%*) -TEST="$NAME: security of TCP4-L with RANGE option" -if [ "$UNAME" != Linux ]; then - $PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N - numCANT=$((numCANT+1)) -else -testserversec "$N" "$TEST" "$opts -s" "tcp4-l:$PORT,reuseaddr,fork,retry=1" "" "range=127.0.0.0:255.255.0.0" "tcp4:127.1.0.0:$PORT" 4 tcp $PORT 0 -fi ;; # Linux -esac -PORT=$((PORT+1)) N=$((N+1)) NAME=UDP6LISTENBIND # this tests for a bug in (up to) 1.5.0.0: -# with upd*-listen, the bind option supported only IPv4 +# with udp*-listen, the bind option supported only IPv4 case "$TESTS" in *%functions%*|*%bugs%*|*%ip6%*|*%ipapp%*|*%udp%*|*%$NAME%*) TEST="$NAME: UDP6-LISTEN with bind" @@ -7131,7 +7156,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="$LOCALHOST6:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UDP6-LISTEN:$tsl,reuseaddr,bind=$LOCALHOST6 PIPE" CMD2="$SOCAT $opts - UDP6:$ts" printf "test $F_n $TEST... " $N @@ -7175,10 +7200,10 @@ else tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" ha="$td/hosts.allow" $ECHO "test : ALL : allow" >"$ha" -CMD1="$SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr,hosts-allow=$a,tcpwrap=test pipe" +CMD1="$SOCAT $opts TCP4-LISTEN:$PORT,reuseaddr,hosts-allow=$ha,tcpwrap=test pipe" CMD2="$SOCAT $opts - TCP:$LOCALHOST:$PORT" printf "test $F_n $TEST... " $N $CMD1 2>"${te}1" & @@ -7219,7 +7244,7 @@ else tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" ha="$td/hosts.allow" hd="$td/hosts.deny" $ECHO "socat : [::1] : allow" >"$ha" @@ -7269,7 +7294,7 @@ ts1p=$PORT; PORT=$((PORT+1)) ts1="$BCADDR:$ts1p" ts2p=$PORT; PORT=$((PORT+1)) ts2="$BCIFADDR:$ts2p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,broadcast PIPE" #CMD2="$SOCAT $opts - UDP4-BROADCAST:$ts1" CMD2="$SOCAT $opts - UDP4-DATAGRAM:$ts1,broadcast" @@ -7302,7 +7327,6 @@ else fi fi ;; # feats esac -PORT=$((PORT+1)) N=$((N+1)) @@ -7330,7 +7354,7 @@ ts1p=$PROTO ts1="$BCADDR:$ts1p" ts2p=$ts1p ts2="$BCIFADDR" -da="$(date) $RANDOM XXXX" +da="test$N $(date) $RANDOM XXXX" sh="$td/test$N-sed.sh" echo 'sed s/XXXX/YYYY/' >"$sh" chmod a+x "$sh" @@ -7394,7 +7418,7 @@ tdiff="$td/test$N.diff" ts1p=$PORT; PORT=$((PORT+1)) ts1a="$SECONDADDR" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT -u $opts UDP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -" CMD2="$SOCAT -u $opts - UDP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a" printf "test $F_n $TEST... " $N @@ -7423,7 +7447,6 @@ else fi fi ;; # not feats esac -PORT=$((PORT+1)) N=$((N+1)) NAME=IP4MULTICAST_UNIDIR @@ -7443,7 +7466,7 @@ tdiff="$td/test$N.diff" ts1p=$PROTO ts1a="$SECONDADDR" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT -u $opts IP4-RECV:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a -" CMD2="$SOCAT -u $opts - IP4-SENDTO:224.255.255.254:$ts1p,bind=$ts1a" printf "test $F_n $TEST... " $N @@ -7491,7 +7514,7 @@ tdiff="$td/test$N.diff" ts1p=$PORT; PORT=$((PORT+1)) if1="$MCINTERFACE" ts1a="[::1]" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT -u $opts UDP6-RECV:$ts1p,reuseaddr,ipv6-join-group=[ff02::2]:$if1 -" CMD2="$SOCAT -u $opts - UDP6-SENDTO:[ff02::2]:$ts1p,bind=$ts1a" printf "test $F_n $TEST... " $N @@ -7520,7 +7543,6 @@ else fi fi ;; # not feats esac -PORT=$((PORT+1)) N=$((N+1)) fi # false @@ -7536,7 +7558,7 @@ ts1a="$SECONDADDR" ts1="$ts1a:$ts1p" ts2p=$PORT; PORT=$((PORT+1)) ts2="$BCIFADDR:$ts2p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts UDP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE" #CMD2="$SOCAT $opts - UDP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a" CMD2="$SOCAT $opts - UDP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a" @@ -7568,7 +7590,6 @@ else numOK=$((numOK+1)) fi ;; esac -PORT=$((PORT+1)) N=$((N+1)) NAME=IP4MULTICAST_BIDIR @@ -7588,7 +7609,7 @@ tdiff="$td/test$N.diff" ts1p=$PROTO ts1a="$SECONDADDR" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts IP4-RECVFROM:$ts1p,reuseaddr,ip-add-membership=224.255.255.254:$ts1a PIPE" #CMD2="$SOCAT $opts - IP4-MULTICAST:224.255.255.254:$ts1p,bind=$ts1a" CMD2="$SOCAT $opts - IP4-DATAGRAM:224.255.255.254:$ts1p,bind=$ts1a" @@ -7596,6 +7617,7 @@ printf "test $F_n $TEST... " $N $CMD1 2>"${te}1" & pid1="$!" waitip4port $ts1p 1 +usleep 100000 # give process a chance to add membership echo "$da" |$CMD2 >>"$tf" 2>>"${te}2" rc2="$?" kill "$pid1" 2>/dev/null; wait; @@ -7643,7 +7665,7 @@ tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" tl="$td/test$N.lock" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" dalen=$((${#da}+1)) TUNNET=10.255.255 CMD1="$SOCAT $opts -u - UDP4-SENDTO:$TUNNET.2:$PORT" @@ -7743,7 +7765,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" ts1="$td/test$N.socket1" ts2="$td/test$N.socket2" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts ABSTRACT-RECVFROM:$ts1,reuseaddr PIPE" #CMD2="$SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2" CMD2="$SOCAT $opts - ABSTRACT-SENDTO:$ts1,bind=$ts2" @@ -7773,7 +7795,6 @@ else fi fi ;; # not feats esac -PORT=$((PORT+1)) N=$((N+1)) @@ -7790,7 +7811,7 @@ tf="$td/test$N.stdout" te="$td/test$N.stderr" tdiff="$td/test$N.diff" ts1="$ts" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -u ABSTRACT-RECV:$ts1,reuseaddr -" CMD2="$SOCAT $opts -u - ABSTRACT-SENDTO:$ts1" printf "test $F_n $TEST... " $N @@ -7821,7 +7842,6 @@ else fi fi ;; # not feats esac -PORT=$((PORT+1)) N=$((N+1)) @@ -7848,7 +7868,7 @@ else tf="$td/test$N.out" te="$td/test$N.err" tdiff="$td/test$N.diff" -da="$(date) $RANDOM" +da="test$N $(date) $RANDOM" SRVCERT=testsrv gentestcert "$SRVCERT" CMD1="$SOCAT $opts -u -T 1 -b $($ECHO "$da\c" |wc -c) OPENSSL-LISTEN:$PORT,reuseaddr,cert=$SRVCERT.pem,verify=0 -" @@ -7900,7 +7920,7 @@ ti="$td/test$N.in" to="$td/test$N.out" te="$td/test$N.err" tdiff="$td/test$N.diff" -da="$(date)" da="$da$($ECHO '\r')" +da="test$N $(date) $RANDOM"; da="$da$($ECHO '\r')" CMD="$SOCAT $opts system:\"echo A; sleep 2\",readbytes=2!!- -!!/dev/null" printf "test $F_n $TEST... " $N (sleep 1; echo) |eval "$CMD" >"$to" 2>"$te" @@ -7983,10 +8003,11 @@ tdiff="$td/test$N.diff" # find a service entry we do not need root for (>=1024; here >=1100 for ease) SERVENT="$(grep '^[a-z][a-z]*[^!-~][^!-~]*[1-9][1-9][0-9][0-9]/tcp' /etc/services |head -n 1)" SERVICE="$(echo $SERVENT |cut -d' ' -f1)" +_PORT="$PORT" PORT="$(echo $SERVENT |sed 's/.* \([1-9][0-9]*\).*/\1/')" tsl="$PORT" ts="127.0.0.1:$SERVICE" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts TCP4-LISTEN:$tsl,reuseaddr PIPE" CMD2="$SOCAT $opts stdin!!stdout TCP4:$ts" printf "test $F_n $TEST... " $N @@ -8013,7 +8034,7 @@ fi kill $pid1 2>/dev/null wait ;; esac -#PORT=$((PORT+1)) +PORT="$_PORT" N=$((N+1)) @@ -8074,7 +8095,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="$LOCALHOST:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -T 0.5 UDP4-LISTEN:$tsl,reuseaddr,fork PIPE" CMD2="$SOCAT $opts - UDP4:$ts" printf "test $F_n $TEST... " $N @@ -8115,7 +8136,7 @@ NAME=UDP4RECVFROM_SIGCHLD case "$TESTS" in *%functions%*|*%ip4%*|*%udp%*|*%dgram%*|*%zombie%*|*%$NAME%*) TEST="$NAME: test if UDP4-RECVFROM child becomes zombie" -# idea: run a udp-recvfrom process with fork and -T. Sent it one packet, so a +# idea: run a udp-recvfrom process with fork and -T. Send it one packet, so a # sub process is forked off. Make some transfer and wait until the -T timeout # is over. Now check for the child process: if it is zombie the test failed. # Correct is that child process terminated @@ -8124,7 +8145,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsl=$PORT ts="$LOCALHOST:$tsl" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -T 0.5 UDP4-RECVFROM:$tsl,reuseaddr,fork PIPE" CMD2="$SOCAT $opts - UDP4-SENDTO:$ts" printf "test $F_n $TEST... " $N @@ -8141,7 +8162,7 @@ if [ $rc2 -ne 0 ]; then $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM numCANT=$((numCANT+1)) elif ! echo "$da" |diff - "$tf" >"$tdiff"; then - $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAMM + $PRINTF "$NO_RESULT\n" # already handled in test UDP4DGRAM numCANT=$((numCANT+1)) elif $(isdefunct "$l"); then $PRINTF "$FAILED: $SOCAT:\n" @@ -8179,7 +8200,7 @@ tdiff="$td/test$N.diff" ts1p=$PROTO; PROTO=$((PROTO+1)) ts1a="127.0.0.1" ts1="$ts1a:$ts1p" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -u IP4-RECV:$ts1p,bind=$ts1a,reuseaddr -" CMD2="$SOCAT $opts -u - IP4-SENDTO:$ts1" printf "test $F_n $TEST... " $N @@ -8209,7 +8230,7 @@ else fi fi # must be root ;; esac -PORT=$((PORT+1)) +PROTO=$((PROTO+1)) N=$((N+1)) @@ -8228,7 +8249,7 @@ te="$td/test$N.stderr" tdiff="$td/test$N.diff" tsp=$PORT ts="$LOCALHOST:$tsp" -da=$(date) +da="test$N $(date) $RANDOM" CMD1="$SOCAT $opts -T 2 UDP4-RECVFROM:$tsp,reuseaddr,fork PIPE" CMD2="$SOCAT $opts -T 1 - UDP4-SENDTO:$ts" printf "test $F_n $TEST... " $N