Files
Pulse/scripts/tests/test_availability_help_docs.py
pulse-triage[bot] 0faea0a45c Align Availability, Recovery, and Security Help with runtime bounds
Update docs/AVAILABILITY.md, docs/RECOVERY.md, and SECURITY.md (with
byte-for-byte in-app mirrors in frontend-modern/public/docs/) and add
source-bound regression tests covering:
- Write-only Availability HTTP secrets, same-origin preservation,
  http_secrets_reentry_required when adding an observation-location
  agent, 64-hex SHA-256 certificate fingerprints, 16-header cap, 64 KiB
  response header cap, and 240-byte transport error limit.
- Recovery /api/recovery/series 3,660-day UTC window cap and cluster or
  connection scope isolation for unlinked Kubernetes PVC and TrueNAS
  dataset rollups.
- Proxmox/PBS /api/auto-register credential verification, authority
  revalidation, saved TLS-pin protection, and agent:exec ceiling when
  minting command-enabled install tokens via API tokens.

Contract-Neutral: Documentation and source-bound doc-verification tests only; no runtime, API, schema, or UI contract changes.
Change-source: pulse-maintainer
2026-11-28 10:40:44 +00:00

152 lines
6.0 KiB
Python

#!/usr/bin/env python3
"""Keep Availability Help aligned with Availability UI, DNS, HTTPS TLS, and retirement code.
Static source/document checks only: no probe, DNS query, network request, or live
alert operation is performed.
"""
from pathlib import Path
import unittest
ROOT = Path(__file__).resolve().parents[2]
DOC = ROOT / "docs/AVAILABILITY.md"
MIRROR = ROOT / "frontend-modern/public/docs/AVAILABILITY.md"
PAGE = ROOT / "frontend-modern/src/features/availability/AvailabilityPageSurface.tsx"
SLOT = (
ROOT
/ "frontend-modern/src/components/Settings/ConnectionEditor/CredentialSlots/AvailabilityTargetSlot.tsx"
)
DNS_SECTION = (
ROOT
/ "frontend-modern/src/components/Settings/ConnectionEditor/CredentialSlots/AvailabilityDnsConfigSection.tsx"
)
PRESETS = (
ROOT
/ "frontend-modern/src/components/Settings/ConnectionEditor/availabilityTargetPresets.ts"
)
HISTORY = ROOT / "frontend-modern/src/utils/availabilityHistoryPresentation.ts"
PROBE_GO = ROOT / "internal/availabilityprobe/probe.go"
POLLER_GO = ROOT / "internal/monitoring/availability_poller.go"
def plain(text: str) -> str:
return " ".join(text.replace("**", "").replace("`", "").split())
class AvailabilityHelpDocsTest(unittest.TestCase):
def setUp(self) -> None:
self.doc = DOC.read_text(encoding="utf-8")
self.guide = plain(self.doc)
self.page = PAGE.read_text(encoding="utf-8")
self.slot = SLOT.read_text(encoding="utf-8")
self.dns_section = DNS_SECTION.read_text(encoding="utf-8")
self.presets = PRESETS.read_text(encoding="utf-8")
self.history = HISTORY.read_text(encoding="utf-8")
self.probe_go = PROBE_GO.read_text(encoding="utf-8")
self.poller_go = POLLER_GO.read_text(encoding="utf-8")
def test_shipped_guide_matches(self) -> None:
self.assertEqual(DOC.read_bytes(), MIRROR.read_bytes())
def test_top_level_page_controls_history_ranges_and_retirement_match_source(self) -> None:
for token in ("Add check", "Test now", "Pause", "Resume", "Edit"):
with self.subTest(control=token):
self.assertIn(token, self.page)
self.assertIn(token, self.guide)
for label in ("24h", "7d", "30d", "1y"):
with self.subTest(range_label=label):
self.assertIn(f"label: '{label}'", self.history)
self.assertIn(label, self.guide)
self.assertIn("refreshAvailabilitySchedule(localTasks)", self.poller_go)
self.assertIn("retires its pending local poll from the scheduler queue", self.guide)
def test_dns_resolution_labels_match_ui_components(self) -> None:
self.assertIn('<option value="dns">DNS resolution</option>', self.slot)
self.assertIn("'DNS server address'", self.slot)
self.assertIn("DNS resolver (Pi-hole / AdGuard / Unbound)", self.presets)
for label in (
"Query hostname",
"Record type",
"Transport",
"UDP (default)",
"TCP",
"Expected answer (optional)",
"NOERROR",
):
with self.subTest(dns_label=label):
self.assertIn(label, self.dns_section)
self.assertIn(label, self.guide)
for phrase in (
"DNS resolution",
"DNS resolver (Pi-hole / AdGuard / Unbound)",
"DNS server address",
):
with self.subTest(phrase=phrase):
self.assertIn(phrase, self.guide)
def test_https_certificate_pinning_and_refusal_match_source(self) -> None:
for label in (
"Monitor TLS certificate validity",
"Expiry warning (days)",
"Pinned certificate fingerprint (optional)",
"Allow an unverified certificate",
"presented certificate SHA-256",
):
with self.subTest(tls_label=label):
self.assertIn(label, self.slot)
self.assertIn(label, self.guide)
self.assertIn("contract.TLSFingerprintSHA256", self.probe_go)
self.assertIn("contract.InsecureSkipVerify || !contract.SendsStoredValues()", self.probe_go)
self.assertIn("httpCertificateRefusal", self.probe_go)
self.assertIn("does not send them to an untrusted certificate", self.guide)
def test_https_write_only_secrets_reentry_and_probe_bounds_match_source(self) -> None:
handlers_go = (ROOT / "internal/api/availability_handlers.go").read_text(encoding="utf-8")
config_go = (ROOT / "internal/config/availability.go").read_text(encoding="utf-8")
for marker in (
"func mergeAvailabilityHTTPSecrets(",
"if !sameAvailabilityHTTPOrigin(previous, next)",
"if availabilityTargetGainsProbeAgent(previous, target) && availabilityTargetReusesHTTPSecrets(requested, target)",
'"http_secrets_reentry_required"',
):
self.assertIn(marker, handlers_go)
for marker in (
"HTTP certificate fingerprint must be a SHA-256 value (64 hexadecimal characters)",
"if len(contract.Headers) > 16",
):
self.assertIn(marker, config_go)
for marker in (
"const httpProbeErrorLimit = 240",
"const httpProbeMaxResponseHeaderBytes = 64 << 10",
):
self.assertIn(marker, self.probe_go)
for phrase in (
"64-character hexadecimal SHA-256 value",
"write-only through the API",
"same scheme, host and port",
"adding a new observation-location agent",
"http_secrets_reentry_required",
"at most 16 custom request headers",
"at most 64 KiB of response headers",
"240 bytes",
):
with self.subTest(phrase=phrase):
self.assertIn(phrase, self.guide)
def test_build_stage_push_checks_not_mentioned(self) -> None:
self.assertNotIn("push check", self.guide.lower())
self.assertNotIn("push checks", self.guide.lower())
if __name__ == "__main__":
unittest.main()