wip: apply pki-ingress-mtls groups 3-5, start group 6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 06:49:52 +03:00
co-authored by Claude Opus 5.5
parent 5c514b09e8
commit 4759f71dec
8 changed files with 372 additions and 36 deletions
+24 -4
View File
@@ -1,6 +1,7 @@
"""Настройка набора: адрес стенда, проверка доступности, фикстуры."""
import os
import ssl
import subprocess
from collections.abc import Callable, Iterator
from typing import Any
@@ -8,10 +9,11 @@ from typing import Any
import httpx
import pytest
from api_client import Actor, Api
from api_client import CA_FILE, Actor, Api, tls_context
from spec_coverage import COLLECTED, Collected
BASE_URL = os.environ.get("BASE_URL", "http://localhost:8080").rstrip("/")
# с лабы 7 — HTTPS балансировщика (change pki-ingress-mtls)
BASE_URL = os.environ.get("BASE_URL", "https://localhost:8443").rstrip("/")
# сколько реплик API за BASE_URL: стенд с LB — API_REPLICAS (make
# student_test), один процесс — 1 (make test_isolated, драйвер в консоли).
# Режим задаётся явно, а не угадывается по ответам: иначе сломанный LB
@@ -84,10 +86,28 @@ def pytest_collection_finish(session: pytest.Session) -> None:
@pytest.fixture(scope="session", autouse=True)
def _server_reachable() -> None:
"""Без сервера прогон останавливается одной строкой, а не 100 ошибками."""
"""Без сервера прогон останавливается одной строкой, а не 100 ошибками.
Так же — сертификат сервера, который не проходит проверку по `CA_FILE`
и hostname: адрес и причина одной строкой, код 2 до первого теста.
"""
try:
resp = httpx.get(f"{BASE_URL}/health/live", timeout=2)
context = tls_context()
except (OSError, ssl.SSLError) as exc:
pytest.exit(
f"cannot load CA_FILE {CA_FILE!r} for {BASE_URL}: {exc}",
returncode=2,
)
try:
resp = httpx.get(f"{BASE_URL}/health/live", timeout=2, verify=context)
except httpx.HTTPError as exc:
cause = exc.__cause__ or exc.__context__
if isinstance(cause, ssl.SSLCertVerificationError):
pytest.exit(
f"server certificate at {BASE_URL} failed verification "
f"(CA_FILE {CA_FILE!r}): {cause.verify_message}",
returncode=2,
)
pytest.exit(
f"server is not reachable at {BASE_URL}: {exc!r}",
returncode=2,