Commit 45385484 authored by Vincent Pelletier's avatar Vincent Pelletier

shell/caucase.sh: Improve built-in test suite.

Simplify code a bit.
Change directory when starting caucased, so all files are stored inside
test's temporary directory (and not just the database).
Tolerate caucased not immediately starting.
Fix CA presence tests (well this is embarrassing).
List test directory content when failing, as it will get deleted shortly
after.
parent ec76d39f
......@@ -1115,6 +1115,7 @@ EOF
_test() {
# shellcheck disable=SC2039
local netloc="$1" \
status \
tmp_dir \
caucased_dir \
caucased_pid
......@@ -1127,30 +1128,55 @@ EOF
fi
tmp_dir="$(mktemp -d --suffix=caucase_sh)"
caucased_dir="$tmp_dir/caucased"
caucased --db "$caucased_dir/db.sqlite" --netloc "$netloc" &
mkdir "$caucased_dir"
if cd "$caucased_dir"; then
:
else
echo 'Could not setup caucased directory'
return 1
fi
caucased --netloc "$netloc" &
caucased_pid="$!"
# shellcheck disable=SC2064
trap "kill \"$caucased_pid\"; wait; rm -rf \"$tmp_dir\"" EXIT
# wait for up to about 10 seconds for caucased to start listening (initial
# certificate generation.
for _ in $(seq 100); do
CURL "http://$netloc" > /dev/null
status=$?
test $status -eq 0 && break
# curl status 7 means "cnould not connect"
if [ $status -ne 7 ]; then
echo "curl failed while accessing test caucased with status $status"
return 1
fi
sleep 0.1
done
if [ $status -ne 0 ]; then
echo 'Timeout while waiting for caucased to start'
return 1
fi
if cd "$tmp_dir"; then
:
else
echo 'Could not setup temporary directory'
echo 'Could not enter test temporary directory'
return 1
fi
_main --ca-url "http://$netloc" --update-user
if [ -r cas.crt.pem ]; then
if [ ! -r cas.crt.pem ]; then
echo 'cas.crt.pem not created'
find . -ls
return 1
fi
if [ -r cau.crt.pem ]; then
if [ ! -r cau.crt.pem ]; then
echo 'cau.crt.pem not created'
find . -ls
return 1
fi
}
if [ "$#" -gt 0 ] && [ "x$1" = 'x--test' ]; then
if [ "$#" -eq 1 ]; then
_test "localhost:8000"
elif [ "$#" -eq 2 ]; then
_test "$2"
if [ "$#" -le 2 ]; then
_test "${2:-localhost:8000}"
else
echo 'Usage: --test [<hostname/address>:<port>]'
return 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment