forked from mtusi2026/mtusi2026lab7
Add operator commands for leaf and secret rotation, identity revocation and CRL renewal without rebuilding images, and a drill under load. A rejected PostgreSQL role password is now 503 instead of 500. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
"""Какие ошибки драйвера — недоступность PostgreSQL (change
|
|
`rotation-revocation`, design, решение 10; спек `data-storage`, «Пароль роли
|
|
отвергнут»): `src/infra/db/errors.py`.
|
|
|
|
Отказ входа роли (28P01) — недоступность зависимости (503), а отказ прав
|
|
(42501) и нарушение ограничения (23505) — дефект запроса (500).
|
|
"""
|
|
|
|
import asyncpg
|
|
import pytest
|
|
from sqlalchemy import exc as sa_exc
|
|
|
|
from src.infra.db.errors import is_db_unavailable
|
|
|
|
|
|
def _dbapi_error(sqlstate: str) -> sa_exc.DBAPIError:
|
|
"""Ошибка, как её отдаёт SQLAlchemy: `orig` несёт SQLSTATE asyncpg."""
|
|
original = asyncpg.PostgresError.new({"C": sqlstate, "M": "text"})
|
|
return sa_exc.DBAPIError("SELECT 1", {}, original)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"sqlstate",
|
|
["08006", "53300", "57014", "57P01", "28P01"],
|
|
)
|
|
def test_unavailable(sqlstate: str) -> None:
|
|
assert is_db_unavailable(_dbapi_error(sqlstate))
|
|
|
|
|
|
@pytest.mark.parametrize("sqlstate", ["42501", "23505", "42601", "28000"])
|
|
def test_not_unavailable(sqlstate: str) -> None:
|
|
assert not is_db_unavailable(_dbapi_error(sqlstate))
|