xref: /openbsd/regress/usr.bin/ftp/redirect.sh (revision 6f40fd34)
1#!/bin/sh
2#	$OpenBSD: redirect.sh,v 1.6 2017/01/23 23:10:35 bluhm Exp $
3
4: ${FTP:=ftp}
5
6: ${rport1:=9000}
7: ${rport2:=9001}
8
9req1=$1
10loc=$2
11req2=$3
12
13echo "Testing $req1 => $loc => $req2"
14
15# Be sure to kill any previous nc running on our port
16while pkill -fx "nc -4 -l $rport1" && sleep 1; do done
17
18echo "HTTP/1.0 302 Found\r\nLocation: $loc\r\n\r" | \
19     nc -4 -l $rport1 >/dev/null &
20
21# Wait for the "server" to start
22until fstat | egrep 'nc[ ]+.*tcp 0x[0-9a-f]* \*:9000' > /dev/null; do
23	sleep .1
24done
25
26unset http_proxy
27
28res=$(${FTP} -4 -o/dev/null -v $req1 2>&1 | \
29    sed '/^Redirected to /{s///;x;};$!d;x')
30
31if [ X"$res" != X"$req2" ]; then
32	echo "*** Fail; expected \"$req2\", got \"$res\""
33	exit 1
34fi
35