add regress tests for upcoming redirection changes to ftp
authorhalex <halex@openbsd.org>
Wed, 14 Jul 2010 06:19:26 +0000 (06:19 +0000)
committerhalex <halex@openbsd.org>
Wed, 14 Jul 2010 06:19:26 +0000 (06:19 +0000)
regress/usr.bin/ftp/Makefile
regress/usr.bin/ftp/redirect.sh [new file with mode: 0644]

index 95397e6..e27c455 100644 (file)
@@ -1,9 +1,8 @@
-# $OpenBSD: Makefile,v 1.1 2010/06/29 21:22:03 halex Exp $
-
-DASHO_TARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
+# $OpenBSD: Makefile,v 1.2 2010/07/14 06:19:26 halex Exp $
 
 REGRESS_TARGETS= \
-       ${DASHO_TARGETS:C/^/t-dasho-/}
+               ${DASHO_TARGETS:C/^/t-dasho-/} \
+               ${REDIRECT_TARGETS:C/^/t-redirect-/}
 
 dfile=file:../src/-
 xfile=file:../src/X
@@ -60,4 +59,66 @@ t-dasho-15:
 t-dasho-16:
        ${dasho} "-V -o- -o '' ${dfile}" 0      ""      ""      "[-] DASH"
 
+DASHO_TARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
+
+
+rport1?=       9000
+rport2?=       9001
+rbase1=                http://localhost:${rport1}
+rbase2=                http://localhost:${rport2}
+rbase_1=       http://[localhost]:${rport1}
+rbase_2=       http://[localhost]:${rport2}
+
+redirect=      @rport1=${rport1} rport2=${rport2} sh ${.CURDIR}/redirect.sh
+
+#      ${redirect}     request                 Location:               request
+
+t-redirect-1:
+       ${redirect}     ${rbase1}/path/to/file  ${rbase2}/another/file  ${rbase2}/another/file
+
+t-redirect-2:
+       ${redirect}     ${rbase1}/path/to/file  ${rbase2}/              ${rbase2}/
+
+t-redirect-3:
+       ${redirect}     ${rbase1}/path/to/file  /another/file           ${rbase1}/another/file
+
+t-redirect-4:
+       ${redirect}     ${rbase1}/path/to/file  /                       ${rbase1}/
+
+t-redirect-5:
+       ${redirect}     ${rbase1}/path/to/file  another/file            ${rbase1}/path/to/another/file
+
+t-redirect-6:
+       ${redirect}     ${rbase1}/path/to/file/ another/file            ${rbase1}/path/to/file/another/file
+
+t-redirect-7:
+       ${redirect}     ${rbase1}/path/to/file  ../                     ${rbase1}/path/to/../
+
+t-redirect-8:
+       ${redirect}     ${rbase1}/path/to/file  ${rbase_2}/another/file ${rbase_2}/another/file
+
+t-redirect-9:
+       ${redirect}     ${rbase1}/path/to/file  ${rbase_2}/             ${rbase_2}/
+
+t-redirect-10:
+       ${redirect}     ${rbase1}/p/x?a#b?c#d   another/file            ${rbase1}/p/another/file
+
+t-redirect-11:
+       ${redirect}     ${rbase1}/p/x#b?c#d     another/file            ${rbase1}/p/another/file
+
+t-redirect-12:
+       ${redirect}     ${rbase1}/p/x/#b?c#d    another/file            ${rbase1}/p/x/another/file
+
+t-redirect-13:
+       ${redirect}     ${rbase1}/p/x?aa#bb     another/file?x#yz       ${rbase1}/p/another/file?x
+
+t-redirect-14:
+       ${redirect}     ${rbase1}/p/x/?aa#bb    another/file?x#yz       ${rbase1}/p/x/another/file?x
+
+t-redirect-15:
+       ${redirect}     ${rbase1}/p/x#y?z/k#l?m file?a#b?c#d            ${rbase1}/p/file?a
+
+REDIRECT_TARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+
+
 .include <bsd.regress.mk>
diff --git a/regress/usr.bin/ftp/redirect.sh b/regress/usr.bin/ftp/redirect.sh
new file mode 100644 (file)
index 0000000..6e365d2
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+: ${FTP:=ftp}
+
+: ${rport1:=9000}
+: ${rport2:=9001}
+
+req1=$1
+loc=$2
+req2=$3
+
+echo "Testing $req1 => $loc => $req2"
+
+# Be sure to kill any previous nc running on our port
+while pkill -fx "nc -l $rport1" && sleep 1; do done
+
+echo "HTTP/1.0 302 Found\r\nLocation: $loc\r\n\r" | nc -l $rport1 >&- &
+
+# Give the "server" some time to start
+sleep .1
+
+res=$(${FTP} -o/dev/null $req1 2>&1 | sed '/^Redirected to /{s///;x;};$!d;x')
+
+if [ X"$res" != X"$req2" ]; then
+       echo "*** Fail; expected \"$req2\", got \"$res\""
+       exit 1
+fi