Module Name: src Committed By: riastradh Date: Sat Oct 12 22:19:37 UTC 2024
Modified Files: src/distrib/sets/lists/tests: mi src/etc/mtree: NetBSD.dist.tests src/tests/usr.bin: Makefile Added Files: src/tests/usr.bin/ftp: Makefile custom_headers.sh t_custom_headers.sh Log Message: ftp(1): Add test for custom HTTP header fields. Based on a patch from Sunil Nimmagadda <su...@nimmagadda.net>. PR bin/58581: ftp(1) should allow specifying header fields in http requests To generate a diff of this commit: cvs rdiff -u -r1.1341 -r1.1342 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.207 -r1.208 src/etc/mtree/NetBSD.dist.tests cvs rdiff -u -r1.41 -r1.42 src/tests/usr.bin/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/ftp/Makefile \ src/tests/usr.bin/ftp/custom_headers.sh \ src/tests/usr.bin/ftp/t_custom_headers.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1341 src/distrib/sets/lists/tests/mi:1.1342 --- src/distrib/sets/lists/tests/mi:1.1341 Wed Oct 9 13:02:53 2024 +++ src/distrib/sets/lists/tests/mi Sat Oct 12 22:19:36 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1341 2024/10/09 13:02:53 kre Exp $ +# $NetBSD: mi,v 1.1342 2024/10/12 22:19:36 riastradh Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -4918,6 +4918,11 @@ ./usr/tests/usr.bin/fstat/Atffile tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/fstat/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua ./usr/tests/usr.bin/fstat/t_fstat tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/ftp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/ftp/Atffile tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/ftp/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua +./usr/tests/usr.bin/ftp/custom_headers.sh tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/ftp/t_custom_headers tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/gdb tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/gdb/Atffile tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/gdb/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua Index: src/etc/mtree/NetBSD.dist.tests diff -u src/etc/mtree/NetBSD.dist.tests:1.207 src/etc/mtree/NetBSD.dist.tests:1.208 --- src/etc/mtree/NetBSD.dist.tests:1.207 Mon Sep 2 05:17:46 2024 +++ src/etc/mtree/NetBSD.dist.tests Sat Oct 12 22:19:37 2024 @@ -1,4 +1,4 @@ -# $NetBSD: NetBSD.dist.tests,v 1.207 2024/09/02 05:17:46 ozaki-r Exp $ +# $NetBSD: NetBSD.dist.tests,v 1.208 2024/10/12 22:19:37 riastradh Exp $ ./usr/libdata/debug/usr/tests ./usr/libdata/debug/usr/tests/atf @@ -452,6 +452,7 @@ ./usr/tests/usr.bin/error ./usr/tests/usr.bin/find ./usr/tests/usr.bin/fstat +./usr/tests/usr.bin/ftp ./usr/tests/usr.bin/gdb ./usr/tests/usr.bin/grep ./usr/tests/usr.bin/gzip Index: src/tests/usr.bin/Makefile diff -u src/tests/usr.bin/Makefile:1.41 src/tests/usr.bin/Makefile:1.42 --- src/tests/usr.bin/Makefile:1.41 Mon Sep 2 05:16:37 2024 +++ src/tests/usr.bin/Makefile Sat Oct 12 22:19:37 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.41 2024/09/02 05:16:37 ozaki-r Exp $ +# $NetBSD: Makefile,v 1.42 2024/10/12 22:19:37 riastradh Exp $ # .include <bsd.own.mk> @@ -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 \ Added files: Index: src/tests/usr.bin/ftp/Makefile diff -u /dev/null src/tests/usr.bin/ftp/Makefile:1.1 --- /dev/null Sat Oct 12 22:19:37 2024 +++ src/tests/usr.bin/ftp/Makefile Sat Oct 12 22:19:37 2024 @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1 2024/10/12 22:19:37 riastradh Exp $ + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/usr.bin/ftp +TESTS_SH= t_custom_headers + +SCRIPTSDIR= ${TESTSDIR} +SCRIPTS+= custom_headers.sh + +# Keep the .sh suffix because we use it to trigger cgi-bin handling in +# bozohttpd (rather silly but it's easier that way). +SCRIPTSNAME_custom_headers.sh= custom_headers.sh + +.include <bsd.test.mk> Index: src/tests/usr.bin/ftp/custom_headers.sh diff -u /dev/null src/tests/usr.bin/ftp/custom_headers.sh:1.1 --- /dev/null Sat Oct 12 22:19:37 2024 +++ src/tests/usr.bin/ftp/custom_headers.sh Sat Oct 12 22:19:37 2024 @@ -0,0 +1,36 @@ +#! /bin/sh +# +# $NetBSD: custom_headers.sh,v 1.1 2024/10/12 22:19:37 riastradh Exp $ +# +# 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/plain; charset=utf-8" +echo "" +echo "HTTP_X_ORIGIN=$HTTP_X_ORIGIN" +echo "HTTP_X_RATE_LIMIT=$HTTP_X_RATE_LIMIT" Index: src/tests/usr.bin/ftp/t_custom_headers.sh diff -u /dev/null src/tests/usr.bin/ftp/t_custom_headers.sh:1.1 --- /dev/null Sat Oct 12 22:19:37 2024 +++ src/tests/usr.bin/ftp/t_custom_headers.sh Sat Oct 12 22:19:37 2024 @@ -0,0 +1,67 @@ +# $NetBSD: t_custom_headers.sh,v 1.1 2024/10/12 22:19:37 riastradh Exp $ +# +# 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)" . + + atf_check \ + -o inline:'HTTP_X_ORIGIN=example.com\nHTTP_X_RATE_LIMIT=1000\n' \ + ftp -V -o - \ + -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 + echo kill -9 "$(cat $HTTPD_PID)" + kill -9 "$(cat $HTTPD_PID)" + echo '# wait for httpd to exit' + sleep 1 + fi +} + +atf_init_test_cases() +{ + atf_add_test_case custom_headers +}