#/bin/bash
#
# Test resuming a session via a session ticket

. common.sh
set +o errexit

sessfile=$(mktemp)
function rmsess {
	rm -f $sessfile
	cleanup
}
trap rmsess EXIT

$HITCH $HITCH_ARGS --backend=[hitch-tls.org]:80 "--frontend=[${LISTENADDR}]:$LISTENPORT" certs/site1.example.com
test "$?" = "0" || die "Hitch did not start."

echo -e "\n" | openssl s_client -prexit -sess_out $sessfile -connect $LISTENADDR:$LISTENPORT >/dev/null 2>&1
test "$?" = "0" || die "s_client failed (1)"

echo -e "\n" | openssl s_client -prexit -sess_in $sessfile -connect $LISTENADDR:$LISTENPORT 2>/dev/null > $DUMPFILE
test "$?" = "0" || die "s_client failed (2)"

grep -q -c "Reused, " $DUMPFILE
test "$?" = "0" || die "Unable to resume session via session ticket."

runcurl $LISTENADDR $LISTENPORT
