Files
proxmox-manager/tests/mock-bin/curl
Tim BaumannandClaude Opus 5 24d5812a2d fix(health): harden notification and state handling
- http:// NTFY_URL together with NTFY_TOKEN_FILE is a config error
  (--check exits 3, --test-notify exits 1).
- Token file: directory must be owned by root/current user and not
  group/world-writable; the token is read through one opened descriptor
  that is verified via /proc/self/fd (regular file, owner, mode 0600).
- Lock file opened for append (never truncated); the parent of
  HEALTH_STATE_DIR must not be group/world-writable.
- qm/pct config fallback runs with timeout 10.
- curl: -q first, --proto =https when a token is used, no --retry.
- json_escape escapes remaining control characters as \u00XX.
- --test-notify removes its temp body file on exit and on INT/TERM.
- _truncate keeps UTF-8 characters intact.
- Tests for each item where practical.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-19 19:07:05 +02:00

27 lines
863 B
Bash
Executable File

#!/usr/bin/env bash
# Mock curl: never touches the network.
# Appends argv to $PMAN_MOCK_CURL_LOG, the stdin config to ${PMAN_MOCK_CURL_LOG}.cfg and
# every @file body to ${PMAN_MOCK_CURL_LOG}.body; exits ${PMAN_MOCK_CURL_RC:-0}.
# PMAN_MOCK_CURL_SLEEP=N delays the call; PMAN_MOCK_FD_LOG records open fds.
set -euo pipefail
if [[ -n "${PMAN_MOCK_FD_LOG:-}" ]]; then
for fd in /proc/"$$"/fd/*; do
printf 'curl %s\n' "$(readlink "$fd" || true)"
done >>"$PMAN_MOCK_FD_LOG"
fi
log="${PMAN_MOCK_CURL_LOG:-}"
cfg="$(cat)"
if [[ -n "${PMAN_MOCK_CURL_SLEEP:-}" ]]; then
sleep "$PMAN_MOCK_CURL_SLEEP"
fi
if [[ -n "$log" ]]; then
printf '%s\n' "$*" >>"$log"
printf '%s\n---\n' "$cfg" >>"${log}.cfg"
for arg in "$@"; do
if [[ "$arg" == @* && -f "${arg#@}" ]]; then
cat -- "${arg#@}" >>"${log}.body"
fi
done
fi
exit "${PMAN_MOCK_CURL_RC:-0}"