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)



The following reply was made to PR bin/58581; it has been noted by GNATS.

From: Sunil Nimmagadda <sunil%nimmagadda.net@localhost>
To: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Cc: gnats-admin%NetBSD.org@localhost,  netbsd-bugs%NetBSD.org@localhost,  gnats-bugs%NetBSD.org@localhost
Subject: Re: bin/58581 (ftp(1) should allow specifying header fields in http
 requests)
Date: Wed, 02 Oct 2024 19:24:53 +0530

 --=-=-=
 Content-Type: text/plain
 
 Taylor R Campbell <riastradh%NetBSD.org@localhost> writes:
 
 >> Date: Mon, 30 Sep 2024 13:10:23 +0530
 >> From: Sunil Nimmagadda <sunil%nimmagadda.net@localhost>
 >> 
 >> Sure, the attached diff has a testcase for the custom headers feature
 >> using atf...
 >
 > That looks great!  Since it's not a trivial change, can you please
 > provide a 2-clause BSD licence statement on the new files?
 >
 > (There are lots of other examples you can derive from, like
 > tests/usr.bin/stat/t_stat.sh -- feel free to keep the copyright for
 > yourself or contribute it to TNF, as you see fit, as long as it's
 > permissively licensed.)
 
 Sure, updated diff with licence for the new files...
 
 --=-=-=
 Content-Type: text/x-patch
 Content-Disposition: attachment; filename=testcase.diff
 Content-Description: ftp(1): Test for custom HTTP headers in a request
 
 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..3609fb6ec6a8
 --- /dev/null
 +++ b/tests/usr.bin/ftp/t_custom_headers.sh
 @@ -0,0 +1,62 @@
 +# Copyright (c) 2024 The NetBSD Foundation, Inc.
 +# All rights reserved.
 +#
 +# This code is derived from software contributed to The NetBSD Foundation
 +# by Sunil Nimmagadda.
 +#
 +# Redistribution and use in source and binary forms, with or without
 +# modification, are permitted provided that the following conditions
 +# are met:
 +# 1. Redistributions of source code must retain the above copyright
 +#    notice, this list of conditions and the following disclaimer.
 +# 2. Redistributions in binary form must reproduce the above copyright
 +#    notice, this list of conditions and the following disclaimer in the
 +#    documentation and/or other materials provided with the distribution.
 +#
 +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 +# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 +# POSSIBILITY OF SUCH DAMAGE.
 +#
 +
 +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..f448c4b49a0f
 --- /dev/null
 +++ b/tests/usr.bin/ftp/www/cgi-bin/custom_headers.sh
 @@ -0,0 +1,39 @@
 +#! /bin/sh
 +
 +# Copyright (c) 2024 The NetBSD Foundation, Inc.
 +# All rights reserved.
 +#
 +# This code is derived from software contributed to The NetBSD Foundation
 +# by Sunil Nimmagadda.
 +#
 +# Redistribution and use in source and binary forms, with or without
 +# modification, are permitted provided that the following conditions
 +# are met:
 +# 1. Redistributions of source code must retain the above copyright
 +#    notice, this list of conditions and the following disclaimer.
 +# 2. Redistributions in binary form must reproduce the above copyright
 +#    notice, this list of conditions and the following disclaimer in the
 +#    documentation and/or other materials provided with the distribution.
 +#
 +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 +# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 +# POSSIBILITY OF SUCH DAMAGE.
 +#
 +
 +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