2022-12-17 16:04:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-12-22 16:25:20 +00:00
|
|
|
[ -z "$srcdir" ] && srcdir=$(dirname "$0")
|
2022-12-17 16:04:13 +00:00
|
|
|
. "${srcdir}/tap.inc"
|
|
|
|
|
2023-01-14 17:17:12 +00:00
|
|
|
test_default_index()
|
2022-12-17 16:04:13 +00:00
|
|
|
{
|
2022-12-31 15:20:07 +00:00
|
|
|
local msg="hio-webs default index.html under a directory"
|
2022-12-17 16:04:13 +00:00
|
|
|
local srvaddr=127.0.0.1:54321
|
|
|
|
local tmpdir="/tmp/s-001.$$"
|
2022-12-22 16:25:20 +00:00
|
|
|
|
|
|
|
mkdir -p "${tmpdir}"
|
|
|
|
|
|
|
|
## check if index.html is retrieved
|
2023-11-17 07:57:12 +00:00
|
|
|
echo ../bin/hio-webs --file-no-list-dir "${srvaddr}" "${tmpdir}" 2>/dev/null &
|
2022-12-31 15:20:07 +00:00
|
|
|
../bin/hio-webs --file-no-list-dir "${srvaddr}" "${tmpdir}" 2>/dev/null &
|
2022-12-17 16:04:13 +00:00
|
|
|
local jid=$!
|
|
|
|
|
|
|
|
cat >"${tmpdir}/index.html" <<EOF
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
hello
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
2022-12-22 16:25:20 +00:00
|
|
|
|
2022-12-17 16:04:13 +00:00
|
|
|
sleep 0.5
|
|
|
|
local hc=$(curl -s -w '%{http_code}\n' -o /dev/null "http://${srvaddr}")
|
|
|
|
tap_ensure "$hc" "200" "$msg - got $hc"
|
|
|
|
|
2022-12-22 16:25:20 +00:00
|
|
|
## check if 404 is returned if the document root is not found
|
2022-12-17 16:04:13 +00:00
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
2022-12-22 16:25:20 +00:00
|
|
|
|
|
|
|
test_file_list_dir()
|
|
|
|
{
|
2022-12-26 17:03:53 +00:00
|
|
|
local msg="hio-webs file-list-dir"
|
2022-12-22 16:25:20 +00:00
|
|
|
local srvaddr=127.0.0.1:54321
|
|
|
|
local tmpdir="/tmp/s-001.$$"
|
|
|
|
|
|
|
|
mkdir -p "${tmpdir}"
|
|
|
|
|
|
|
|
## check directory listing against an empty directory
|
2022-12-31 15:20:07 +00:00
|
|
|
../bin/hio-webs "${srvaddr}" "${tmpdir}" 2>/dev/null &
|
2022-12-22 16:25:20 +00:00
|
|
|
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()
|
|
|
|
{
|
2023-01-15 13:16:11 +00:00
|
|
|
local msg="hio-webs cgi"
|
2023-01-14 17:17:12 +00:00
|
|
|
local srvaddr=127.0.0.1:54321
|
|
|
|
local tmpdir="/tmp/s-001.$$"
|
|
|
|
|
|
|
|
mkdir -p "${tmpdir}"
|
2023-11-18 08:37:35 +00:00
|
|
|
cp -pf "${srcdir}/t-cgi.sh" "${tmpdir}/t.cgi"
|
|
|
|
chmod ugo+x "${tmpdir}/t.cgi"
|
2023-01-14 17:17:12 +00:00
|
|
|
|
|
|
|
## check directory listing against an empty directory
|
|
|
|
../bin/hio-webs "${srvaddr}" "${tmpdir}" 2>/dev/null &
|
|
|
|
local jid=$!
|
|
|
|
sleep 0.5
|
|
|
|
|
2023-01-19 16:11:37 +00:00
|
|
|
local hc=$(curl -s -w '%{http_code}\n' -o "${tmpdir}/t.out" "http://${srvaddr}/t.cgi?abc=def")
|
2023-01-14 17:17:12 +00:00
|
|
|
tap_ensure "$hc" "200" "$msg - got $hc"
|
|
|
|
|
2023-01-19 16:11:37 +00:00
|
|
|
ls -ld ${tmpdir}
|
|
|
|
ls -l ${tmpdir}
|
2023-11-18 08:37:35 +00:00
|
|
|
echo "--------------------"
|
|
|
|
cat ${tmpdir}/t.out
|
|
|
|
echo "--------------------"
|
|
|
|
cat ${tmpdir}/t.cgi
|
|
|
|
echo "--------------------"
|
|
|
|
|
2023-01-15 13:16:11 +00:00
|
|
|
local request_method=$(grep -E "^REQUEST_METHOD:" "${tmpdir}/t.out" | cut -d: -f2)
|
|
|
|
local request_uri=$(grep -E "^REQUEST_URI:" "${tmpdir}/t.out" | cut -d: -f2)
|
|
|
|
local query_string=$(grep -E "^QUERY_STRING:" "${tmpdir}/t.out" | cut -d: -f2)
|
|
|
|
|
|
|
|
tap_ensure "$request_method", "GET", "$msg - request_method"
|
|
|
|
tap_ensure "$request_uri", "/t.cgi", "$msg - request_uri"
|
|
|
|
tap_ensure "$query_string", "abc=def", "$msg - query_string"
|
|
|
|
|
2023-01-19 16:11:37 +00:00
|
|
|
|
|
|
|
local hc=$(curl -s -w '%{http_code}\n' -X POST --data-binary "hello world" -o "${tmpdir}/t.out" "http://${srvaddr}/t.cgi?abc=def")
|
2023-01-15 13:16:11 +00:00
|
|
|
tap_ensure "$hc" "200" "$msg - got $hc"
|
|
|
|
|
|
|
|
local request_method=$(grep -E "^REQUEST_METHOD:" "${tmpdir}/t.out" | cut -d: -f2)
|
|
|
|
local request_uri=$(grep -E "^REQUEST_URI:" "${tmpdir}/t.out" | cut -d: -f2)
|
|
|
|
local query_string=$(grep -E "^QUERY_STRING:" "${tmpdir}/t.out" | cut -d: -f2)
|
|
|
|
|
|
|
|
tap_ensure "$request_method", "POST", "$msg - request_method"
|
|
|
|
tap_ensure "$request_uri", "/t.cgi", "$msg - request_uri"
|
|
|
|
tap_ensure "$query_string", "abc=def", "$msg - query_string"
|
|
|
|
|
|
|
|
## TODO: write more...
|
2023-01-14 17:17:12 +00:00
|
|
|
rm -rf "${tmpdir}"
|
|
|
|
|
|
|
|
kill -TERM ${jid}
|
|
|
|
wait ${jid}
|
|
|
|
}
|
|
|
|
|
2022-12-17 16:04:13 +00:00
|
|
|
test_default_index
|
2022-12-22 16:25:20 +00:00
|
|
|
test_file_list_dir
|
2023-01-14 17:17:12 +00:00
|
|
|
test_cgi
|
|
|
|
|
2022-12-22 16:25:20 +00:00
|
|
|
tap_end
|