fix: address telemetry-mtls verify findings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 00:45:12 +03:00
co-authored by Claude Opus 5.5
parent 845a8fc0e6
commit 97b6dc25f0
17 changed files with 309 additions and 38 deletions
+64
View File
@@ -560,6 +560,70 @@ def test_entrypoint_refuses_before_sending(
assert "BEGIN" not in output
def _run_replay(pki: Path, **env: str) -> tuple[int, list[dict[str, Any]]]:
stand = pki / "stand"
result = subprocess.run( # noqa: S603
[sys.executable, "-m", "src.relay", "replay"],
cwd=BASE_DIR,
env={
**os.environ,
"APP__RUN_MODE": "console",
"CLIENT_TLS__CA_FILE": str(stand / "ca.crt"),
# закрытый порт: после проверки replay получает отказ PostgreSQL
# (код 1) сразу, без стенда
"DATABASE__HOST": "localhost",
"DATABASE__PORT": "1",
"BROKER__HOST": "localhost",
"BROKER__CERT_FILE": str(stand / "relay.crt"),
"BROKER__KEY_FILE": str(stand / "relay.key"),
"BROKER__CRL_FILE": str(stand / "crl.pem"),
"TELEMETRY__ENABLED": "true",
"TELEMETRY__OTLP_ENDPOINT": "https://otel-collector:4318",
"TELEMETRY__CERT_FILE": "",
"TELEMETRY__KEY_FILE": "",
"TELEMETRY__CRL_FILE": "",
**env,
},
capture_output=True,
text=True,
timeout=60,
check=False,
)
records = []
for line in result.stdout.splitlines():
with contextlib.suppress(ValueError):
records.append(json.loads(line))
return result.returncode, records
def test_replay_does_not_check_telemetry(pki: Path) -> None:
"""Команда replay SDK не запускает (verify S2): при включённой телеметрии
без файлов `[telemetry]` проверка при старте их не называет, команда
доходит до PostgreSQL (закрытый порт — код 1, а не 2)."""
code, records = _run_replay(pki)
refusal = [
r for r in records if r["event"] == "Invalid client TLS settings"
]
assert refusal == [], records
assert code == 1, records
def test_replay_still_checks_database_and_broker(pki: Path) -> None:
"""Секции, которые проверялись у replay до change, проверяются и дальше:
IP-адрес PostgreSQL и пустая пара брокера — код 2 с их полями."""
code, records = _run_replay(
pki,
DATABASE__HOST="127.0.0.1",
BROKER__CERT_FILE="",
)
assert code == 2, records # noqa: PLR2004
refusal = [
r for r in records if r["event"] == "Invalid client TLS settings"
]
assert len(refusal) == 1, records
assert refusal[0]["fields"] == ["database.host", "broker.cert_file"]
# --- настройки ----------------------------------------------------------------