Files
cacti/tests/e2e/support_diagnostics_docker.sh
Thomas Vincent 41780277d3 fix(docker): restrict development permissions and start the poller (#8453)
* fix(docker): restrict the dev stack to localhost and make the poller run

The web port bound to every interface, named volumes hid the shipped .htaccess denies, and the cron job could neither find php nor write to PID 1's output, so the poller never ran.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(docker): keep harnesses polling and restore the developer's config.php

check_docker.sh deleted an existing include/config.php on exit, health polling aborted under pipefail before the container reported, the MariaDB wait had no bound, and the BSD mktemp template left its Xs literal.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* docs(changelog): add fragment for #8453

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(e2e): move the pointer off the Deepness multiselect button

Deepness sets a zero body margin, so the unhovered #ms-button sits at the viewport origin and headless Chromium on Linux intermittently applies :hover to it.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* ci: pull pinned integration database from authenticated mirror

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-10-23 08:17:48 -04:00

104 lines
4.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# +-------------------------------------------------------------------------+
# | Copyright (C) 2004-2026 The Cacti Group |
# | |
# | This program is free software; you can redistribute it and/or |
# | modify it under the terms of the GNU General Public License |
# | as published by the Free Software Foundation; either version 2 |
# | of the License, or (at your option) any later version. |
# +-------------------------------------------------------------------------+
# | Cacti: The Complete RRDtool-based Graphing Solution |
# +-------------------------------------------------------------------------+
#
# End-to-end check for the Copy Diagnostics redaction feature (#7349). Boots the
# Cacti Docker stack, then runs support_diagnostics_probe.php inside the web
# container against a real database to confirm the diagnostics report never
# leaks the database host, password or full RSA fingerprint.
#
# Requires Docker. Run from a checkout: tests/e2e/support_diagnostics_docker.sh
set -euo pipefail
COMPOSE_PROJECT="cacti_support_diag_e2e_$$"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
ENV_FILE="$REPO_DIR/.env.support-diag-e2e"
WEB_PORT=18082
DB_PORT=13308
CONFIG_EXISTED=0
CONFIG_BACKUP=""
if [ -f "$REPO_DIR/include/config.php" ]; then
CONFIG_EXISTED=1
CONFIG_BACKUP="$(mktemp "${TMPDIR:-/tmp}/cacti-config.XXXXXX")"
cp "$REPO_DIR/include/config.php" "$CONFIG_BACKUP"
rm -f "$REPO_DIR/include/config.php"
fi
cleanup() {
cd "$REPO_DIR"
docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" down -v --remove-orphans 2>/dev/null || true
rm -f "$ENV_FILE"
if [ "$CONFIG_EXISTED" -eq 1 ] && [ -n "$CONFIG_BACKUP" ] && [ -f "$CONFIG_BACKUP" ]; then
# The entrypoint may have created a container-owned config.php that cp
# cannot open for writing; the host user can still unlink it.
rm -f "$REPO_DIR/include/config.php"
cp "$CONFIG_BACKUP" "$REPO_DIR/include/config.php"
rm -f "$CONFIG_BACKUP"
elif [ "$CONFIG_EXISTED" -eq 0 ]; then
rm -f "$REPO_DIR/include/config.php"
fi
}
trap cleanup EXIT
cd "$REPO_DIR"
cat > "$ENV_FILE" <<EOF
WEB_PORT=$WEB_PORT
DB_ROOT_PASSWORD=testroot
DB_NAME=cacti
DB_USER=cacti
DB_PASSWORD=testpass
DB_PORT=$DB_PORT
TIMEZONE=UTC
PHP_MEMORY_LIMIT=256M
DB_MAX_CONNECTIONS=50
DB_BUFFER_POOL_SIZE=256M
EOF
echo "Building support diagnostics Docker test image..."
docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" build --quiet
echo "Starting support diagnostics Docker test stack..."
docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" up -d
echo "Waiting for Docker test stack..."
TRIES=0
while [ "$TRIES" -lt 36 ]; do
# grep returns non-zero before the Health field appears; tolerate it under
# pipefail so the poll loop keeps waiting instead of exiting the script
DB_HEALTH=$(docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" ps --format json 2>/dev/null | grep -o '"Health":"[^"]*"' | head -1 | cut -d'"' -f4 || true)
WEB_HEALTH=$(docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" ps --format json 2>/dev/null | grep -o '"Health":"[^"]*"' | tail -1 | cut -d'"' -f4 || true)
if [ "$DB_HEALTH" = "healthy" ] && [ "$WEB_HEALTH" = "healthy" ]; then
break
fi
sleep 5
TRIES=$((TRIES + 1))
done
if [ "${DB_HEALTH:-}" != "healthy" ] || [ "${WEB_HEALTH:-}" != "healthy" ]; then
docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" ps
exit 1
fi
WEB_CONTAINER=$(docker compose -p "$COMPOSE_PROJECT" --env-file "$ENV_FILE" ps -q web)
docker exec "$WEB_CONTAINER" php -l /var/www/html/cacti/support.php
docker exec "$WEB_CONTAINER" php -l /var/www/html/cacti/tests/e2e/support_diagnostics_probe.php
PROBE_OUTPUT=$(docker exec "$WEB_CONTAINER" php /var/www/html/cacti/tests/e2e/support_diagnostics_probe.php)
echo "$PROBE_OUTPUT"
grep -q 'PASS support diagnostics docker probe' <<<"$PROBE_OUTPUT"