hio/t/s-001.sh

91 lines
1.8 KiB
Bash
Raw Normal View History

#!/bin/sh
[ -z "$srcdir" ] && srcdir=$(dirname "$0")
. "${srcdir}/tap.inc"
2023-01-14 17:17:12 +00:00
test_default_index()
{
local msg="hio-webs default index.html under a directory"
local srvaddr=127.0.0.1:54321
local tmpdir="/tmp/s-001.$$"
mkdir -p "${tmpdir}"
## check if index.html is retrieved
../bin/hio-webs --file-no-list-dir "${srvaddr}" "${tmpdir}" 2>/dev/null &
local jid=$!
cat >"${tmpdir}/index.html" <<EOF
<html>
<body>
hello
</body>
</html>
EOF
sleep 0.5
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}")
tap_ensure "$hc" "200" "$msg - got $hc"
## check if 404 is returned if the document root is not found
rm -rf "${tmpdir}"
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}")
tap_ensure "$hc" "404" "$msg - got $hc"
kill -TERM ${jid}
wait ${jid}
}
test_file_list_dir()
{
2022-12-26 17:03:53 +00:00
local msg="hio-webs file-list-dir"
local srvaddr=127.0.0.1:54321
local tmpdir="/tmp/s-001.$$"
mkdir -p "${tmpdir}"
## check directory listing against an empty directory
../bin/hio-webs "${srvaddr}" "${tmpdir}" 2>/dev/null &
local jid=$!
sleep 0.5
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}")
tap_ensure "$hc" "200" "$msg - got $hc"
rm -rf "${tmpdir}"
kill -TERM ${jid}
wait ${jid}
}
2023-01-14 17:17:12 +00:00
test_cgi()
{
local msg="hio-webs file-list-dir"
local srvaddr=127.0.0.1:54321
local tmpdir="/tmp/s-001.$$"
mkdir -p "${tmpdir}"
cp -pf t-cgi "${tmpdir}/t.cgi"
## check directory listing against an empty directory
../bin/hio-webs "${srvaddr}" "${tmpdir}" 2>/dev/null &
local jid=$!
sleep 0.5
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}/t.cgi?abc=def#qq")
tap_ensure "$hc" "200" "$msg - got $hc"
rm -rf "${tmpdir}"
kill -TERM ${jid}
wait ${jid}
}
test_default_index
test_file_list_dir
2023-01-14 17:17:12 +00:00
test_cgi
tap_end