fix: address storage-tls verify findings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 00:55:33 +03:00
co-authored by Claude Opus 5.5
parent 9f01fcce4b
commit a1bfb8dde2
16 changed files with 340 additions and 62 deletions
+26 -1
View File
@@ -118,10 +118,17 @@ def _settings(**sections: Any) -> Settings:
def test_problems_ca_file(tmp_path: Path, pki: Path) -> None:
garbage = tmp_path / "garbage.crt"
garbage.write_text("not a certificate\n")
empty = tmp_path / "empty.crt"
empty.write_text("")
cases = {
"": ["client_tls.ca_file"],
str(tmp_path / "missing.crt"): ["client_tls.ca_file"],
str(garbage): ["client_tls.ca_file"],
str(empty): ["client_tls.ca_file"],
# PEM без сертификата CA (verify S1): контекст загружается, но
# доверять в нём нечему — только CRL или только leaf
str(pki / "stand" / "crl.pem"): ["client_tls.ca_file"],
str(pki / "stand" / "valkey.crt"): ["client_tls.ca_file"],
str(pki / "stand" / "ca.crt"): [],
}
for path, expected in cases.items():
@@ -289,11 +296,24 @@ def _run_entrypoint(
("case", "env", "field"),
[
("no_ca", {"CLIENT_TLS__CA_FILE": ""}, "client_tls.ca_file"),
# нечитаемый CA (verify W1): API строил контекст при импорте
# src.main и падал с кодом 1 до проверки настроек
(
"missing_ca",
{"CLIENT_TLS__CA_FILE": "{tmp}/missing.crt"},
"client_tls.ca_file",
),
(
"garbage_ca",
{"CLIENT_TLS__CA_FILE": "{tmp}/garbage.crt"},
"client_tls.ca_file",
),
("ip_host", {"DATABASE__HOST": "127.0.0.1"}, "database.host"),
],
)
def test_entrypoint_refuses_before_connecting(
pki: Path,
tmp_path: Path,
name: str,
case: str,
env: dict[str, str],
@@ -302,7 +322,11 @@ def test_entrypoint_refuses_before_connecting(
"""Спек `service-configuration`, «Процесс без CA» и «IP-адрес вместо
имени хранилища»: код 2, запись «Invalid client TLS settings» называет
поле, пути CA в выводе нет."""
env = {"CLIENT_TLS__CA_FILE": str(pki / "stand" / "ca.crt"), **env}
(tmp_path / "garbage.crt").write_text("not a certificate\n")
env = {
"CLIENT_TLS__CA_FILE": str(pki / "stand" / "ca.crt"),
**{key: value.format(tmp=tmp_path) for key, value in env.items()},
}
code, records = _run_entrypoint(name, pki, **env)
assert code == 2, (case, records)
refusal = [
@@ -312,6 +336,7 @@ def test_entrypoint_refuses_before_connecting(
assert refusal[0]["fields"] == [field]
assert refusal[0]["module"] == ENTRYPOINTS[name][1]
assert str(pki) not in json.dumps(records)
assert str(tmp_path) not in json.dumps(records)
async def _resp_session(