Home | History | Annotate | Line # | Download | only in ftp
      1  1.1  riastrad #	$NetBSD: t_custom_headers.sh,v 1.1 2024/10/12 22:19:37 riastradh Exp $
      2  1.1  riastrad #
      3  1.1  riastrad # Copyright (c) 2024 The NetBSD Foundation, Inc.
      4  1.1  riastrad # All rights reserved.
      5  1.1  riastrad #
      6  1.1  riastrad # This code is derived from software contributed to The NetBSD Foundation
      7  1.1  riastrad # by Sunil Nimmagadda.
      8  1.1  riastrad #
      9  1.1  riastrad # Redistribution and use in source and binary forms, with or without
     10  1.1  riastrad # modification, are permitted provided that the following conditions
     11  1.1  riastrad # are met:
     12  1.1  riastrad # 1. Redistributions of source code must retain the above copyright
     13  1.1  riastrad #    notice, this list of conditions and the following disclaimer.
     14  1.1  riastrad # 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  riastrad #    notice, this list of conditions and the following disclaimer in the
     16  1.1  riastrad #    documentation and/or other materials provided with the distribution.
     17  1.1  riastrad #
     18  1.1  riastrad # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19  1.1  riastrad # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20  1.1  riastrad # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21  1.1  riastrad # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22  1.1  riastrad # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23  1.1  riastrad # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24  1.1  riastrad # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  1.1  riastrad # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26  1.1  riastrad # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27  1.1  riastrad # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  1.1  riastrad # POSSIBILITY OF SUCH DAMAGE.
     29  1.1  riastrad #
     30  1.1  riastrad 
     31  1.1  riastrad atf_test_case custom_headers cleanup
     32  1.1  riastrad custom_headers_head()
     33  1.1  riastrad {
     34  1.1  riastrad 	atf_require_prog ftp
     35  1.1  riastrad 	atf_set "descr" "Check for custom HTTP headers"
     36  1.1  riastrad }
     37  1.1  riastrad 
     38  1.1  riastrad HTTPD_PID=./.__httpd.pid
     39  1.1  riastrad custom_headers_body()
     40  1.1  riastrad {
     41  1.1  riastrad 	# start httpd in daemon mode
     42  1.1  riastrad 	atf_check -s exit:0 \
     43  1.1  riastrad 	    /usr/libexec/httpd -P $HTTPD_PID -I 8080 -b -C .sh /bin/sh \
     44  1.1  riastrad 	    -c "$(atf_get_srcdir)" .
     45  1.1  riastrad 
     46  1.1  riastrad 	atf_check \
     47  1.1  riastrad 	    -o inline:'HTTP_X_ORIGIN=example.com\nHTTP_X_RATE_LIMIT=1000\n' \
     48  1.1  riastrad 	    ftp -V -o - \
     49  1.1  riastrad 		-H 'X-Origin: example.com' \
     50  1.1  riastrad 		-H 'X-Rate-Limit: 1000' \
     51  1.1  riastrad 		http://127.0.0.1:8080/cgi-bin/custom_headers.sh
     52  1.1  riastrad }
     53  1.1  riastrad 
     54  1.1  riastrad custom_headers_cleanup()
     55  1.1  riastrad {
     56  1.1  riastrad 	if [ -f "$HTTPD_PID" ]; then
     57  1.1  riastrad 		echo kill -9 "$(cat $HTTPD_PID)"
     58  1.1  riastrad 		kill -9 "$(cat $HTTPD_PID)"
     59  1.1  riastrad 		echo '# wait for httpd to exit'
     60  1.1  riastrad 		sleep 1
     61  1.1  riastrad 	fi
     62  1.1  riastrad }
     63  1.1  riastrad 
     64  1.1  riastrad atf_init_test_cases()
     65  1.1  riastrad {
     66  1.1  riastrad 	atf_add_test_case custom_headers
     67  1.1  riastrad }
     68