Files
ayurishchevandClaude Sonnet 5.5 ad6995bb63 Docs restructure, code review, gatherer reliability, JWT key fail-closed
Documentation
- Three levels: DOCS/General (overview, configuration), DOCS/Deployment
  (choose a method, first steps), details per method in Containers/ and
  System_Services/; new root README and DOCS/README map.
- Remove superseded pages (Deployment.md, Deployment_Docker/Native.md, Index.md);
  split the two scenario guides by section.
- Isolate the Timeweb/Hysteria2 records in DEPLOYMENTS/timeweb-hysteria2/
  (not linked from DOCS, listed in .graphifyignore).
- Add DOCS/code_review/ with a time-stamped analysis of the code base.

Gatherer (BUG-02, BUG-03)
- Session key (CN, address, connected_since_ts), baseline from the
  active_sessions snapshot, grace period for sessions missing from the status.
- Status file integrity (TITLE/TIME/END) and freshness; a torn read skips the tick.
- Cache applied after commit; main loop survives exceptions, backs off, and
  stops cleanly on SIGTERM/SIGINT; new client rows start with the first
  frame's totals; five tests.

JWT signing key (SEC-01)
- No built-in default: Core and Profiler refuse to start with a missing,
  placeholder or short (< 32) key; shipped config.ini has an empty value.
- Same rule in install.sh, update.sh (issues a new key when missing or weak),
  docker lib/entrypoint; five tests, conftest.py for the test key.

Each change has a plan and a summary under DOCS/Changes/.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-05 20:30:45 +03:00

30 lines
1.3 KiB
Python

import pytest
from secret_key import resolve_secret_key, SecretKeyError
GOOD = "0123456789abcdef" * 4 # 64 hex characters
def test_weak_or_missing_key_is_refused():
for bad in (None, "", " ", "ovpmon-secret-change-me", "Change-Me-Please", "k" * 31):
with pytest.raises(SecretKeyError) as exc:
resolve_secret_key(bad, None)
assert "openssl rand -hex 32" in str(exc.value)
if bad and bad.strip():
assert bad not in str(exc.value) # the key value is never part of the message
# the same checks apply to the config.ini value
with pytest.raises(SecretKeyError):
resolve_secret_key(None, "ovpmon-secret-change-me")
# legacy variable name is called out explicitly
with pytest.raises(SecretKeyError) as exc:
resolve_secret_key(None, "", legacy_env=GOOD)
assert "OVPMON_SECRET_KEY" in str(exc.value) and "OVPMON_API_SECRET_KEY" in str(exc.value)
assert GOOD not in str(exc.value)
def test_good_key_and_priority():
assert resolve_secret_key(GOOD, None) == (GOOD, "environment")
assert resolve_secret_key(None, GOOD) == (GOOD, "config.ini")
# environment wins over config.ini, even when the config.ini value is the old default
assert resolve_secret_key(GOOD, "ovpmon-secret-change-me") == (GOOD, "environment")