Files
nextcloud-docker/scripts/test.sh
2026-04-17 11:30:59 +05:30

49 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# scripts/test.sh
set -euo pipefail
DOMAIN="nxt.bhatfamily.in"
HTTP_PORT=8082
HTTPS_PORT=8446
STRICT_TLS="${STRICT_TLS:-0}"
CURL_TLS_ARGS=("-k")
if [ "${STRICT_TLS}" = "1" ]; then
CURL_TLS_ARGS=()
fi
echo "==> Testing HTTP redirect..."
http_code="$(curl -s -o /dev/null -w "%{http_code}" "http://${DOMAIN}:${HTTP_PORT}/")"
case "${http_code}" in
301|302|307|308) ;;
*)
echo "ERROR: Expected HTTP redirect status (301/302/307/308), got ${http_code}."
exit 1
;;
esac
echo "==> Testing HTTPS endpoint..."
https_code="$(curl "${CURL_TLS_ARGS[@]}" -s -o /dev/null -w "%{http_code}" "https://${DOMAIN}:${HTTPS_PORT}/")"
case "${https_code}" in
200|301|302|303|307|308) ;;
*)
echo "ERROR: Expected successful HTTPS response/redirect, got ${https_code}."
exit 1
;;
esac
echo "==> Testing Nextcloud status.php..."
status_file="$(mktemp)"
trap 'rm -f "${status_file}"' EXIT
status_code="$(curl "${CURL_TLS_ARGS[@]}" -s -o "${status_file}" -w "%{http_code}" "https://${DOMAIN}:${HTTPS_PORT}/status.php")"
if [ "${status_code}" != "200" ]; then
echo "ERROR: Expected /status.php HTTP 200, got ${status_code}."
exit 1
fi
if ! grep -q '"installed":true' "${status_file}"; then
echo "ERROR: /status.php did not return expected installed=true payload."
exit 1
fi
echo "All tests passed."