14ee8f2c5SMilton Miller#!/bin/sh -e 24ee8f2c5SMilton Miller 34ee8f2c5SMilton Millerset -e 44ee8f2c5SMilton Miller 54ee8f2c5SMilton MillerTMPFILE="out.$$" 64ee8f2c5SMilton MillerURLFILE="urls.$$" 74ee8f2c5SMilton Miller# TRACEFILE="/dev/tty" 84ee8f2c5SMilton Miller 94ee8f2c5SMilton Miller# create temp files 10*272b453cSPatrick Williams# shellcheck disable=SC2064 114ee8f2c5SMilton Millerrm -f $TMPFILE $URLFILE && touch $TMPFILE && 124ee8f2c5SMilton Millertrap "rm ./$TMPFILE ./$URLFILE" 0 || exit 2 134ee8f2c5SMilton Millerecho "/over/the/rainbow /over/the/rainbow" > $URLFILE 144ee8f2c5SMilton Miller 154ee8f2c5SMilton Miller# build up the command line 164ee8f2c5SMilton Miller# for mawk, add -Wi or -W interactive to avoid buffered read on fifo 174ee8f2c5SMilton Milleroverrides="-v urlfile=$URLFILE -f add-urls.awk -v tracefile=$TRACEFILE" 184ee8f2c5SMilton Millercommand="awk -f ./http-redirect.awk $overrides" 194ee8f2c5SMilton Miller 20756eaf79SMilton Millerawk -f ./test.awk -v "resultfile=$TMPFILE" -v "tracefile=$TRACEFILE" 214ee8f2c5SMilton Miller 224ee8f2c5SMilton Miller# remember the CR in your expect 234ee8f2c5SMilton Miller 244ee8f2c5SMilton Millertest="1 test absolute URI" 254ee8f2c5SMilton Millerexpect='^location: https://somewhere.example.com/over/the/rainbow.$' 264ee8f2c5SMilton Miller$command << HERE > $TMPFILE 274ee8f2c5SMilton MillerGET http://somewhere.example.com/over/the/rainbow HTTP/1.1 284ee8f2c5SMilton MillerHost: elsewhere.example 294ee8f2c5SMilton Miller 304ee8f2c5SMilton MillerHERE 314ee8f2c5SMilton Miller 324ee8f2c5SMilton Millerif grep -is "$expect" $TMPFILE 334ee8f2c5SMilton Millerthen 34*272b453cSPatrick Williams echo "PASS $test" 354ee8f2c5SMilton Millerelse 36*272b453cSPatrick Williams echo "FAIL $test" 374ee8f2c5SMilton Miller echo "Expected to find >'$expect'< in :" 384ee8f2c5SMilton Miller cat $TMPFILE 394ee8f2c5SMilton Miller false 404ee8f2c5SMilton Millerfi 414ee8f2c5SMilton Miller 424ee8f2c5SMilton Millertest="2 Test no absolute-path in URI" 434ee8f2c5SMilton Millerexpect='^location: https://somewhere.example/.$' 444ee8f2c5SMilton Miller$command << HERE > $TMPFILE 454ee8f2c5SMilton MillerGET http://somewhere.example HTTP/1.1 464ee8f2c5SMilton MillerHost: elsewhere.example 474ee8f2c5SMilton Miller 484ee8f2c5SMilton MillerHERE 494ee8f2c5SMilton Miller 504ee8f2c5SMilton Millerif grep -is "$expect" $TMPFILE 514ee8f2c5SMilton Millerthen 52*272b453cSPatrick Williams echo "PASS $test" 534ee8f2c5SMilton Millerelse 54*272b453cSPatrick Williams echo "FAIL $test" 554ee8f2c5SMilton Miller echo "Expected to find >'$expect'< in :" 564ee8f2c5SMilton Miller cat $TMPFILE 574ee8f2c5SMilton Miller false 584ee8f2c5SMilton Millerfi 594ee8f2c5SMilton Miller 604ee8f2c5SMilton Miller 614ee8f2c5SMilton Millertest="3 test generic 1.1 client" 624ee8f2c5SMilton Millerexpect='^location: https://elsewhere.example/over/the/rainbow.$' 634ee8f2c5SMilton Miller$command << HERE > $TMPFILE 644ee8f2c5SMilton MillerGET /over/the/rainbow HTTP/1.1 654ee8f2c5SMilton MillerHost: elsewhere.example 664ee8f2c5SMilton Miller 674ee8f2c5SMilton MillerHERE 684ee8f2c5SMilton Miller 694ee8f2c5SMilton Millerif grep -is "$expect" $TMPFILE 704ee8f2c5SMilton Millerthen 71*272b453cSPatrick Williams echo "PASS $test" 724ee8f2c5SMilton Millerelse 73*272b453cSPatrick Williams echo "FAIL $test" 744ee8f2c5SMilton Miller echo "Expected to find >'$expect'< in :" 754ee8f2c5SMilton Miller cat $TMPFILE 764ee8f2c5SMilton Miller false 774ee8f2c5SMilton Millerfi 784ee8f2c5SMilton Miller 794ee8f2c5SMilton Miller 804ee8f2c5SMilton Miller 814ee8f2c5SMilton Millertest="4 test generic 1.1 client" 824ee8f2c5SMilton Millerexpect='^location: https://somewhere.com/over/the/rainbow.$' 834ee8f2c5SMilton Miller$command << HERE > $TMPFILE 844ee8f2c5SMilton MillerGET /over/the/rainbow HTTP/1.1 854ee8f2c5SMilton Millernot-host: elsewhere.example 864ee8f2c5SMilton Millerx-host: elsewhere.example.com 874ee8f2c5SMilton Miller ( comment ) 884ee8f2c5SMilton Millerhost: somewhere.com 894ee8f2c5SMilton Millerhost2: else.where.example.com 904ee8f2c5SMilton Miller 914ee8f2c5SMilton MillerHERE 924ee8f2c5SMilton Miller 934ee8f2c5SMilton Miller 944ee8f2c5SMilton Millerif grep -is "$expect" $TMPFILE 954ee8f2c5SMilton Millerthen 96*272b453cSPatrick Williams echo "PASS $test" 974ee8f2c5SMilton Millerelse 98*272b453cSPatrick Williams echo "FAIL $test" 994ee8f2c5SMilton Miller echo "Expected to find >'$expect'< in :" 1004ee8f2c5SMilton Miller cat $TMPFILE 1014ee8f2c5SMilton Miller false 1024ee8f2c5SMilton Millerfi 1034ee8f2c5SMilton Miller 1044ee8f2c5SMilton Miller 1054ee8f2c5SMilton Miller 1064ee8f2c5SMilton Millerecho all tests passed 107