smoke-noninteractive.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env bash
  2. #
  3. # smoke-noninteractive.sh — verify the non-interactive install path.
  4. #
  5. # Runs install.sh inside an Ubuntu container with NO TTY (piped) and
  6. # XUI_NONINTERACTIVE=1, then asserts:
  7. # * /etc/x-ui/install-result.env exists (mode 600) with random, non-default creds
  8. # * the panel reports hasDefaultCredential: false (no admin/admin remains)
  9. # * the panel HTTP server actually serves on the generated port/base path
  10. #
  11. # Requires Docker and network access (install.sh downloads the released binary).
  12. # Usage: bash deploy/test/smoke-noninteractive.sh
  13. set -euo pipefail
  14. REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
  15. IMAGE="${SMOKE_IMAGE:-ubuntu:24.04}"
  16. if ! command -v docker > /dev/null 2>&1; then
  17. echo "ERROR: docker is required for this smoke test." >&2
  18. exit 1
  19. fi
  20. echo "== non-interactive install smoke test (image: $IMAGE) =="
  21. docker run --rm \
  22. -v "${REPO_ROOT}/install.sh:/root/install.sh:ro" \
  23. -e XUI_NONINTERACTIVE=1 \
  24. -e XUI_SSL_MODE=none \
  25. -e DEBIAN_FRONTEND=noninteractive \
  26. "$IMAGE" bash -euo pipefail -c '
  27. apt-get update -qq
  28. apt-get install -y -qq curl tar openssl ca-certificates > /dev/null
  29. echo "--- running install.sh piped (no TTY) ---"
  30. # Piping guarantees stdin is not a TTY, exercising the auto non-interactive path.
  31. cat /root/install.sh | bash
  32. echo "--- assertions ---"
  33. RESULT=/etc/x-ui/install-result.env
  34. test -f "$RESULT" || { echo "FAIL: $RESULT missing"; exit 1; }
  35. perms=$(stat -c %a "$RESULT")
  36. [ "$perms" = "600" ] || { echo "FAIL: $RESULT perms=$perms (want 600)"; exit 1; }
  37. # shellcheck disable=SC1090
  38. . "$RESULT"
  39. [ -n "${XUI_USERNAME:-}" ] && [ "$XUI_USERNAME" != "admin" ] \
  40. || { echo "FAIL: username missing or still admin"; exit 1; }
  41. [ -n "${XUI_PASSWORD:-}" ] && [ "$XUI_PASSWORD" != "admin" ] \
  42. || { echo "FAIL: password missing or still admin"; exit 1; }
  43. [ -n "${XUI_PANEL_PORT:-}" ] || { echo "FAIL: port missing"; exit 1; }
  44. # No default admin in the DB.
  45. /usr/local/x-ui/x-ui setting -show | grep -q "hasDefaultCredential: false" \
  46. || { echo "FAIL: hasDefaultCredential is not false"; exit 1; }
  47. echo "--- verifying the panel serves HTTP ---"
  48. cd /usr/local/x-ui
  49. ./x-ui > /tmp/xui.log 2>&1 &
  50. xpid=$!
  51. for _ in $(seq 1 15); do
  52. code=$(curl -s -o /dev/null -w "%{http_code}" \
  53. "http://127.0.0.1:${XUI_PANEL_PORT}/${XUI_WEB_BASE_PATH}/" 2>/dev/null || true)
  54. case "$code" in 200|301|302|307|308) break ;; esac
  55. sleep 1
  56. done
  57. kill "$xpid" 2>/dev/null || true
  58. echo "panel HTTP status: ${code:-none}"
  59. case "${code:-}" in
  60. 200|301|302|307|308) : ;;
  61. *) echo "FAIL: panel did not serve (status ${code:-none})"; tail -n 30 /tmp/xui.log; exit 1 ;;
  62. esac
  63. echo "SMOKE_PASS: user=$XUI_USERNAME port=$XUI_PANEL_PORT path=$XUI_WEB_BASE_PATH"
  64. '
  65. echo "== non-interactive smoke test PASSED =="