Files
mtusi2026lab7-safronov/student-tests/test_transport.py
T
ricoromaandClaude Opus 5.5 13fdd187c6 feat: harden authentication (Argon2id by measurement, login limits, body limit)
Apply auth-hardening up to the bench_login label: Argon2id parameters
from [auth] chosen by driver.py argon2-params (m=64 MiB, t=2, p=1),
rehash on login, per-process KDF budget with 429, shared login failure
limit in Valkey with a local fallback, X-Forwarded-For from HAProxy,
64 KiB body limit (400) in LB and middleware, bench login profile,
tests, threat model and trust matrix rows. Hypotheses H1-H4 are
committed here before the baseline label.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 17:52:48 +03:00

51 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Проверки транспорта лабы 7 (спек `student-tests`, «Проверки входа и
транспорта лабы 7»; сценарий «Недоверенный TLS» — вне сверки покрытия, в
докстринге): публичная точка входа отвергается проверкой сертификата при
чужом CA (системное хранилище вместо CA стенда) и при имени хоста не из SAN
(`127.0.0.1` вместо `localhost`) — именно ошибкой проверки, а не отказом
соединения.
"""
import ssl
import urllib.parse
import httpx
import pytest
from api_client import tls_context
from conftest import BASE_URL
HEALTH = "/health/live"
def _verify_error(url: str, context: ssl.SSLContext) -> str:
with pytest.raises(httpx.ConnectError) as caught:
httpx.get(url, verify=context, timeout=5)
cause = caught.value.__context__ or caught.value.__cause__
text = f"{caught.value} {cause!r}"
assert "CERTIFICATE_VERIFY_FAILED" in text, text
return text
def test_untrusted_tls() -> None:
"""Сценарий «Недоверенный TLS» (`student-tests`)."""
parts = urllib.parse.urlsplit(BASE_URL)
if parts.hostname != "localhost":
pytest.skip(f"BASE_URL host {parts.hostname!r} is not localhost")
# системное хранилище: CA стенда в нём нет
unknown_issuer = _verify_error(
BASE_URL + HEALTH,
ssl.create_default_context(),
)
assert "unable to get local issuer" in unknown_issuer.lower() or (
"self-signed" in unknown_issuer.lower()
), unknown_issuer
# CA стенда, но имя не из SAN
by_ip = parts._replace(netloc=f"127.0.0.1:{parts.port}").geturl()
mismatch = _verify_error(by_ip + HEALTH, tls_context())
assert "mismatch" in mismatch.lower(), mismatch
# с CA стенда и localhost — работает: отказ выше не от недоступности
assert (
httpx.get(BASE_URL + HEALTH, verify=tls_context()).status_code == 200
)