NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/58581 (ftp(1) should allow specifying header fields in http requests)
riastradh%NetBSD.org@localhost writes:
> Synopsis: ftp(1) should allow specifying header fields in http requests
>
> State-Changed-From-To: open->needs-pullups
> State-Changed-By: riastradh%NetBSD.org@localhost
> State-Changed-When: Fri, 27 Sep 2024 16:34:22 +0000
> State-Changed-Why:
> Cool, thanks, Sunil! Would also be nice if we had automatic tests for
> this, maybe with bozohttpd and a simple cgi script run under atf.
>
> Anyway, let's get this pulled up to 10.
Sure, the attached diff has a testcase for the custom headers feature
using atf...
diff --git a/tests/usr.bin/Makefile b/tests/usr.bin/Makefile
index d0456d50235b..3d30e6157de5 100644
--- a/tests/usr.bin/Makefile
+++ b/tests/usr.bin/Makefile
@@ -6,7 +6,7 @@
TESTSDIR= ${TESTSBASE}/usr.bin
TESTS_SUBDIRS= awk basename bzip2 cc cmp compress config cpio col cut \
- diff dirname error find fstat gdb grep gzip id indent \
+ diff dirname error find fstat ftp gdb grep gzip id indent \
infocmp jot ld locale m4 make mixerctl mkdep mtree nbperf \
netpgpverify patch pkill pr printf pwhash realpath rump_server \
shmif_dumpbus shmif_pcapin sdiff sed sort stat tar tmux tr \
diff --git a/tests/usr.bin/ftp/Makefile b/tests/usr.bin/ftp/Makefile
new file mode 100644
index 000000000000..b66e9fdeefde
--- /dev/null
+++ b/tests/usr.bin/ftp/Makefile
@@ -0,0 +1,8 @@
+# $NetBSD: Makefile,v 1.1 2020/06/24 10:05:07 jruoho Exp $
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/usr.bin/ftp
+TESTS_SH= t_custom_headers
+
+.include <bsd.test.mk>
diff --git a/tests/usr.bin/ftp/t_custom_headers.sh b/tests/usr.bin/ftp/t_custom_headers.sh
new file mode 100644
index 000000000000..03eddee22e54
--- /dev/null
+++ b/tests/usr.bin/ftp/t_custom_headers.sh
@@ -0,0 +1,34 @@
+atf_test_case custom_headers cleanup
+custom_headers_head()
+{
+ atf_require_prog ftp
+ atf_set "descr" "Check for custom HTTP headers"
+}
+
+HTTPD_PID=./.__httpd.pid
+custom_headers_body()
+{
+ # start httpd in daemon mode
+ atf_check -s exit:0 \
+ /usr/libexec/httpd -P $HTTPD_PID -I 8080 -b -C .sh /bin/sh \
+ -c $(atf_get_srcdir)/www/cgi-bin $(atf_get_srcdir)/www
+
+ atf_check -o inline:"example.com\n1000\n" \
+ -x "ftp -Vo- -H X-Origin:example.com \
+ -H X-Rate-Limit:1000 \
+ http://127.0.0.1:8080/cgi-bin/custom_headers.sh"
+}
+
+custom_headers_cleanup()
+{
+ if [ -f $HTTPD_PID ]; then
+ kill -9 $(cat $HTTPD_PID)
+ rm -f $HTTPD_PID
+ sleep 1
+ fi
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case custom_headers
+}
diff --git a/tests/usr.bin/ftp/www/cgi-bin/custom_headers.sh b/tests/usr.bin/ftp/www/cgi-bin/custom_headers.sh
new file mode 100755
index 000000000000..65428b79c352
--- /dev/null
+++ b/tests/usr.bin/ftp/www/cgi-bin/custom_headers.sh
@@ -0,0 +1,11 @@
+#! /bin/sh
+
+echo "Content-type: text/html; charset=utf-8"
+echo ""
+if [ "$HTTP_X_ORIGIN" ]; then
+ echo "$HTTP_X_ORIGIN"
+fi
+
+if [ "$HTTP_X_RATE_LIMIT" ]; then
+ echo "$HTTP_X_RATE_LIMIT"
+fi
Home |
Main Index |
Thread Index |
Old Index